24#ifndef BIG_MPI_COMPAT_H
25#define BIG_MPI_COMPAT_H
29#ifdef DEAL_II_WITH_MPI
34# error "Your MPI implementation does not define MPI_VERSION!"
38# error "BigMPICompat requires at least MPI 3.0"
59 std::numeric_limits<int>::max();
69 MPI_Datatype *newtype)
72 return MPI_Type_contiguous_c(count, oldtype, newtype);
75 return MPI_Type_contiguous(count, oldtype, newtype);
82 ierr = MPI_Type_size_x(oldtype, &size_old);
84 MPI_Count n_chunks = count / max_signed_int;
85 MPI_Count n_remaining_elements = count % max_signed_int;
88 ierr = MPI_Type_vector(
89 n_chunks, max_signed_int, max_signed_int, oldtype, &chunks);
90 if (ierr != MPI_SUCCESS)
93 MPI_Datatype remainder;
95 MPI_Type_contiguous(n_remaining_elements, oldtype, &remainder);
96 if (ierr != MPI_SUCCESS)
99 int blocklengths[2] = {1, 1};
100 MPI_Aint displacements[2] = {0,
101 static_cast<MPI_Aint
>(n_chunks) *
102 size_old * max_signed_int};
103 MPI_Datatype
types[2] = {chunks, remainder};
104 ierr = MPI_Type_create_struct(
105 2, blocklengths, displacements,
types, newtype);
106 if (ierr != MPI_SUCCESS)
109 ierr = MPI_Type_commit(newtype);
110 if (ierr != MPI_SUCCESS)
113 ierr = MPI_Type_free(&chunks);
114 if (ierr != MPI_SUCCESS)
117 ierr = MPI_Type_free(&remainder);
118 if (ierr != MPI_SUCCESS)
121# ifndef MPI_COMPAT_SKIP_SIZE_CHECK
123 ierr = MPI_Type_size_x(*newtype, &size_new);
124 if (ierr != MPI_SUCCESS)
127 if (size_old * count != size_new)
138 return MPI_ERR_INTERN;
156 MPI_Datatype datatype,
162 return MPI_Send_c(buf, count, datatype, dest, tag,
comm);
165 return MPI_Send(buf, count, datatype, dest, tag,
comm);
167 MPI_Datatype bigtype;
170 if (ierr != MPI_SUCCESS)
172 ierr = MPI_Type_commit(&bigtype);
173 if (ierr != MPI_SUCCESS)
176 ierr = MPI_Send(buf, 1, bigtype, dest, tag,
comm);
177 if (ierr != MPI_SUCCESS)
180 ierr = MPI_Type_free(&bigtype);
181 if (ierr != MPI_SUCCESS)
195 MPI_Datatype datatype,
202 return MPI_Recv_c(buf, count, datatype, source, tag,
comm, status);
205 return MPI_Recv(buf, count, datatype, source, tag,
comm, status);
207 MPI_Datatype bigtype;
210 if (ierr != MPI_SUCCESS)
213 ierr = MPI_Type_commit(&bigtype);
214 if (ierr != MPI_SUCCESS)
217 ierr = MPI_Recv(buf, 1, bigtype, source, tag,
comm, status);
218 if (ierr != MPI_SUCCESS)
221 ierr = MPI_Type_free(&bigtype);
222 if (ierr != MPI_SUCCESS)
237 MPI_Datatype datatype,
238 unsigned int root_mpi_rank,
242 return MPI_Bcast_c(buf, count, datatype, root_mpi_rank,
comm);
245 return MPI_Bcast(buf, count, datatype, root_mpi_rank,
comm);
247 MPI_Datatype bigtype;
250 if (ierr != MPI_SUCCESS)
252 ierr = MPI_Type_commit(&bigtype);
253 if (ierr != MPI_SUCCESS)
256 ierr = MPI_Bcast(buf, 1, bigtype, root_mpi_rank,
comm);
257 if (ierr != MPI_SUCCESS)
260 ierr = MPI_Type_free(&bigtype);
261 if (ierr != MPI_SUCCESS)
277 MPI_Datatype datatype,
281 return MPI_File_write_at(fh, offset, buf, count, datatype, status);
283 MPI_Datatype bigtype;
286 if (ierr != MPI_SUCCESS)
288 ierr = MPI_Type_commit(&bigtype);
289 if (ierr != MPI_SUCCESS)
292 ierr = MPI_File_write_at(fh, offset, buf, 1, bigtype, status);
293 if (ierr != MPI_SUCCESS)
296 ierr = MPI_Type_free(&bigtype);
297 if (ierr != MPI_SUCCESS)
313 MPI_Datatype datatype,
317 return MPI_File_write_at_all(
318 fh, offset, buf, count, datatype, status);
320 MPI_Datatype bigtype;
323 if (ierr != MPI_SUCCESS)
325 ierr = MPI_Type_commit(&bigtype);
326 if (ierr != MPI_SUCCESS)
329 ierr = MPI_File_write_at_all(fh, offset, buf, 1, bigtype, status);
330 if (ierr != MPI_SUCCESS)
333 ierr = MPI_Type_free(&bigtype);
334 if (ierr != MPI_SUCCESS)
348 MPI_Datatype datatype,
352 return MPI_File_write_ordered(fh, buf, count, datatype, status);
354 MPI_Datatype bigtype;
357 if (ierr != MPI_SUCCESS)
359 ierr = MPI_Type_commit(&bigtype);
360 if (ierr != MPI_SUCCESS)
363 ierr = MPI_File_write_ordered(fh, buf, 1, bigtype, status);
364 if (ierr != MPI_SUCCESS)
367 ierr = MPI_Type_free(&bigtype);
368 if (ierr != MPI_SUCCESS)
384 MPI_Datatype datatype,
388 return MPI_File_read_at(fh, offset, buf, count, datatype, status);
390 MPI_Datatype bigtype;
393 if (ierr != MPI_SUCCESS)
395 ierr = MPI_Type_commit(&bigtype);
396 if (ierr != MPI_SUCCESS)
399 ierr = MPI_File_read_at(fh, offset, buf, 1, bigtype, status);
400 if (ierr != MPI_SUCCESS)
403 ierr = MPI_Type_free(&bigtype);
404 if (ierr != MPI_SUCCESS)
420 MPI_Datatype datatype,
424 return MPI_File_read_at_all(fh, offset, buf, count, datatype, status);
426 MPI_Datatype bigtype;
429 if (ierr != MPI_SUCCESS)
431 ierr = MPI_Type_commit(&bigtype);
432 if (ierr != MPI_SUCCESS)
435 ierr = MPI_File_read_at_all(fh, offset, buf, 1, bigtype, status);
436 if (ierr != MPI_SUCCESS)
439 ierr = MPI_Type_free(&bigtype);
440 if (ierr != MPI_SUCCESS)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
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