加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.cpp 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
Sanzo 提交于 2021-01-24 18:11 . Fixed default value of variable
#include "main.h"
int main(int argc, char **argv) {
if (argc < 2 ){
cout << "Usage : ./bellman MODE FILE BLOCK_SIZE DEBUG" << endl;
cout << "MODE - seq / cuda \n"
"FILE - Input file \n"
"BLOCKS - Number of blocks per grid for cuda\n"
"BLOCK_SIZE - Number of threads per block for cuda \n"
"DEBUG - 1 or 0 to enable/disable extended debug messages on console\n"
"Program expects these CSV files based on FILE thats passed in the argument\n"
" FILE_V.csv\n"
" FILE_I.csv\n"
" FILE_E.csv\n"
" FILE_W.csv"
<< endl;
return -1;
}
std::string mode = argv[1];
std::string file;
if(argv[2] != NULL){
file = argv[2];
//Check if all CSR files are present
if(!isValidFile(file + "_V.csv") ||
!isValidFile(file + "_I.csv") ||
!isValidFile(file + "_E.csv") ||
!isValidFile(file + "_W.csv")){
cout << "One or more CSR files missing" << endl;
return -1;
}
}
int BLOCKS = argc > 3 ? atoi(argv[3]) : 4;
int BLOCK_SIZE = argc > 4 ? atoi(argv[4]) : 512;
int debug = argc > 5 ? atoi(argv[5]) : 0;
if(mode == "seq") {
// Reference https://www.geeksforgeeks.org/measure-execution-time-function-cpp/
auto start = high_resolution_clock::now();
runBellmanFordSequential(file, debug);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
cout << "Elapsed time : " << duration.count() << " milli seconds " << endl;
}
if(mode == "cuda"){
runBellmanFordOnGPU(file.c_str(), BLOCK_SIZE,debug);
}
if(mode == "cuda-stride"){
runBellmanFordOnGPUWithGridStride(file.c_str(), BLOCKS, BLOCK_SIZE, debug);
}
if(mode == "cuda-v3") {
runBellmanFordOnGPUV3(file.c_str(), BLOCKS, BLOCK_SIZE, debug);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化