21#define GRID_LIBRARY_PRINT(FN, MSG, OUTPUT_UNIT) \
22 ((FN)(MSG, (int)strlen(MSG), OUTPUT_UNIT))
25#define GRID_NBACKENDS 5
26#define GRID_NKERNELS 4
43#error "OpenMP is required. Please add -fopenmp to your C compiler flags."
48 "Please do not build CP2K with NDEBUG. There is no performance advantage and asserts will save your neck."
57 printf(
"Error: Grid library was already initialized.\n");
61#if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_GRID)
67 offloadEnsureMallocHeapSize(64 * 1024 * 1024);
75#pragma omp parallel default(none) shared(per_thread_globals) \
76 num_threads(max_threads)
78 const int ithread = omp_get_thread_num();
93 printf(
"Error: Grid library is not initialized.\n");
112 const int ithread = omp_get_thread_num();
122 const int ithread = omp_get_thread_num();
127 globals->
scratch = malloc(bytes);
128 assert(globals->
scratch != NULL);
141 config.validate = validate;
157 const int increment) {
164 const int ithread = omp_get_thread_num();
174 return *(
long *)b - *(
long *)a;
183 const int output_unit) {
185 printf(
"Error: Grid library is not initialized.\n");
192 long counters[ncounters][2];
193 memset(counters, 0, ncounters * 2 *
sizeof(
long));
195 for (
int i = 0;
i < ncounters;
i++) {
201 total += counters[
i][0];
209 for (
int i = 0;
i < ncounters && !print;
i++) {
210 if (counters[
i][0] != 0) {
222 " ----------------------------------------------------------------"
232 " - GRID STATISTICS "
242 " ----------------------------------------------------------------"
247 " LP KERNEL BACKEND "
251 const char *kernel_names[] = {
"collocate ortho",
"integrate ortho",
252 "collocate general",
"integrate general"};
253 const char *backend_names[] = {
"REF",
"CPU",
"DGEMM",
"GPU"};
255 for (
int i = 0;
i < ncounters;
i++) {
256 if (counters[
i][0] == 0)
258 const double percent = 100.0 * counters[
i][0] / total;
259 const int idx = counters[
i][1];
261 const int back =
idx / backend_stride;
265 snprintf(buffer,
sizeof(buffer),
" %-5i %-17s %-6s %34li %10.2f%%\n", lp,
266 kernel_names[kern], backend_names[back], counters[
i][0], percent);
272 " ----------------------------------------------------------------"
void cp_mpi_sum_long(long *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_LONG.
cp_mpi_comm_t cp_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
static bool library_initialized
static int compare_counters(const void *a, const void *b)
Comperator passed to qsort to compare two counters.
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
static int imin(int x, int y)
Returns the smaller of the two integers (missing from the C standard).
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 apply_cutoff(void *ptr)
void grid_library_finalize(void)
Finalizes the grid library.
#define GRID_LIBRARY_PRINT(FN, MSG, OUTPUT_UNIT)
static grid_library_config config
void * grid_library_get_scratch(const size_t bytes)
Returns a pointer to a thread local scratch buffer with at least the given size. The buffer grows on ...
grid_sphere_cache * grid_library_get_sphere_cache(void)
Returns a pointer to the thread local sphere cache.
void grid_library_init(void)
Initializes the grid library.
grid_library_config grid_library_get_config(void)
Returns the library config.
void grid_library_counter_add(const int lp, const enum grid_backend backend, const enum grid_library_kernel kernel, const int increment)
Adds given increment to counter specified by lp, backend, and kernel.
void grid_library_set_config(const enum grid_backend backend, const bool validate, const bool apply_cutoff)
Configures the grid library.
void grid_library_print_stats(const int fortran_comm, void(*print_func)(const char *, int, int), const int output_unit)
Prints statistics gathered by the grid library.
static int compare_counters(const void *a, const void *b)
Comperator passed to qsort to compare two counters.
static grid_library_globals ** per_thread_globals
grid_library_kernel
Various kernels provided by the grid library.
void grid_sphere_cache_free(grid_sphere_cache *cache)
Free the memory of the sphere cache.
Configuration of the grid library.
grid_sphere_cache sphere_cache
long counters[GRID_NBACKENDS *GRID_NKERNELS *GRID_MAX_LP]
Struct holding the entire sphere cache, ie. for all grids.