Reference documentation for deal.II version GIT relicensing-660-g9ae06c0eb4 2024-05-17 13:10:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
mpi_large_count.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2022 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15//
16// The content of this file is a slightly modified version of the
17// header-only library BigMPICompat - a tiny MPI 4.x compatibility
18// library released under MIT license at
19// https://github.com/tjhei/BigMPICompat and relicensed and included
20// here with permission.
21//
22
23#ifndef BIG_MPI_COMPAT_H
24#define BIG_MPI_COMPAT_H
25
26#include <deal.II/base/config.h>
27
28#ifdef DEAL_II_WITH_MPI
29# include <mpi.h>
30// required for std::numeric_limits used below.
31# include <limits>
32# ifndef MPI_VERSION
33# error "Your MPI implementation does not define MPI_VERSION!"
34# endif
35
36# if MPI_VERSION < 3
37# error "BigMPICompat requires at least MPI 3.0"
38# endif
39
41
42namespace Utilities
43{
44 namespace MPI
45 {
51 namespace LargeCount
52 {
57 static constexpr MPI_Count mpi_max_int_count =
58 std::numeric_limits<int>::max();
59
65 inline int
69 {
70# if MPI_VERSION >= 4
72# else
75 else
76 {
77 int ierr;
79
82
83 MPI_Count n_chunks = count / max_signed_int;
85
89 if (ierr != MPI_SUCCESS)
90 return ierr;
91
93 ierr =
95 if (ierr != MPI_SUCCESS)
96 return ierr;
97
98 int blocklengths[2] = {1, 1};
99 MPI_Aint displacements[2] = {0,
100 static_cast<MPI_Aint>(n_chunks) *
105 if (ierr != MPI_SUCCESS)
106 return ierr;
107
109 if (ierr != MPI_SUCCESS)
110 return ierr;
111
113 if (ierr != MPI_SUCCESS)
114 return ierr;
115
117 if (ierr != MPI_SUCCESS)
118 return ierr;
119
120# ifndef MPI_COMPAT_SKIP_SIZE_CHECK
123 if (ierr != MPI_SUCCESS)
124 return ierr;
125
126 if (size_old * count != size_new)
127 {
128 // This error can happen when you are using a very old and
129 // buggy MPI implementation. There is nothing we can do
130 // here, unfortunately. Please update your installation.
131 // std::cerr
132 //<< "MPI_Type_contiguous_c() produced an invalid result.
133 // Expected =
134 //"
135 //<< size_old << " * " << count << " = " << size_old * count
136 //<< " but received " << size_new << std::endl;
137 return MPI_ERR_INTERN;
138 }
139# endif
140
141 return MPI_SUCCESS;
142 }
143# endif
144 }
145
146
152 inline int
153 Send_c(const void *buf,
156 int dest,
157 int tag,
159 {
160# if MPI_VERSION >= 4
161 return MPI_Send_c(buf, count, datatype, dest, tag, comm);
162# else
164 return MPI_Send(buf, count, datatype, dest, tag, comm);
165
167 int ierr;
169 if (ierr != MPI_SUCCESS)
170 return ierr;
172 if (ierr != MPI_SUCCESS)
173 return ierr;
174
175 ierr = MPI_Send(buf, 1, bigtype, dest, tag, comm);
176 if (ierr != MPI_SUCCESS)
177 return ierr;
178
180 if (ierr != MPI_SUCCESS)
181 return ierr;
182 return MPI_SUCCESS;
183# endif
184 }
185
191 inline int
192 Recv_c(void *buf,
195 int source,
196 int tag,
198 MPI_Status *status)
199 {
200# if MPI_VERSION >= 4
201 return MPI_Recv_c(buf, count, datatype, source, tag, comm, status);
202# else
204 return MPI_Recv(buf, count, datatype, source, tag, comm, status);
205
207 int ierr;
209 if (ierr != MPI_SUCCESS)
210 return ierr;
211
213 if (ierr != MPI_SUCCESS)
214 return ierr;
215
216 ierr = MPI_Recv(buf, 1, bigtype, source, tag, comm, status);
217 if (ierr != MPI_SUCCESS)
218 return ierr;
219
221 if (ierr != MPI_SUCCESS)
222 return ierr;
223 return MPI_SUCCESS;
224# endif
225 }
226
233 inline int
237 unsigned int root_mpi_rank,
239 {
240# if MPI_VERSION >= 4
242# else
245
247 int ierr;
249 if (ierr != MPI_SUCCESS)
250 return ierr;
252 if (ierr != MPI_SUCCESS)
253 return ierr;
254
256 if (ierr != MPI_SUCCESS)
257 return ierr;
258
260 if (ierr != MPI_SUCCESS)
261 return ierr;
262 return MPI_SUCCESS;
263# endif
264 }
265
271 inline int
273 MPI_Offset offset,
274 const void *buf,
277 MPI_Status *status)
278 {
280 return MPI_File_write_at(fh, offset, buf, count, datatype, status);
281
283 int ierr;
285 if (ierr != MPI_SUCCESS)
286 return ierr;
288 if (ierr != MPI_SUCCESS)
289 return ierr;
290
291 ierr = MPI_File_write_at(fh, offset, buf, 1, bigtype, status);
292 if (ierr != MPI_SUCCESS)
293 return ierr;
294
296 if (ierr != MPI_SUCCESS)
297 return ierr;
298 return MPI_SUCCESS;
299 }
300
307 inline int
309 MPI_Offset offset,
310 const void *buf,
313 MPI_Status *status)
314 {
317 fh, offset, buf, count, datatype, status);
318
320 int ierr;
322 if (ierr != MPI_SUCCESS)
323 return ierr;
325 if (ierr != MPI_SUCCESS)
326 return ierr;
327
328 ierr = MPI_File_write_at_all(fh, offset, buf, 1, bigtype, status);
329 if (ierr != MPI_SUCCESS)
330 return ierr;
331
333 if (ierr != MPI_SUCCESS)
334 return ierr;
335 return MPI_SUCCESS;
336 }
337
343 inline int
345 const void *buf,
348 MPI_Status *status)
349 {
351 return MPI_File_write_ordered(fh, buf, count, datatype, status);
352
354 int ierr;
356 if (ierr != MPI_SUCCESS)
357 return ierr;
359 if (ierr != MPI_SUCCESS)
360 return ierr;
361
362 ierr = MPI_File_write_ordered(fh, buf, 1, bigtype, status);
363 if (ierr != MPI_SUCCESS)
364 return ierr;
365
367 if (ierr != MPI_SUCCESS)
368 return ierr;
369 return MPI_SUCCESS;
370 }
371
378 inline int
380 MPI_Offset offset,
381 void *buf,
384 MPI_Status *status)
385 {
387 return MPI_File_read_at(fh, offset, buf, count, datatype, status);
388
390 int ierr;
392 if (ierr != MPI_SUCCESS)
393 return ierr;
395 if (ierr != MPI_SUCCESS)
396 return ierr;
397
398 ierr = MPI_File_read_at(fh, offset, buf, 1, bigtype, status);
399 if (ierr != MPI_SUCCESS)
400 return ierr;
401
403 if (ierr != MPI_SUCCESS)
404 return ierr;
405 return MPI_SUCCESS;
406 }
407
414 inline int
416 MPI_Offset offset,
417 void *buf,
420 MPI_Status *status)
421 {
423 return MPI_File_read_at_all(fh, offset, buf, count, datatype, status);
424
426 int ierr;
428 if (ierr != MPI_SUCCESS)
429 return ierr;
431 if (ierr != MPI_SUCCESS)
432 return ierr;
433
434 ierr = MPI_File_read_at_all(fh, offset, buf, 1, bigtype, status);
435 if (ierr != MPI_SUCCESS)
436 return ierr;
437
439 if (ierr != MPI_SUCCESS)
440 return ierr;
441 return MPI_SUCCESS;
442 }
443
444 } // namespace LargeCount
445 } // namespace MPI
446} // namespace Utilities
447
449
450#endif
451#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
int File_write_at_c(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int File_write_ordered_c(MPI_File fh, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int File_write_at_all_c(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int Recv_c(void *buf, MPI_Count count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
int File_read_at_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int Type_contiguous_c(MPI_Count count, MPI_Datatype oldtype, MPI_Datatype *newtype)
int Bcast_c(void *buf, MPI_Count count, MPI_Datatype datatype, unsigned int root_mpi_rank, MPI_Comm comm)
int Send_c(const void *buf, MPI_Count count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
int File_read_at_all_c(MPI_File fh, MPI_Offset offset, void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
static constexpr MPI_Count mpi_max_int_count
Definition types.h:32
*braid_SplitCommworld & comm