Line data Source code
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 : ******************************************************************************/
18 : void dbm_library_init(void);
19 :
20 : /*******************************************************************************
21 : * \brief Finalizes the DBM library.
22 : * \author Ole Schuett
23 : ******************************************************************************/
24 : void 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 : ******************************************************************************/
33 28637784 : static inline int dbm_library_counter_index(const int m, const int n,
34 : const int k) {
35 28637784 : const int lm = (100 <= m ? (1000 <= m ? 3 : 2) : (10 <= m ? 1 : 0));
36 28637784 : const int ln = (100 <= n ? (1000 <= n ? 3 : 2) : (10 <= n ? 1 : 0));
37 28637784 : const int lk = (100 <= k ? (1000 <= k ? 3 : 2) : (10 <= k ? 1 : 0));
38 28637784 : 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 : ******************************************************************************/
47 : void 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 : ******************************************************************************/
53 : enum dbm_library_phase {
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
62 : DBM_NUM_PHASES = 8
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 : ******************************************************************************/
71 : void 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 : ******************************************************************************/
78 : void 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
|