Compare commits

..

2 Commits

Author SHA1 Message Date
6d1d360ec0 Correctly handle --threads param 2020-12-16 19:22:02 +01:00
4c687844d3 More minor code improvements 2020-12-16 19:19:35 +01:00

View File

@ -173,7 +173,7 @@ void print_usage() {
std::cerr << "Usage: gol --mode seq|omp|ocl [--threads number] [--device cpu|gpu] --load infile.gol --save outfile.gol --generations number [--measure]" << std::endl;
}
void main_opencl(std::string infile, std::string outfile, int num_generations, bool measure) {
void main_opencl(std::string infile, std::string outfile, int num_generations, bool measure, bool use_gpu) {
Timing *timing = Timing::getInstance();
// Get Nvidia CUDA platform
@ -324,11 +324,10 @@ void main_opencl(std::string infile, std::string outfile, int num_generations, b
result_file.close();
timing->stopFinalization();
delete[] world;
delete[] result;
if (measure) {
std::cout << timing->getResults() << std::endl;
}
timing->stopFinalization();
}
void main_classic(std::string infile, std::string outfile, int num_generations, bool measure, Mode mode) {
@ -408,10 +407,6 @@ void main_classic(std::string infile, std::string outfile, int num_generations,
delete neighbor_counts;
timing->stopFinalization();
if (measure) {
std::cout << timing->getResults() << std::endl;
}
}
int main(int argc, char* argv[]) {
@ -426,7 +421,6 @@ int main(int argc, char* argv[]) {
Mode mode = Mode::SEQ;
bool use_gpu = false;
int num_generations = 0;
int num_threads = 1;
bool measure = false;
if (argc < 8) {
@ -468,7 +462,7 @@ int main(int argc, char* argv[]) {
}
} else if (std::string(argv[i]) == "--threads") {
if (i + 1 < argc) {
num_threads = std::stoi(argv[i+1]);
omp_set_num_threads(std::stoi(argv[i+1]));
} else {
print_usage();
return 1;
@ -502,13 +496,14 @@ int main(int argc, char* argv[]) {
// If OpenCL was demanded, run that function.
if (mode == Mode::OCL) {
main_opencl(infile, outfile, num_generations, measure);
return 0;
main_opencl(infile, outfile, num_generations, measure, use_gpu);
} else {
main_classic(infile, outfile, num_generations, measure, mode);
}
if (measure) {
std::cout << timing->getResults() << std::endl;
}
return 0;
}