9 #define QMP_CHECK(qmp_call) do { \ 10 QMP_status_t status = qmp_call; \ 11 if (status != QMP_SUCCESS) \ 12 errorQuda("(QMP) %s", QMP_error_string(status)); \ 15 #define MPI_CHECK(mpi_call) \ 17 int status = mpi_call; \ 18 if (status != MPI_SUCCESS) { \ 19 char err_string[128]; \ 21 MPI_Error_string(status, err_string, &err_len); \ 22 err_string[127] = '\0'; \ 23 errorQuda("(MPI) %s", err_string); \ 35 #define USE_MPI_GATHER 56 for (
int j=0; j<128; j++) {
57 data[j] = (i ==
comm_rank()) ? hostname[j] : 0;
59 hostname_recv_buf[i*128 + j] = data[j];
81 gpuid_recv_buf[i] = data;
89 if ( QMP_is_initialized() != QMP_TRUE ) {
90 errorQuda(
"QMP has not been initialized");
94 for (
int i = 0; i <
ndim; i++) {
97 if (grid_size != QMP_get_number_of_nodes()) {
98 errorQuda(
"Communication grid size declared via initCommsGridQuda() does not match" 99 " total number of QMP nodes (%d != %d)", grid_size, QMP_get_number_of_nodes());
107 return QMP_get_node_number();
113 return QMP_get_number_of_nodes();
127 mh->
mem = QMP_declare_msgmem(buffer, nbytes);
128 if (mh->
mem == NULL)
errorQuda(
"Unable to allocate QMP message memory");
130 mh->
handle = QMP_declare_send_to(mh->
mem, rank, 0);
131 if (mh->
handle == NULL)
errorQuda(
"Unable to allocate QMP message handle");
146 mh->
mem = QMP_declare_msgmem(buffer, nbytes);
147 if (mh->
mem == NULL)
errorQuda(
"Unable to allocate QMP message memory");
149 mh->
handle = QMP_declare_receive_from(mh->
mem, rank, 0);
150 if (mh->
handle == NULL)
errorQuda(
"Unable to allocate QMP message handle");
161 size_t blksize,
int nblocks,
size_t stride)
168 mh->
mem = QMP_declare_strided_msgmem(buffer, blksize, nblocks, stride);
169 if (mh->
mem == NULL)
errorQuda(
"Unable to allocate QMP message memory");
171 mh->
handle = QMP_declare_send_to(mh->
mem, rank, 0);
172 if (mh->
handle == NULL)
errorQuda(
"Unable to allocate QMP message handle");
182 size_t blksize,
int nblocks,
size_t stride)
189 mh->
mem = QMP_declare_strided_msgmem(buffer, blksize, nblocks, stride);
190 if (mh->
mem == NULL)
errorQuda(
"Unable to allocate QMP message memory");
192 mh->
handle = QMP_declare_receive_from(mh->
mem, rank, 0);
193 if (mh->
handle == NULL)
errorQuda(
"Unable to allocate QMP message handle");
200 QMP_free_msghandle(mh->
handle);
201 QMP_free_msgmem(mh->
mem);
221 return (QMP_is_complete(mh->
handle) == QMP_TRUE);
226 std::sort(array, array + n);
227 return std::accumulate(array, array + n, 0.0);
237 double *recv_buf = (
double *)
safe_malloc(n *
sizeof(
double));
259 QMP_CHECK(QMP_sum_double_array(data, size));
263 double *recv_buf =
new double[size * n];
266 double *recv_trans =
new double[size * n];
267 for (
size_t i = 0; i < n; i++) {
268 for (
size_t j = 0; j <
size; j++) { recv_trans[j * n + i] = recv_buf[i * size + j]; }
280 for (
size_t i = 0; i <
size; i++) {
QMP_CHECK(QMP_max_double(data + i)); }
290 if (
sizeof(uint64_t) !=
sizeof(
unsigned long))
errorQuda(
"unsigned long is not 64-bit");
291 QMP_CHECK( QMP_xor_ulong( reinterpret_cast<unsigned long*>(data) ));
296 QMP_CHECK( QMP_broadcast(data, nbytes) );
void comm_gather_gpuid(int *gpuid_recv_buf)
Gather all GPU ids.
int comm_query(MsgHandle *mh)
_EXTERN_C_ int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
void comm_free(MsgHandle *&mh)
void comm_allreduce_xor(uint64_t *data)
Topology * comm_default_topology(void)
void comm_wait(MsgHandle *mh)
void comm_start(MsgHandle *mh)
void comm_allreduce_max_array(double *data, size_t size)
MsgHandle * comm_declare_strided_send_displaced(void *buffer, const int displacement[], size_t blksize, int nblocks, size_t stride)
char * comm_hostname(void)
MsgHandle * comm_declare_strided_receive_displaced(void *buffer, const int displacement[], size_t blksize, int nblocks, size_t stride)
void comm_allreduce(double *data)
void comm_abort(int status)
#define MPI_CHECK(mpi_call)
#define QMP_CHECK(qmp_call)
int comm_rank_displaced(const Topology *topo, const int displacement[])
int(* QudaCommsMap)(const int *coords, void *fdata)
void comm_init_common(int ndim, const int *dims, QudaCommsMap rank_from_coords, void *map_data)
Initialize the communications common to all communications abstractions.
void comm_init(int ndim, const int *dims, QudaCommsMap rank_from_coords, void *map_data)
Initialize the communications, implemented in comm_single.cpp, comm_qmp.cpp, and comm_mpi.cpp.
#define safe_malloc(size)
bool comm_deterministic_reduce()
void comm_allreduce_max(double *data)
T deterministic_reduce(T *array, int n)
void comm_allreduce_int(int *data)
MsgHandle * comm_declare_receive_displaced(void *buffer, const int displacement[], size_t nbytes)
void comm_allreduce_array(double *data, size_t size)
void comm_broadcast(void *data, size_t nbytes)
void comm_gather_hostname(char *hostname_recv_buf)
Gather all hostnames.
void comm_allreduce_min(double *data)
MsgHandle * comm_declare_send_displaced(void *buffer, const int displacement[], size_t nbytes)