2 #ifndef UTIL_MPI_SEND_RECV_H 3 #define UTIL_MPI_SEND_RECV_H 76 #include <util/mpi/MpiTraits.h> 77 #include <util/containers/DArray.h> 78 #include <util/containers/DMatrix.h> 97 void send(MPI::Comm& comm, T& data,
int dest,
int tag)
100 UTIL_THROW(
"No committed MPI type in send<T>");
115 template <
typename T>
116 void recv(MPI::Comm& comm, T& data,
int source,
int tag)
119 UTIL_THROW(
"No committed MPI type in recv<T>");
133 template <
typename T>
134 void bcast(MPI::Intracomm& comm, T& data,
int root)
137 UTIL_THROW(
"No committed MPI type in bcast<T>");
155 template <
typename T>
156 void send(MPI::Comm& comm, T* array,
int count,
int dest,
int tag)
163 for (
int i = 0; i < count; ++i) {
164 send<T>(comm, array[i], dest, tag);
181 template <
typename T>
182 void recv(MPI::Comm& comm, T* array,
int count,
int source,
int tag)
189 for (
int i = 0; i < count; ++i) {
190 recv<T>(comm, array[i], source, tag);
206 template <
typename T>
207 void bcast(MPI::Intracomm& comm, T* array,
int count,
int root)
214 for (
int i = 0; i < count; ++i) {
215 bcast<T>(comm, array[i], root);
234 template <
typename T>
242 UTIL_THROW(
"Error: Logical size count > DArray capacity");
250 for (
int i = 0; i < count; ++i) {
251 send<T>(comm, array[i], dest, tag);
268 template <
typename T>
269 void recv(MPI::Comm& comm,
DArray<T>& array,
int count,
int source,
int tag)
276 UTIL_THROW(
"Error: Logical size count > DArray capacity");
284 for (
int i = 0; i < count; ++i) {
285 recv<T>(comm, array[i], source, tag);
301 template <
typename T>
309 UTIL_THROW(
"Error: Logical size count > DArray capacity");
317 for (
int i = 0; i < count; ++i) {
318 bcast<T>(comm, array[i], root);
338 template <
typename T>
343 UTIL_THROW(
"Cannot read unallocated DMatrix");
346 UTIL_THROW(
"Error: Logical size m > DMatrix<T>::capacity1()");
349 UTIL_THROW(
"Error: Logical size n > DMatrix<T>::capacity2()");
361 for (i = 0; i < m; ++i) {
362 for (j = 0; j < n; ++j) {
363 send<T>(comm, matrix(i, j), dest, tag);
382 template <
typename T>
388 UTIL_THROW(
"Cannot recv unallocated DMatrix");
391 UTIL_THROW(
"Error: Logical size m > DMatrix<T>::capacity1()");
394 UTIL_THROW(
"Error: Logical size n > DMatrix<T>::capacity2()");
406 for (i = 0; i < m; ++i) {
407 for (j = 0; j < n; ++j) {
408 recv<T>(comm, matrix(i, j), source, tag);
426 template <
typename T>
431 UTIL_THROW(
"Cannot bcast unallocated DMatrix");
434 UTIL_THROW(
"Error: Logical size m > DMatrix<T>::capacity1()");
437 UTIL_THROW(
"Error: Logical size n > DMatrix<T>::capacity2()");
449 for (i = 0; i < m; ++i) {
450 for (j = 0; j < n; ++j) {
451 bcast<T>(comm, matrix(i, j), root);
463 void send<bool>(MPI::Comm& comm,
bool& data,
int dest,
int tag);
469 void recv<bool>(MPI::Comm& comm,
bool& data,
int source,
int tag);
475 void bcast<bool>(MPI::Intracomm& comm,
bool& data,
int root);
483 send<std::string>(MPI::Comm& comm, std::string& data,
int dest,
int tag);
489 recv<std::string>(MPI::Comm& comm, std::string& data,
int source,
int tag);
495 void bcast<std::string>(MPI::Intracomm& comm, std::string& data,
int root);
void send< bool >(MPI::Comm &comm, bool &data, int dest, int tag)
Explicit specialization of send for bool data.
void recv(MPI::Comm &comm, T &data, int source, int tag)
Receive a single T value.
File containing preprocessor macros for error handling.
void send(MPI::Comm &comm, T &data, int dest, int tag)
Send a single T value.
void bcast< bool >(MPI::Intracomm &comm, bool &data, int root)
Explicit specialization of bcast for bool data.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
int capacity2() const
Get number of columns (range of the second array index).
void bcast(MPI::Intracomm &comm, T &data, int root)
Broadcast a single T value.
Dynamically allocated Matrix.
Utility classes for scientific computation.
bool isAllocated() const
Return true if the DArray has been allocated, false otherwise.
int capacity1() const
Get number of rows (range of the first array index).
Dynamically allocatable contiguous array template.
int capacity() const
Return allocated size.
bool isAllocated() const
Return true if the DMatrix has been allocated, false otherwise.
void recv< bool >(MPI::Comm &comm, bool &data, int source, int tag)
Explicit specialization of recv for bool data.