(git:3f0d10b)
Loading...
Searching...
No Matches
dbm_library.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#ifndef DBM_LIBRARY_H
8#define DBM_LIBRARY_H
9
10#include "dbm_multiply.h"
11
12#include <stdint.h>
13
14/*******************************************************************************
15 * \brief Initializes the DBM library.
16 * \author Ole Schuett
17 ******************************************************************************/
18void dbm_library_init(void);
19
20/*******************************************************************************
21 * \brief Finalizes the DBM library.
22 * \author Ole Schuett
23 ******************************************************************************/
24void dbm_library_finalize(void);
25
26#define DBM_NUM_COUNTERS 64
27
28/*******************************************************************************
29 * \brief Internal routine for the stats counter of a block multiplication,
30 * i.e., min(3, floor(log10(x))) per m, n, and k.
31 * \author Ole Schuett
32 ******************************************************************************/
33static inline int dbm_library_counter_index(const int m, const int n,
34 const int k) {
35 const int lm = (100 <= m ? (1000 <= m ? 3 : 2) : (10 <= m ? 1 : 0));
36 const int ln = (100 <= n ? (1000 <= n ? 3 : 2) : (10 <= n ? 1 : 0));
37 const int lk = (100 <= k ? (1000 <= k ? 3 : 2) : (10 <= k ? 1 : 0));
38 return 16 * lm + 4 * ln + lk;
39}
40
41/*******************************************************************************
42 * \brief Add the calling thread's counts (dbm_library_counter_index) to the
43 * stats. Counting locally first avoids a call per block multiplication.
44 * This routine is thread-safe.
45 * \author Hans Pabst
46 ******************************************************************************/
47void dbm_library_counters_add(const int64_t counters[DBM_NUM_COUNTERS]);
48
49/*******************************************************************************
50 * \brief Phases of dbm_multiply whose duration the stats report per rank.
51 * \author Hans Pabst
52 ******************************************************************************/
54 DBM_PHASE_SETUP = 0, // scaling, filter thresholds, backend, filter
55 DBM_PHASE_PACK = 1, // planning and filling the redistribution's buffers
56 DBM_PHASE_ALLTOALL = 2, // redistribution's all-to-all exchange
57 DBM_PHASE_SORT = 3, // sorting the redistributed blocks
58 DBM_PHASE_SHIFT = 4, // exchanging packs per tick (sendrecv)
59 DBM_PHASE_UPLOAD = 5, // handing packs to the backend
60 DBM_PHASE_MULTIPLY = 6, // generating and processing batches
61 DBM_PHASE_FINISH = 7, // backend stop, i.e., waiting for the results
63};
64
65/*******************************************************************************
66 * \brief Add the durations (seconds) of a multiplication's phases and the
67 * bytes sent by them to the stats. Called once per dbm_multiply
68 * outside of parallel regions.
69 * \author Hans Pabst
70 ******************************************************************************/
71void dbm_library_phases_add(const double seconds[DBM_NUM_PHASES],
72 const int64_t bytes[DBM_NUM_PHASES]);
73
74/*******************************************************************************
75 * \brief Prints statistics gathered by the DBM library.
76 * \author Ole Schuett
77 ******************************************************************************/
78void dbm_library_print_stats(const int fortran_comm,
79 void (*print_func)(const char *, int, int),
80 const int output_unit);
81
82#endif
83
84// EOF
void dbm_library_finalize(void)
Finalizes the DBM library.
Definition dbm_library.c:70
void dbm_library_counters_add(const int64_t counters[DBM_NUM_COUNTERS])
Add the calling thread's counts (dbm_library_counter_index) to the stats. Counting locally first avoi...
Definition dbm_library.c:93
#define DBM_NUM_COUNTERS
Definition dbm_library.h:26
static int dbm_library_counter_index(const int m, const int n, const int k)
Internal routine for the stats counter of a block multiplication, i.e., min(3, floor(log10(x))) per m...
Definition dbm_library.h:33
dbm_library_phase
Phases of dbm_multiply whose duration the stats report per rank.
Definition dbm_library.h:53
@ DBM_NUM_PHASES
Definition dbm_library.h:62
@ DBM_PHASE_ALLTOALL
Definition dbm_library.h:56
@ DBM_PHASE_FINISH
Definition dbm_library.h:61
@ DBM_PHASE_SORT
Definition dbm_library.h:57
@ DBM_PHASE_MULTIPLY
Definition dbm_library.h:60
@ DBM_PHASE_UPLOAD
Definition dbm_library.h:59
@ DBM_PHASE_SHIFT
Definition dbm_library.h:58
@ DBM_PHASE_SETUP
Definition dbm_library.h:54
@ DBM_PHASE_PACK
Definition dbm_library.h:55
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.
void dbm_library_init(void)
Initializes the DBM library.
Definition dbm_library.c:36
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 and the bytes sent by them to the stats....
static void print_func(const char *msg, int msglen, int output_unit)
Wrapper for printf, passed to dbm_library_print_stats.
Definition dbm_miniapp.c:26