(git:1f285aa)
dbm_mpi.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* CP2K: A general program to perform molecular dynamics simulations */
3 /* Copyright 2000-2024 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 <stdint.h>
13 
14 #if defined(__parallel)
15 #include <mpi.h>
16 typedef MPI_Comm dbm_mpi_comm_t;
17 #else
18 typedef int dbm_mpi_comm_t;
19 #endif
20 
21 /*******************************************************************************
22  * \brief Wrapper around MPI_Init.
23  * \author Ole Schuett
24  ******************************************************************************/
25 void dbm_mpi_init(int *argc, char ***argv);
26 
27 /*******************************************************************************
28  * \brief Wrapper around MPI_Finalize.
29  * \author Ole Schuett
30  ******************************************************************************/
31 void dbm_mpi_finalize();
32 
33 /*******************************************************************************
34  * \brief Returns MPI_COMM_WORLD.
35  * \author Ole Schuett
36  ******************************************************************************/
38 
39 /*******************************************************************************
40  * \brief Wrapper around MPI_Comm_f2c.
41  * \author Ole Schuett
42  ******************************************************************************/
43 dbm_mpi_comm_t dbm_mpi_comm_f2c(const int fortran_comm);
44 
45 /*******************************************************************************
46  * \brief Wrapper around MPI_Comm_c2f.
47  * \author Ole Schuett
48  ******************************************************************************/
49 int dbm_mpi_comm_c2f(const dbm_mpi_comm_t comm);
50 
51 /*******************************************************************************
52  * \brief Wrapper around MPI_Comm_rank.
53  * \author Ole Schuett
54  ******************************************************************************/
55 int dbm_mpi_comm_rank(const dbm_mpi_comm_t comm);
56 
57 /*******************************************************************************
58  * \brief Wrapper around MPI_Comm_size.
59  * \author Ole Schuett
60  ******************************************************************************/
61 int dbm_mpi_comm_size(const dbm_mpi_comm_t comm);
62 
63 /*******************************************************************************
64  * \brief Wrapper around MPI_Dims_create.
65  * \author Ole Schuett
66  ******************************************************************************/
67 void dbm_mpi_dims_create(const int nnodes, const int ndims, int dims[]);
68 
69 /*******************************************************************************
70  * \brief Wrapper around MPI_Cart_create.
71  * \author Ole Schuett
72  ******************************************************************************/
74  const int ndims, const int dims[],
75  const int periods[], const int reorder);
76 
77 /*******************************************************************************
78  * \brief Wrapper around MPI_Cart_get.
79  * \author Ole Schuett
80  ******************************************************************************/
81 void dbm_mpi_cart_get(const dbm_mpi_comm_t comm, int maxdims, int dims[],
82  int periods[], int coords[]);
83 
84 /*******************************************************************************
85  * \brief Wrapper around MPI_Cart_rank.
86  * \author Ole Schuett
87  ******************************************************************************/
88 int dbm_mpi_cart_rank(const dbm_mpi_comm_t comm, const int coords[]);
89 
90 /*******************************************************************************
91  * \brief Wrapper around MPI_Cart_sub.
92  * \author Ole Schuett
93  ******************************************************************************/
95  const int remain_dims[]);
96 
97 /*******************************************************************************
98  * \brief Wrapper around MPI_Comm_free.
99  * \author Ole Schuett
100  ******************************************************************************/
102 
103 /*******************************************************************************
104  * \brief Wrapper around MPI_Comm_compare.
105  * \author Ole Schuett
106  ******************************************************************************/
108  const dbm_mpi_comm_t comm2);
109 
110 /*******************************************************************************
111  * \brief Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_INT.
112  * \author Ole Schuett
113  ******************************************************************************/
114 void dbm_mpi_max_int(int *values, const int count, const dbm_mpi_comm_t comm);
115 
116 /*******************************************************************************
117  * \brief Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_DOUBLE.
118  * \author Ole Schuett
119  ******************************************************************************/
120 void dbm_mpi_max_double(double *values, const int count,
121  const dbm_mpi_comm_t comm);
122 
123 /*******************************************************************************
124  * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT.
125  * \author Ole Schuett
126  ******************************************************************************/
127 void dbm_mpi_sum_int(int *values, const int count, const dbm_mpi_comm_t comm);
128 
129 /*******************************************************************************
130  * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT64_T.
131  * \author Ole Schuett
132  ******************************************************************************/
133 void dbm_mpi_sum_int64(int64_t *values, const int count,
134  const dbm_mpi_comm_t comm);
135 
136 /*******************************************************************************
137  * \brief Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_DOUBLE.
138  * \author Ole Schuett
139  ******************************************************************************/
140 void dbm_mpi_sum_double(double *values, const int count,
141  const dbm_mpi_comm_t comm);
142 
143 /*******************************************************************************
144  * \brief Wrapper around MPI_Sendrecv for datatype MPI_BYTE.
145  * \author Ole Schuett
146  ******************************************************************************/
147 int dbm_mpi_sendrecv_byte(const void *sendbuf, const int sendcount,
148  const int dest, const int sendtag, void *recvbuf,
149  const int recvcount, const int source,
150  const int recvtag, const dbm_mpi_comm_t comm);
151 
152 /*******************************************************************************
153  * \brief Wrapper around MPI_Sendrecv for datatype MPI_DOUBLE.
154  * \author Ole Schuett
155  ******************************************************************************/
156 int dbm_mpi_sendrecv_double(const double *sendbuf, const int sendcount,
157  const int dest, const int sendtag, double *recvbuf,
158  const int recvcount, const int source,
159  const int recvtag, const dbm_mpi_comm_t comm);
160 
161 /*******************************************************************************
162  * \brief Wrapper around MPI_Alltoall for datatype MPI_INT.
163  * \author Ole Schuett
164  ******************************************************************************/
165 void dbm_mpi_alltoall_int(const int *sendbuf, const int sendcount, int *recvbuf,
166  const int recvcount, const dbm_mpi_comm_t comm);
167 
168 /*******************************************************************************
169  * \brief Wrapper around MPI_Alltoallv for datatype MPI_BYTE.
170  * \author Ole Schuett
171  ******************************************************************************/
172 void dbm_mpi_alltoallv_byte(const void *sendbuf, const int *sendcounts,
173  const int *sdispls, void *recvbuf,
174  const int *recvcounts, const int *rdispls,
175  const dbm_mpi_comm_t comm);
176 
177 /*******************************************************************************
178  * \brief Wrapper around MPI_Alltoallv for datatype MPI_DOUBLE.
179  * \author Ole Schuett
180  ******************************************************************************/
181 void dbm_mpi_alltoallv_double(const double *sendbuf, const int *sendcounts,
182  const int *sdispls, double *recvbuf,
183  const int *recvcounts, const int *rdispls,
184  const dbm_mpi_comm_t comm);
185 
186 #endif
187 
188 // 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:326
void dbm_mpi_finalize()
Wrapper around MPI_Finalize.
Definition: dbm_mpi.c:44
int dbm_mpi_comm_rank(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_rank.
Definition: dbm_mpi.c:92
int dbm_mpi_cart_rank(const dbm_mpi_comm_t comm, const int coords[])
Wrapper around MPI_Cart_rank.
Definition: dbm_mpi.c:176
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:221
int dbm_mpi_comm_size(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_size.
Definition: dbm_mpi.c:107
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:402
int dbm_mpi_comm_t
Definition: dbm_mpi.h:18
void dbm_mpi_init(int *argc, char ***argv)
Wrapper around MPI_Init.
Definition: dbm_mpi.c:31
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:308
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:137
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:290
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:255
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:386
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:356
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:238
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:192
void dbm_mpi_dims_create(const int nnodes, const int ndims, int dims[])
Wrapper around MPI_Dims_create.
Definition: dbm_mpi.c:122
int dbm_mpi_comm_c2f(const dbm_mpi_comm_t comm)
Wrapper around MPI_Comm_c2f.
Definition: dbm_mpi.c:79
void dbm_mpi_comm_free(dbm_mpi_comm_t *comm)
Wrapper around MPI_Comm_free.
Definition: dbm_mpi.c:209
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:421
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:158
dbm_mpi_comm_t dbm_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
Definition: dbm_mpi.c:66
dbm_mpi_comm_t dbm_mpi_get_comm_world()
Returns MPI_COMM_WORLD.
Definition: dbm_mpi.c:54
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:273