19#define DBM_LIBRARY_PRINT(FN, MSG, OUTPUT_UNIT) \
20 ((FN)(MSG, (int)strlen(MSG), OUTPUT_UNIT))
29#error "OpenMP is required. Please add -fopenmp to your C compiler flags."
40 fprintf(stderr,
"DBM library was already initialized.\n");
53#pragma omp parallel default(none) shared(per_thread_counters) \
54 num_threads(max_threads)
56 const int ithread = omp_get_thread_num();
74 fprintf(stderr,
"Error: DBM library is not initialized.\n");
94 const int ithread = omp_get_thread_num();
121 const int64_t x = *(
const int64_t *)a, y = *(
const int64_t *)b;
122 return (x < y) - (x > y);
131 const int output_unit) {
135 fprintf(stderr,
"Error: DBM library is not initialized.\n");
149 total += counters[
i][0];
161 phase_min[
i] = -phase_max[
i];
162 phase_avg[
i] = phase_max[
i];
178 if (counters[
i][0] != 0) {
190 " ----------------------------------------------------------------"
210 " ----------------------------------------------------------------"
219 const char *labels[] = {
"?",
"??",
"???",
">999"};
222 if (counters[
i][0] == 0) {
225 const double percent = 100.0 * counters[
i][0] / total;
226 const int idx = counters[
i][1];
227 const int m = (
idx % 64) / 16;
228 const int n = (
idx % 16) / 4;
229 const int k = (
idx % 4) / 1;
230 snprintf(buffer,
sizeof(buffer),
231 " %4s x %4s x %4s %46" PRId64
" %10.2f%%\n", labels[m],
232 labels[n], labels[k], counters[
i][0], percent);
238 const char *
const phases[] = {
"setup",
"pack",
"alltoall",
239 "sort",
"shift",
"upload",
240 "multiply",
"finish",
"total"};
243 " ----------------------------------------------------------------"
246 snprintf(buffer,
sizeof(buffer),
" %-24s %12s %12s %12s %12s\n",
247 "PHASE PER RANK",
"MIN [s]",
"AVG [s]",
"MAX [s]",
"GB/s");
253 const int n = snprintf(
254 buffer,
sizeof(buffer),
" %-24s %12.3f %12.3f %12.3f", phases[
i],
255 -phase_min[
i], phase_avg[
i] / nranks, phase_max[
i]);
257 snprintf(buffer + n,
sizeof(buffer) - n,
" %12.1f\n",
258 1E-9 * bytes[
i] / phase_avg[
i]);
260 snprintf(buffer + n,
sizeof(buffer) - n,
"\n");
268 " ----------------------------------------------------------------"
#define cp_assert(condition)
int cp_mpi_comm_size(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_size.
void cp_mpi_sum_double(double *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_DOUBLE.
void cp_mpi_max_double(double *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_DOUBLE.
void cp_mpi_sum_int64(int64_t *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT64_T.
cp_mpi_comm_t cp_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
static bool library_initialized
void dbm_library_finalize(void)
Finalizes the DBM library.
void dbm_library_counters_add(const int64_t counters[DBM_NUM_COUNTERS])
Add the calling thread's counts to the stats. This routine is thread-safe.
#define DBM_LIBRARY_PRINT(FN, MSG, OUTPUT_UNIT)
void dbm_library_print_stats(const int fortran_comm, void(*print_func)(const char *, int, int), const int output_unit)
Prints statistics gathered by the DBM library.
static int64_t phase_bytes[DBM_NUM_PHASES]
void dbm_library_init(void)
Initializes the DBM library.
static double phase_seconds[DBM_NUM_PHASES]
static int compare_counters(const void *a, const void *b)
Comperator passed to qsort to compare two counters.
void dbm_library_phases_add(const double seconds[DBM_NUM_PHASES], const int64_t bytes[DBM_NUM_PHASES])
Add the durations (seconds) of a multiplication's phases to the stats. Called once per dbm_multiply o...
static int64_t ** per_thread_counters
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
static void const int const int i
void offload_init(void)
Initialize runtime.
void offload_mempool_clear(void)
Internal routine for freeing all memory in the pool.