Loading src/CreateImage.cpp +23 −12 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ // Load the input file static RayTrace::create_image_struct *loadInput( const std::string &filename, double scale, double **image0 = nullptr, double **I_ang0 = nullptr ) static RayTrace::create_image_struct *loadInput( const std::string &filename, double scale, double **image0 = nullptr, double **I_ang0 = nullptr ) { // Load the input file FILE *fid = fopen( filename.c_str(), "rb" ); Loading Loading @@ -79,6 +79,11 @@ static inline void free2( RayTrace::create_image_struct *info ) delete info; } // Get the number of ns elapsed #define diff_ns( X, Y ) std::chrono::duration_cast<std::chrono::nanoseconds>( X - Y ).count() // Run the tests for a single file int run_tests( const std::string &filename, const Options &options ) { Loading Loading @@ -111,18 +116,24 @@ int run_tests( const std::string &filename, const Options &options ) if ( !serial ) RayTrace::create_image( info2, methods[i] ); // Run the timing tests auto t1 = std::chrono::steady_clock::now(); auto t0 = std::chrono::steady_clock::now(); while ( true ) { for ( int it = 0; it < iterations; it++ ) { auto t1 = std::chrono::steady_clock::now(); RayTrace::create_image( info, methods[i] ); if ( options.benchmark ) { // Mimic communication in full application communicate( *info ); } auto t2 = std::chrono::steady_clock::now(); auto dt = std::chrono::duration<double>( t2 - t1 ); time[i].push_back( dt.count() ); time[i].push_back( 1e-9 * diff_ns( t2, t1 ) ); t1 = t2; } double time = 1e-9 * diff_ns( std::chrono::steady_clock::now(), t0 ); time = bcast( time ); if ( time > options.time ) break; } time[i] = gatherAll( time[i] ); // Check the results if ( options.scale == 1.0 ) { Loading src/CreateImageHelpers.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -341,7 +341,8 @@ Options::Options( int argc, char *argv[] ) : iterations( 1 ), scale( 1.0 ) " -benchmark Run in benchmark mode.\n" " Benchmark mode will run the calculation across all nodes,\n" " returning the average rays/second processed\n" " Note: a single method must be specified\n"; " Note: a single method must be specified\n" " -time=xxx Run each method for a minimum of xxx seconds\n"; std::vector<std::string> exclude; // Process the input arguments for ( int i = 1; i < argc; i++ ) { Loading @@ -363,6 +364,8 @@ Options::Options( int argc, char *argv[] ) : iterations( 1 ), scale( 1.0 ) scale = atof( &argv[i][7] ); } else if ( strncmp( argv[i], "-benchmark", 10 ) == 0 ) { benchmark = true; } else if ( strncmp( argv[i], "-time=", 6 ) == 0 ) { time = atoi( &argv[i][6] ); } else { std::cerr << "Unknown option: " << argv[i] << std::endl; exit( 1 ); Loading src/CreateImageHelpers.h +1 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ public: bool benchmark = false; int iterations = 1; double scale = 1.0; double time = 0; std::vector<std::string> methods; std::vector<std::string> filenames; }; Loading src/MPI_helpers.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,12 @@ int sumReduce( const int val ) MPI_Allreduce( &val, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); return result; } double bcast( double x, int root ) { double y = x; MPI_Bcast( &y, 1, MPI_DOUBLE, root, MPI_COMM_WORLD ); return y; } std::vector<double> gatherAll( const std::vector<double>& x ) { std::vector<double> y( x.size() * size(), 0 ); Loading @@ -50,6 +56,7 @@ void barrier() {} int rank() { return 0; } int size() { return 1; } int sumReduce( const int val ) { return val; } double bcast( double x, int ) { return x; } std::vector<double> gatherAll( const std::vector<double>& x ) { return x; } #endif src/MPI_helpers.h +1 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,5 @@ void barrier(); int rank(); int size(); int sumReduce( const int val ); double bcast( double x, int root = 0 ); std::vector<double> gatherAll( const std::vector<double>& x ); Loading
src/CreateImage.cpp +23 −12 Original line number Diff line number Diff line Loading @@ -24,8 +24,8 @@ // Load the input file static RayTrace::create_image_struct *loadInput( const std::string &filename, double scale, double **image0 = nullptr, double **I_ang0 = nullptr ) static RayTrace::create_image_struct *loadInput( const std::string &filename, double scale, double **image0 = nullptr, double **I_ang0 = nullptr ) { // Load the input file FILE *fid = fopen( filename.c_str(), "rb" ); Loading Loading @@ -79,6 +79,11 @@ static inline void free2( RayTrace::create_image_struct *info ) delete info; } // Get the number of ns elapsed #define diff_ns( X, Y ) std::chrono::duration_cast<std::chrono::nanoseconds>( X - Y ).count() // Run the tests for a single file int run_tests( const std::string &filename, const Options &options ) { Loading Loading @@ -111,18 +116,24 @@ int run_tests( const std::string &filename, const Options &options ) if ( !serial ) RayTrace::create_image( info2, methods[i] ); // Run the timing tests auto t1 = std::chrono::steady_clock::now(); auto t0 = std::chrono::steady_clock::now(); while ( true ) { for ( int it = 0; it < iterations; it++ ) { auto t1 = std::chrono::steady_clock::now(); RayTrace::create_image( info, methods[i] ); if ( options.benchmark ) { // Mimic communication in full application communicate( *info ); } auto t2 = std::chrono::steady_clock::now(); auto dt = std::chrono::duration<double>( t2 - t1 ); time[i].push_back( dt.count() ); time[i].push_back( 1e-9 * diff_ns( t2, t1 ) ); t1 = t2; } double time = 1e-9 * diff_ns( std::chrono::steady_clock::now(), t0 ); time = bcast( time ); if ( time > options.time ) break; } time[i] = gatherAll( time[i] ); // Check the results if ( options.scale == 1.0 ) { Loading
src/CreateImageHelpers.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -341,7 +341,8 @@ Options::Options( int argc, char *argv[] ) : iterations( 1 ), scale( 1.0 ) " -benchmark Run in benchmark mode.\n" " Benchmark mode will run the calculation across all nodes,\n" " returning the average rays/second processed\n" " Note: a single method must be specified\n"; " Note: a single method must be specified\n" " -time=xxx Run each method for a minimum of xxx seconds\n"; std::vector<std::string> exclude; // Process the input arguments for ( int i = 1; i < argc; i++ ) { Loading @@ -363,6 +364,8 @@ Options::Options( int argc, char *argv[] ) : iterations( 1 ), scale( 1.0 ) scale = atof( &argv[i][7] ); } else if ( strncmp( argv[i], "-benchmark", 10 ) == 0 ) { benchmark = true; } else if ( strncmp( argv[i], "-time=", 6 ) == 0 ) { time = atoi( &argv[i][6] ); } else { std::cerr << "Unknown option: " << argv[i] << std::endl; exit( 1 ); Loading
src/CreateImageHelpers.h +1 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,7 @@ public: bool benchmark = false; int iterations = 1; double scale = 1.0; double time = 0; std::vector<std::string> methods; std::vector<std::string> filenames; }; Loading
src/MPI_helpers.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,12 @@ int sumReduce( const int val ) MPI_Allreduce( &val, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); return result; } double bcast( double x, int root ) { double y = x; MPI_Bcast( &y, 1, MPI_DOUBLE, root, MPI_COMM_WORLD ); return y; } std::vector<double> gatherAll( const std::vector<double>& x ) { std::vector<double> y( x.size() * size(), 0 ); Loading @@ -50,6 +56,7 @@ void barrier() {} int rank() { return 0; } int size() { return 1; } int sumReduce( const int val ) { return val; } double bcast( double x, int ) { return x; } std::vector<double> gatherAll( const std::vector<double>& x ) { return x; } #endif
src/MPI_helpers.h +1 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,5 @@ void barrier(); int rank(); int size(); int sumReduce( const int val ); double bcast( double x, int root = 0 ); std::vector<double> gatherAll( const std::vector<double>& x );