Commit d11e2fb6499ce3d67d387d49fc0d664f144e2c72

Authored by David Mayerich
1 parent cf5b4c92

fixed async bugs in GCC

Showing 1 changed file with 6 additions and 6 deletions   Show diff stats
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 #include <deque> 10 #include <deque>
11 #include <chrono> 11 #include <chrono>
12 #include <future> 12 #include <future>
13 - 13 +#include <algorithm>
14 14
15 15
16 namespace stim{ 16 namespace stim{
@@ -403,7 +403,7 @@ public: @@ -403,7 +403,7 @@ public:
403 dst[1] = (T*) malloc(max_batch_bytes); 403 dst[1] = (T*) malloc(max_batch_bytes);
404 404
405 size_t N[2]; //number of slices stored in buffers 0 and 1 405 size_t N[2]; //number of slices stored in buffers 0 and 1
406 - N[0] = N[1] = min(Y(), max_slices_per_batch); //start with the maximum number of slices that can be stored (may be the entire data set) 406 + N[0] = N[1] = std::min<size_t>(Y(), max_slices_per_batch); //start with the maximum number of slices that can be stored (may be the entire data set)
407 407
408 std::ofstream target(outname.c_str(), std::ios::binary); //open an output file for writing 408 std::ofstream target(outname.c_str(), std::ios::binary); //open an output file for writing
409 //initialize with buffer 0 (used for double buffering) 409 //initialize with buffer 0 (used for double buffering)
@@ -425,7 +425,7 @@ public: @@ -425,7 +425,7 @@ public:
425 if(y_load < Y()){ //if there are still slices to be loaded, load them 425 if(y_load < Y()){ //if there are still slices to be loaded, load them
426 if(y_load + N[b] > Y()) N[b] = Y() - y_load; //if the next batch would process more than the total slices, adjust the batch size 426 if(y_load + N[b] > Y()) N[b] = Y() - y_load; //if the next batch would process more than the total slices, adjust the batch size
427 rthread = std::async(std::launch::async, &stim::bsq<T>::readlines, this, src[b], y_load, N[b]); 427 rthread = std::async(std::launch::async, &stim::bsq<T>::readlines, this, src[b], y_load, N[b]);
428 - 428 + //rthread.wait();
429 y_load += N[b]; //increment the number of loaded slices 429 y_load += N[b]; //increment the number of loaded slices
430 } 430 }
431 431
@@ -438,7 +438,7 @@ public: @@ -438,7 +438,7 @@ public:
438 t_end = std::chrono::high_resolution_clock::now(); 438 t_end = std::chrono::high_resolution_clock::now();
439 t_batch = std::chrono::duration_cast<std::chrono::milliseconds>(t_end-t_start).count(); 439 t_batch = std::chrono::duration_cast<std::chrono::milliseconds>(t_end-t_start).count();
440 t_total += t_batch; 440 t_total += t_batch;
441 - rthread.wait(); 441 + if(y_load < Y()) rthread.wait(); //if a new batch was set to load, make sure it loads after calculations
442 } 442 }
443 443
444 std::cout<<"Total time to execute: "<<t_total<<" ms"<<std::endl; 444 std::cout<<"Total time to execute: "<<t_total<<" ms"<<std::endl;
@@ -471,7 +471,7 @@ public: @@ -471,7 +471,7 @@ public:
471 dst[1] = (T*) malloc(max_batch_bytes); 471 dst[1] = (T*) malloc(max_batch_bytes);
472 472
473 size_t N[2]; //number of slices stored in buffers 0 and 1 473 size_t N[2]; //number of slices stored in buffers 0 and 1
474 - N[0] = N[1] = min(Y(), max_slices_per_batch); //start with the maximum number of slices that can be stored (may be the entire data set) 474 + N[0] = N[1] = std::min<size_t>(Y(), max_slices_per_batch); //start with the maximum number of slices that can be stored (may be the entire data set)
475 475
476 std::ofstream target(outname.c_str(), std::ios::binary); //open an output file for writing 476 std::ofstream target(outname.c_str(), std::ios::binary); //open an output file for writing
477 //initialize with buffer 0 (used for double buffering) 477 //initialize with buffer 0 (used for double buffering)
@@ -506,7 +506,7 @@ public: @@ -506,7 +506,7 @@ public:
506 t_end = std::chrono::high_resolution_clock::now(); 506 t_end = std::chrono::high_resolution_clock::now();
507 t_batch = std::chrono::duration_cast<std::chrono::milliseconds>(t_end-t_start).count(); 507 t_batch = std::chrono::duration_cast<std::chrono::milliseconds>(t_end-t_start).count();
508 t_total += t_batch; 508 t_total += t_batch;
509 - rthread.wait(); 509 + if(y_load < Y()) rthread.wait(); //if a batch was threaded to load, make sure it finishes
510 } 510 }
511 511
512 std::cout<<"Total time to execute: "<<t_total<<" ms"<<std::endl; 512 std::cout<<"Total time to execute: "<<t_total<<" ms"<<std::endl;