(git:d18deda)
Loading...
Searching...
No Matches
dbm_mpi.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7
8#ifndef DBM_MPI_H
9#define DBM_MPI_H
10
11#include <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
14
15#if defined(__parallel)
16#include <mpi.h>
17typedef MPI_Comm dbm_mpi_comm_t;
18#else
19typedef int dbm_mpi_comm_t;
20#endif
21
22/*******************************************************************************
23 * \brief Wrapper around MPI_Init.
24 * \author Ole Schuett
25 ******************************************************************************/
26void dbm_mpi_init(int *argc, char ***argv);
27
28/*******************************************************************************
29 * \brief Wrapper around MPI_Finalize.
30 * \author Ole Schuett
31 ******************************************************************************/
32void dbm_mpi_finalize();
33
34/*******************************************************************************
35 * \brief Returns MPI_COMM_WORLD.
36 * \author Ole Schuett
37 ******************************************************************************/
39
40/*******************************************************************************
41 * \brief Wrapper around MPI_Comm_f2c.
42 * \author Ole Schuett
43 ******************************************************************************/
44dbm_mpi_comm_t dbm_mpi_comm_f2c(const int fortran_comm);
45
46/*******************************************************************************
47 * \brief Wrapper around MPI_Comm_c2f.
48 * \author Ole Schuett
49 ******************************************************************************/
50int dbm_mpi_comm_c2f(const dbm_mpi_comm_t comm);
51
52/*******************************************************************************
53 * \brief Wrapper around MPI_Comm_rank.
54 * \author Ole Schuett
55 ******************************************************************************/
56int dbm_mpi_comm_rank(const dbm_mpi_comm_t comm);
57
58/*******************************************************************************
59 * \brief Wrapper around MPI_Comm_size.
60 * \author Ole Schuett
61 ******************************************************************************/
62int dbm_mpi_comm_size(const dbm_mpi_comm_t comm);
63
64/*******************************************************************************
65 * \brief Wrapper around MPI_Dims_create.
66 * \author Ole Schuett
67 ******************************************************************************/
68void dbm_mpi_dims_create(const int nnodes, const int ndims, int dims[]);
69
70/*******************************************************************************
71 * \brief Wrapper around MPI_Cart_create.
72 * \author Ole Schuett
73 ******************************************************************************/
75 const int ndims, const int dims[],
76 const int periods[], const int reorder);
77
78/*******************************************************************************
79 * \brief Wrapper around MPI_Cart_get.
80 * \author Ole Schuett
81 ******************************************************************************/
82void dbm_mpi_cart_get(const dbm_mpi_comm_t comm, int maxdims, int dims[],
83 int periods[], int coords[]);
84
85/*******************************************************************************
86 * \brief Wrapper around MPI_Cart_rank.
87 * \author Ole Schuett
88 ******************************************************************************/
89int dbm_mpi_cart_rank(const dbm_mpi_comm_t comm, const int coords[]);
90
91/*******************************************************************************
92 * \brief Wrapper around MPI_Cart_sub.
93 * \author Ole Schuett
94 ******************************************************************************/
96 const int remain_dims[]);
97
98/*******************************************************************************
99 * \brief Wrapper around MPI_Comm_free.
100 * \author Ole Schuett
101 ******************************************************************************/
103
104/*******************************************************************************
105 * \brief Wrapper around MPI_Comm_compare.
106 * \author Ole Schuett
107 ******************************************************************************/
109 const dbm_mpi_comm_t comm2);
110
111/*******************************************************************************
112 * \brief Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_INT.
113 * \author Ole Schuett
114 ******************************************************************************/
115void dbm_mpi_max_int(int *values, const int count, const dbm_mpi_comm_t comm);
116
117/*******************************************************************************
118 * \brief Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_UINT64_T.
119 * \author Hans Pabst
120 ******************************************************************************/
121void dbm_mpi_max_uint64(uint64_t *values, const int count,
122 const dbm_mpi_comm_t comm);
123
124/*******************************************************************************
125 * \brief Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_DOUBLE.
126 * \author Ole Schuett
127 ******************************************************************************/
128void dbm_mpi_max_double(double *values, const int count,
129 const dbm_mpi_comm_t comm);
130
131/*******************************************************************************
132 * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT.
133 * \author Ole Schuett
134 ******************************************************************************/
135void dbm_mpi_sum_int(int *values, const int count, const dbm_mpi_comm_t comm);
136
137/*******************************************************************************
138 * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT64_T.
139 * \author Ole Schuett
140 ******************************************************************************/
141void dbm_mpi_sum_int64(int64_t *values, const int count,
142 const dbm_mpi_comm_t comm);
143
144/*******************************************************************************
145 * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_DOUBLE.
146 * \author Ole Schuett
147 ******************************************************************************/
148void dbm_mpi_sum_double(double *values, const int count,
149 const dbm_mpi_comm_t comm);
150
151/*******************************************************************************
152 * \brief Wrapper around MPI_Sendrecv for datatype MPI_BYTE.
153 * \author Ole Schuett
154 ******************************************************************************/
155int dbm_mpi_sendrecv_byte(const void *sendbuf, const int sendcount,
156 const int dest, const int sendtag, void *recvbuf,
157 const int recvcount, const int source,
158 const int recvtag, const dbm_mpi_comm_t comm);
159
160/*******************************************************************************
161 * \brief Wrapper around MPI_Sendrecv for datatype MPI_DOUBLE.
162 * \author Ole Schuett
163 ******************************************************************************/
164int dbm_mpi_sendrecv_double(const double *sendbuf, const int sendcount,
165 const int dest, const int sendtag, double *recvbuf,
166 const int recvcount, const int source,
167 const int recvtag, const dbm_mpi_comm_t comm);
168
169/*******************************************************************************
170 * \brief Wrapper around MPI_Alltoall for datatype MPI_INT.
171 * \author Ole Schuett
172 ******************************************************************************/
173void dbm_mpi_alltoall_int(const int *sendbuf, const int sendcount, int *recvbuf,
174 const int recvcount, const dbm_mpi_comm_t comm);
175
176/*******************************************************************************
177 * \brief Wrapper around MPI_Alltoallv for datatype MPI_BYTE.
178 * \author Ole Schuett
179 ******************************************************************************/
180void dbm_mpi_alltoallv_byte(const void *sendbuf, const int *sendcounts,
181 const int *sdispls, void *recvbuf,
182 const int *recvcounts, const int *rdispls,
183 const dbm_mpi_comm_t comm);
184
185/*******************************************************************************
186 * \brief Wrapper around MPI_Alltoallv for datatype MPI_DOUBLE.
187 * \author Ole Schuett
188 ******************************************************************************/
189void dbm_mpi_alltoallv_double(const double *sendbuf, const int *sendcounts,
190 const int *sdispls, double *recvbuf,
191 const int *recvcounts, const int *rdispls,
192 const dbm_mpi_comm_t comm);
193
194/*******************************************************************************
195 * \brief Wrapper around MPI_Alloc_mem.
196 * \author Hans Pabst
197 ******************************************************************************/
198void *dbm_mpi_alloc_mem(size_t size);
199
200/*******************************************************************************
201 * \brief Wrapper around MPI_Free_mem.
202 * \author Hans Pabst
203 ******************************************************************************/
204void dbm_mpi_free_mem(void *ptr);
205
206#endif
207
208// EOF
int dbm_mpi_sendrecv_byte(const void *sendbuf, const int sendcount, const int dest, const int sendtag, void *recvbuf, const int recvcount, const int source, const int recvtag, const dbm_mpi_comm_t comm)
Wrapper around MPI_Sendrecv for datatype MPI_BYTE.
Definition dbm_mpi.c:369
void dbm_mpi_finalize()
Wrapper around MPI_Finalize.
Definition dbm_mpi.c:47
void * dbm_mpi_alloc_mem(size_t size)
Wrapper around MPI_Alloc_mem.
Definition dbm_mpi.c:483
int dbm_mpi_comm_rank(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_rank.
Definition dbm_mpi.c:95
int dbm_mpi_cart_rank(const dbm_mpi_comm_t comm, const int coords[])
Wrapper around MPI_Cart_rank.
Definition dbm_mpi.c:179
bool dbm_mpi_comms_are_similar(const dbm_mpi_comm_t comm1, const dbm_mpi_comm_t comm2)
Wrapper around MPI_Comm_compare.
Definition dbm_mpi.c:224
int dbm_mpi_comm_size(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_size.
Definition dbm_mpi.c:110
void dbm_mpi_alltoallv_byte(const void *sendbuf, const int *sendcounts, const int *sdispls, void *recvbuf, const int *recvcounts, const int *rdispls, const dbm_mpi_comm_t comm)
Wrapper around MPI_Alltoallv for datatype MPI_BYTE.
Definition dbm_mpi.c:445
int dbm_mpi_comm_t
Definition dbm_mpi.h:19
void dbm_mpi_init(int *argc, char ***argv)
Wrapper around MPI_Init.
Definition dbm_mpi.c:34
void dbm_mpi_sum_double(double *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_DOUBLE.
Definition dbm_mpi.c:347
dbm_mpi_comm_t dbm_mpi_cart_create(const dbm_mpi_comm_t comm_old, const int ndims, const int dims[], const int periods[], const int reorder)
Wrapper around MPI_Cart_create.
Definition dbm_mpi.c:140
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.
Definition dbm_mpi.c:325
void dbm_mpi_max_double(double *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_DOUBLE.
Definition dbm_mpi.c:283
void dbm_mpi_alltoall_int(const int *sendbuf, const int sendcount, int *recvbuf, const int recvcount, const dbm_mpi_comm_t comm)
Wrapper around MPI_Alltoall for datatype MPI_INT.
Definition dbm_mpi.c:429
int dbm_mpi_sendrecv_double(const double *sendbuf, const int sendcount, const int dest, const int sendtag, double *recvbuf, const int recvcount, const int source, const int recvtag, const dbm_mpi_comm_t comm)
Wrapper around MPI_Sendrecv for datatype MPI_DOUBLE.
Definition dbm_mpi.c:399
void dbm_mpi_max_int(int *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_INT.
Definition dbm_mpi.c:241
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.
Definition dbm_mpi.c:261
dbm_mpi_comm_t dbm_mpi_cart_sub(const dbm_mpi_comm_t comm, const int remain_dims[])
Wrapper around MPI_Cart_sub.
Definition dbm_mpi.c:195
void dbm_mpi_dims_create(const int nnodes, const int ndims, int dims[])
Wrapper around MPI_Dims_create.
Definition dbm_mpi.c:125
int dbm_mpi_comm_c2f(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_c2f.
Definition dbm_mpi.c:82
void dbm_mpi_comm_free(dbm_mpi_comm_t *comm)
Wrapper around MPI_Comm_free.
Definition dbm_mpi.c:212
void dbm_mpi_alltoallv_double(const double *sendbuf, const int *sendcounts, const int *sdispls, double *recvbuf, const int *recvcounts, const int *rdispls, const dbm_mpi_comm_t comm)
Wrapper around MPI_Alltoallv for datatype MPI_DOUBLE.
Definition dbm_mpi.c:464
void dbm_mpi_free_mem(void *ptr)
Wrapper around MPI_Free_mem.
Definition dbm_mpi.c:499
void dbm_mpi_cart_get(const dbm_mpi_comm_t comm, int maxdims, int dims[], int periods[], int coords[])
Wrapper around MPI_Cart_get.
Definition dbm_mpi.c:161
dbm_mpi_comm_t dbm_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
Definition dbm_mpi.c:69
dbm_mpi_comm_t dbm_mpi_get_comm_world()
Returns MPI_COMM_WORLD.
Definition dbm_mpi.c:57
void dbm_mpi_sum_int(int *values, const int count, const dbm_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT.
Definition dbm_mpi.c:305