19#define DBM_NUM_COUNTERS 64
26#error "OpenMP is required. Please add -fopenmp to your C compiler flags."
34 assert(omp_get_num_threads() == 1);
37 fprintf(stderr,
"DBM library was already initialized.\n");
46#pragma omp parallel default(none) shared(per_thread_counters) \
47 num_threads(max_threads)
49 const int ithread = omp_get_thread_num();
64 assert(omp_get_num_threads() == 1);
67 fprintf(stderr,
"Error: DBM library is not initialized.\n");
103 const int ithread = omp_get_thread_num();
114 return *(
const int64_t *)b - *(
const int64_t *)a;
121void dbm_library_print_stats(
const int fortran_comm,
123 const int output_unit) {
124 assert(omp_get_num_threads() == 1);
127 fprintf(stderr,
"Error: DBM library is not initialized.\n");
141 total += counters[
i][0];
149 print_func(
" ----------------------------------------------------------------"
161 print_func(
" ----------------------------------------------------------------"
168 const char *labels[] = {
"?",
"??",
"???",
">999"};
171 if (counters[
i][0] == 0) {
174 const double percent = 100.0 * counters[
i][0] / total;
175 const int idx = counters[
i][1];
176 const int m = (
idx % 64) / 16;
177 const int n = (
idx % 16) / 4;
178 const int k = (
idx % 4) / 1;
179 snprintf(buffer,
sizeof(buffer),
180 " %4s x %4s x %4s %46" PRId64
" %10.2f%%\n", labels[m],
181 labels[n], labels[k], counters[
i][0], percent);
185 print_func(
" ----------------------------------------------------------------"
196 " Number of allocations Used [MiB] Size [MiB]\n",
201 snprintf(buffer,
sizeof(buffer),
203 " %20" PRIuPTR
" %10" PRIuPTR
" %10" PRIuPTR
"\n",
205 (uintptr_t)((memstats.
device_used + (512U << 10)) >> 20),
206 (uintptr_t)((memstats.
device_size + (512U << 10)) >> 20));
211 snprintf(buffer,
sizeof(buffer),
213 " %20" PRIuPTR
" %10" PRIuPTR
" %10" PRIuPTR
"\n",
215 (uintptr_t)((memstats.
host_used + (512U << 10)) >> 20),
216 (uintptr_t)((memstats.
host_size + (512U << 10)) >> 20));
221 " ----------------------------------------------------------------"
static bool library_initialized
void dbm_library_finalize(void)
Finalizes the DBM library.
void dbm_library_counter_increment(const int m, const int n, const int k)
Add given block multiplication to stats. This routine is thread-safe.
static int floorlog10(const int x)
Computes min(3, floor(log10(x))).
void dbm_library_init(void)
Initializes the DBM library.
static int compare_counters(const void *a, const void *b)
Comperator passed to qsort to compare two counters.
static int64_t ** per_thread_counters
void dbm_mempool_statistics(dbm_memstats_t *memstats)
Internal routine to query statistics.
void dbm_mempool_clear(void)
Internal routine for freeing all memory in the pool.
static void print_func(char *message, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
void dbm_mpi_sum_int64(int64_t *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT64_T.
void dbm_mpi_max_uint64(uint64_t *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_UINT64_T.
dbm_mpi_comm_t dbm_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
static void const int const int i
Internal struct for pool statistics.