28#ifndef _H_GRB_BENCH_BASE
29#define _H_GRB_BENCH_BASE
39#include <graphblas/utils.hpp>
40#include <graphblas/utils/TimerResults.hpp>
50#ifndef _GRB_NO_EXCEPTIONS
91 class BenchmarkerBase {
104 static void printTimeSinceEpoch(
const bool printHeader =
true ) {
105 const auto now = std::chrono::system_clock::now();
106 const auto since = now.time_since_epoch();
108 std::cout <<
"Time since epoch (in ms.): ";
110 std::cout << std::chrono::duration_cast<
111 std::chrono::milliseconds
112 >( since ).count() <<
"\n";
119 static void benchmark_calc_inner(
122 grb::utils::TimerResults &inner_times,
123 grb::utils::TimerResults &total_times,
124 grb::utils::TimerResults &min_times,
125 grb::utils::TimerResults &max_times,
126 grb::utils::TimerResults * sdev_times
128 inner_times.normalize( total );
129 total_times.accum( inner_times );
130 min_times.min( inner_times );
131 max_times.max( inner_times );
132 sdev_times[ loop ] = inner_times;
138 static void benchmark_calc_outer(
140 grb::utils::TimerResults &total_times,
141 grb::utils::TimerResults &min_times,
142 grb::utils::TimerResults &max_times,
143 grb::utils::TimerResults * sdev_times,
146 total_times.normalize( total );
147 grb::utils::TimerResults sdev;
151 for(
size_t i = 0; i < total; i++ ) {
152 double diff = sdev_times[ i ].io - total_times.io;
153 sdev.io += diff * diff;
154 diff = sdev_times[ i ].preamble - total_times.preamble;
155 sdev.preamble += diff * diff;
156 diff = sdev_times[ i ].useful - total_times.useful;
157 sdev.useful += diff * diff;
158 diff = sdev_times[ i ].postamble - total_times.postamble;
159 sdev.postamble += diff * diff;
162 sdev.normalize( total - 1 );
167 std::cout <<
"Overall timings (io, preamble, useful, postamble):\n"
169 std::cout <<
"Avg: " << total_times.io <<
", " << total_times.preamble
170 <<
", " << total_times.useful <<
", " << total_times.postamble <<
"\n";
171 std::cout <<
"Min: " << min_times.io <<
", " << min_times.preamble <<
", "
172 << min_times.useful <<
", " << min_times.postamble <<
"\n";
173 std::cout <<
"Max: " << max_times.io <<
", " << max_times.preamble <<
", "
174 << max_times.useful <<
", " << max_times.postamble <<
"\n";
175 std::cout <<
"Std: " << sqrt( sdev.io ) <<
", " << sqrt( sdev.preamble )
176 <<
", " << sqrt( sdev.useful ) <<
", " << sqrt( sdev.postamble ) <<
"\n";
178 std::cout << std::defaultfloat;
180 printTimeSinceEpoch();
215 enum Backend implementation = config::default_backend
218 void ( *alp_program )(
const void *,
const size_t, U & ),
219 const void * data_in,
220 const size_t in_size,
226 const double inf = std::numeric_limits< double >::infinity();
227 grb::utils::TimerResults total_times, min_times, max_times;
228 grb::utils::TimerResults * sdev_times =
229 new grb::utils::TimerResults[ outer ];
230 total_times.set( 0 );
231 min_times.set( inf );
235 for(
size_t out = 0; out < outer; ++out ) {
236 grb::utils::TimerResults inner_times;
237 inner_times.set( 0 );
240 for(
size_t in = 0; in < inner; in++ ) {
241 data_out.times.set( 0 );
242 ( *alp_program )( data_in, in_size, data_out );
251 inner_times.accum( data_out.times );
255 benchmark_calc_inner( out, inner, inner_times, total_times, min_times,
256 max_times, sdev_times );
261 std::cout <<
"Outer iteration #" << out <<
" timings (io, preamble, "
262 <<
"useful, postamble, time since epoch): ";
263 std::cout << inner_times.io <<
", " << inner_times.preamble <<
", "
264 << inner_times.useful <<
", " << inner_times.postamble <<
", ";
265 printTimeSinceEpoch(
false );
270 if( sleep( 1 ) != 0 ) {
272 std::cerr <<
"Sleep interrupted, assume benchmark is unreliable; "
280 benchmark_calc_outer( outer, total_times, min_times, max_times, sdev_times,
282 delete [] sdev_times;
309 typename T,
typename U,
310 enum Backend implementation = config::default_backend
313 void ( *alp_program )(
const T &, U & ),
320 const double inf = std::numeric_limits< double >::infinity();
321 grb::utils::TimerResults total_times, min_times, max_times;
322 grb::utils::TimerResults * sdev_times =
323 new grb::utils::TimerResults[ outer ];
324 total_times.set( 0 );
325 min_times.set( inf );
329 for(
size_t out = 0; out < outer; ++out ) {
330 grb::utils::TimerResults inner_times;
331 inner_times.set( 0 );
334 for(
size_t in = 0; in < inner; ++in ) {
335 data_out.times.set( 0 );
337 ( *alp_program )( data_in, data_out );
346 inner_times.accum( data_out.times );
350 benchmark_calc_inner( out, inner, inner_times, total_times, min_times,
351 max_times, sdev_times );
356 std::cout <<
"Outer iteration #" << out <<
" timings "
357 <<
"(io, preamble, useful, postamble, time since epoch): " << std::fixed
358 << inner_times.io <<
", " << inner_times.preamble <<
", "
359 << inner_times.useful <<
", " << inner_times.postamble <<
", ";
360 printTimeSinceEpoch(
false );
361 std::cout << std::scientific;
366 if( sleep( 1 ) != 0 ) {
368 std::cerr <<
"Sleep interrupted, assume benchmark is unreliable; "
376 benchmark_calc_outer( outer, total_times, min_times, max_times, sdev_times,
388 printTimeSinceEpoch();
404 template< enum EXEC_MODE mode, enum Backend implementation >
438 const size_t process_id = 0,
440 std::string hostname =
"localhost",
441 std::string port =
"0"
443 (void)process_id; (void)nprocs; (void)hostname; (void)port;
444#ifndef _GRB_NO_EXCEPTIONS
445 throw std::logic_error(
"Benchmarker class called with unsupported mode or "
485 template<
typename T,
typename U >
487 void ( *alp_program )(
const T &, U & ),
492 const bool broadcast =
false
545 template<
typename U >
547 void ( *alp_program )(
const void *,
const size_t, U & ),
548 const void * data_in,
const size_t in_size,
550 const size_t inner,
const size_t outer,
551 const bool broadcast =
false
This file contains a register of all backends that are either implemented, under implementation,...
A class that follows the API of the grb::Launcher, but instead of launching the given ALP program onc...
Definition: benchmark.hpp:405
Benchmarker(const size_t process_id=0, size_t nprocs=1, std::string hostname="localhost", std::string port="0")
Constructs an instance of the benchmarker class.
Definition: benchmark.hpp:437
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:546
static RC finalize()
Releases all ALP resources.
Definition: benchmark.hpp:591
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
static RC finalize()
Releases all ALP resources.
Definition: exec.hpp:322
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
This operator takes the maximum of the two input parameters and writes the result to the output varia...
Definition: ops.hpp:243
Specifies some basic collectives which may be used within a multi-process ALP program.
Specifies the grb::Launcher functionalities.
Backend
A collection of all backends.
Definition: backends.hpp:46
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:452
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
@ PANIC
Generic fatal error code.
Definition: rc.hpp:68
@ SUCCESS
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
Provides a set of standard binary operators.
Defines the ALP error codes.
Contains the configuration parameters for the reference and reference_omp backends.