28 #ifndef _H_GRB_BENCH_BASE 29 #define _H_GRB_BENCH_BASE 41 #ifndef _GRB_NO_EXCEPTIONS 48 #include <graphblas/utils.hpp> 49 #include <graphblas/utils/timerResults.hpp> 90 class BenchmarkerBase {
103 static void printTimeSinceEpoch(
const bool printHeader =
true ) {
104 const auto now = std::chrono::system_clock::now();
105 const auto since = now.time_since_epoch();
107 std::cout <<
"Time since epoch (in ms.): ";
109 std::cout << std::chrono::duration_cast<
110 std::chrono::milliseconds
111 >( since ).count() <<
"\n";
118 static void benchmark_calc_inner(
121 grb::utils::TimerResults &inner_times,
122 grb::utils::TimerResults &total_times,
123 grb::utils::TimerResults &min_times,
124 grb::utils::TimerResults &max_times,
125 std::vector< grb::utils::TimerResults > &sdev_times
127 inner_times.normalize( total );
128 total_times.accum( inner_times );
129 min_times.min( inner_times );
130 max_times.max( inner_times );
131 sdev_times[ loop ] = inner_times;
137 static void benchmark_calc_outer(
139 grb::utils::TimerResults &total_times,
140 grb::utils::TimerResults &min_times,
141 grb::utils::TimerResults &max_times,
142 std::vector< grb::utils::TimerResults > &sdev_times,
145 total_times.normalize( total );
146 grb::utils::TimerResults sdev;
150 for(
size_t i = 0; i < total; i++ ) {
151 double diff = sdev_times[ i ].io - total_times.io;
152 sdev.io += diff * diff;
153 diff = sdev_times[ i ].preamble - total_times.preamble;
154 sdev.preamble += diff * diff;
155 diff = sdev_times[ i ].useful - total_times.useful;
156 sdev.useful += diff * diff;
157 diff = sdev_times[ i ].postamble - total_times.postamble;
158 sdev.postamble += diff * diff;
161 sdev.normalize( total - 1 );
163 #ifndef _GRB_NO_STDIO 166 std::cout <<
"Overall timings (io, preamble, useful, postamble):\n" 168 std::cout <<
"Avg: " << total_times.io <<
", " << total_times.preamble
169 <<
", " << total_times.useful <<
", " << total_times.postamble <<
"\n";
170 std::cout <<
"Min: " << min_times.io <<
", " << min_times.preamble <<
", " 171 << min_times.useful <<
", " << min_times.postamble <<
"\n";
172 std::cout <<
"Max: " << max_times.io <<
", " << max_times.preamble <<
", " 173 << max_times.useful <<
", " << max_times.postamble <<
"\n";
174 std::cout <<
"Std: " << sqrt( sdev.io ) <<
", " << sqrt( sdev.preamble )
175 <<
", " << sqrt( sdev.useful ) <<
", " << sqrt( sdev.postamble ) <<
"\n";
177 std::cout << std::defaultfloat;
179 printTimeSinceEpoch();
217 grb::utils::TimerResults ×,
218 const size_t inner,
const size_t outer,
221 const double inf = std::numeric_limits< double >::infinity();
222 grb::utils::TimerResults total_times, min_times, max_times;
223 std::vector< grb::utils::TimerResults > sdev_times( outer );
224 total_times.set( 0 );
225 min_times.set( inf );
230 for(
size_t out = 0; out < outer && ret ==
grb::SUCCESS; ++out ) {
231 grb::utils::TimerResults inner_times;
232 inner_times.set( 0 );
235 for(
size_t in = 0; in < inner && ret ==
grb::SUCCESS; ++in ) {
250 inner_times.accum( times );
256 benchmark_calc_inner( out, inner, inner_times, total_times, min_times,
257 max_times, sdev_times );
260 #ifndef _GRB_NO_STDIO 264 std::ios_base::fmtflags prev_cout_state( std::cout.flags() );
265 std::cout <<
"Outer iteration #" << out <<
" timings " 266 <<
"(io, preamble, useful, postamble, time since epoch): " 268 << inner_times.io <<
", " << inner_times.preamble <<
", " 269 << inner_times.useful <<
", " << inner_times.postamble <<
", ";
270 printTimeSinceEpoch(
false );
271 std::cout.flags( prev_cout_state );
273 std::cerr <<
"Error during cross-process collection of timing results: " 281 #ifndef _GRB_NO_STDIO 282 std::cerr <<
"Sleep interrupted, assume benchmark is unreliable; " 291 benchmark_calc_outer( outer, total_times, min_times, max_times,
325 AlpUntypedFunc< U > alp_program,
326 const void * data_in,
const size_t in_size,
328 const size_t inner,
const size_t outer,
331 auto runner = [ alp_program, data_in, in_size, &data_out ] {
332 alp_program( data_in, in_size, data_out );
334 return benchmark< implementation >( runner, data_out.times, inner, outer,
361 typename T,
typename U,
365 AlpTypedFunc< T, U > alp_program,
366 const T &data_in, U &data_out,
367 const size_t inner,
const size_t outer,
370 auto runner = [ alp_program, &data_in, &data_out ] {
371 alp_program( data_in, data_out );
373 return benchmark< implementation >( runner, data_out.times, inner, outer,
381 #ifndef _GRB_NO_STDIO 382 printTimeSinceEpoch();
398 template< enum EXEC_MODE mode, enum Backend implementation >
432 const size_t process_id = 0,
433 const size_t nprocs = 1,
434 const std::string hostname =
"localhost",
435 const std::string port =
"0" 441 #ifndef _GRB_NO_EXCEPTIONS 442 throw std::logic_error(
"Benchmarker class called with unsupported mode or " 485 template<
typename T,
typename U >
487 void ( *alp_program )(
const T &, U & ),
488 const T &data_in, U &data_out,
489 const size_t inner,
const size_t outer,
490 const bool broadcast =
false 503 #ifndef _GRB_NO_STDIO 504 std::cerr <<
"Error: base Benchmarker::exec called. An implementation-" 505 <<
"specific variant should have been called instead.\n";
548 template<
typename U >
550 void ( *alp_program )(
const void *,
const size_t, U & ),
551 const void * data_in,
const size_t in_size,
553 const size_t inner,
const size_t outer,
554 const bool broadcast =
false 568 #ifndef _GRB_NO_STDIO 569 std::cerr <<
"Error: base Benchmarker::exec called. An implementation-" 570 <<
"specific variant should have been called instead.\n";
600 #endif // end _H_GRB_BENCH_BASE Defines the ALP error codes.
This file contains a register of all backends that are either implemented, under implementation,...
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
static RC finalize()
Releases all ALP resources.
Definition: benchmark.hpp:592
Benchmarker(const size_t process_id=0, const size_t nprocs=1, const std::string hostname="localhost", const std::string port="0")
Constructs an instance of the benchmarker class.
Definition: benchmark.hpp:431
This operator takes the maximum of the two input parameters and writes the result to the output varia...
Definition: ops.hpp:241
RC exec(void(*alp_program)(const void *, const size_t, U &), const void *data_in, const size_t in_size, U &data_out, const size_t inner, const size_t outer, const bool broadcast=false) const
Benchmarks a given ALP program.
Definition: benchmark.hpp:549
static RC reduce(IOType &inout, const size_t root=0, const Operator op=Operator())
Schedules a reduce operation of a single object of type IOType per process.
Definition: collectives.hpp:191
Backend
A collection of all backends.
Definition: backends.hpp:49
Specifies the grb::Launcher functionalities.
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
A class that follows the API of the grb::Launcher, but instead of launching the given ALP program onc...
Definition: benchmark.hpp:399
RC exec(void(*alp_program)(const T &, U &), const T &data_in, U &data_out, const size_t inner, const size_t outer, const bool broadcast=false) const
Benchmarks a given ALP program.
Definition: benchmark.hpp:486
Generic fatal error code.
Definition: rc.hpp:68
Defines both configuration parameters effective for all backends, as well as defines structured ways ...
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
Specifies some basic collectives which may be used within a multi-process ALP program.
static RC finalize()
Releases all ALP resources.
Definition: exec.hpp:431
Provides a set of standard binary operators.
std::string toString(const RC code)