24 int n_neighbor_pe_send,
int *neighbor_pe_send,
int *sendbuf_index,
25 void *sendbuf,
int n_neighbor_pe_recv,
int *neighbor_pe_recv,
32 if (n_neighbor_pe_send > 0) {
35 if (request_send ==
NULL) {
41 if (status_send ==
NULL) {
46 if (n_neighbor_pe_recv > 0) {
49 if (request_recv ==
NULL) {
55 if (status_recv ==
NULL) {
62 int *_sendbuf = (
int *)sendbuf;
63 int *_recvbuf = (
int *)recvbuf;
66 for (i = 0; i < n_neighbor_pe_send; i++) {
68 sendbuf_index[i + 1] - sendbuf_index[i],
HECMW_INT,
69 neighbor_pe_send[i], 0, comm, &request_send[i]);
70 if (rtc != 0)
goto error;
74 for (i = 0; i < n_neighbor_pe_recv; i++) {
76 recvbuf_index[i + 1] - recvbuf_index[i],
HECMW_INT,
77 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
78 if (rtc != 0)
goto error;
81 double *_sendbuf = (
double *)sendbuf;
82 double *_recvbuf = (
double *)recvbuf;
85 for (i = 0; i < n_neighbor_pe_send; i++) {
88 neighbor_pe_send[i], 0, comm, &request_send[i]);
89 if (rtc != 0)
goto error;
93 for (i = 0; i < n_neighbor_pe_recv; i++) {
96 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
97 if (rtc != 0)
goto error;
100 char *_sendbuf = (
char *)sendbuf;
101 char *_recvbuf = (
char *)recvbuf;
104 for (i = 0; i < n_neighbor_pe_send; i++) {
106 sendbuf_index[i + 1] - sendbuf_index[i],
HECMW_CHAR,
107 neighbor_pe_send[i], 0, comm, &request_send[i]);
108 if (rtc != 0)
goto error;
112 for (i = 0; i < n_neighbor_pe_recv; i++) {
114 recvbuf_index[i + 1] - recvbuf_index[i],
HECMW_CHAR,
115 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
116 if (rtc != 0)
goto error;
119 long long *_sendbuf = (
long long *)sendbuf;
120 long long *_recvbuf = (
long long *)recvbuf;
123 for (i = 0; i < n_neighbor_pe_send; i++) {
126 neighbor_pe_send[i], 0, comm, &request_send[i]);
127 if (rtc != 0)
goto error;
131 for (i = 0; i < n_neighbor_pe_recv; i++) {
134 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
135 if (rtc != 0)
goto error;
143 if (n_neighbor_pe_recv > 0) {
144 rtc =
HECMW_Waitall(n_neighbor_pe_recv, request_recv, status_recv);
145 if (rtc != 0)
goto error;
148 if (n_neighbor_pe_send > 0) {
149 rtc =
HECMW_Waitall(n_neighbor_pe_send, request_send, status_send);
150 if (rtc != 0)
goto error;
170 int *sendbuf_index,
void *sendbuf,
171 int *recvbuf_index,
void *recvbuf,
178 if (n_neighbor_pe > 0) {
181 if (request_send ==
NULL) {
187 if (status_send ==
NULL) {
193 if (request_recv ==
NULL) {
199 if (status_recv ==
NULL) {
206 int *_sendbuf = (
int *)sendbuf;
207 int *_recvbuf = (
int *)recvbuf;
210 for (i = 0; i < n_neighbor_pe; i++) {
212 sendbuf_index[i + 1] - sendbuf_index[i], datatype,
213 neighbor_pe[i], 0, comm, &request_send[i]);
214 if (rtc != 0)
goto error;
218 for (i = 0; i < n_neighbor_pe; i++) {
220 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
221 neighbor_pe[i], 0, comm, &request_recv[i]);
222 if (rtc != 0)
goto error;
225 double *_sendbuf = (
double *)sendbuf;
226 double *_recvbuf = (
double *)recvbuf;
229 for (i = 0; i < n_neighbor_pe; i++) {
231 sendbuf_index[i + 1] - sendbuf_index[i], datatype,
232 neighbor_pe[i], 0, comm, &request_send[i]);
233 if (rtc != 0)
goto error;
237 for (i = 0; i < n_neighbor_pe; i++) {
239 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
240 neighbor_pe[i], 0, comm, &request_recv[i]);
241 if (rtc != 0)
goto error;
244 char *_sendbuf = (
char *)sendbuf;
245 char *_recvbuf = (
char *)recvbuf;
248 for (i = 0; i < n_neighbor_pe; i++) {
250 sendbuf_index[i + 1] - sendbuf_index[i], datatype,
251 neighbor_pe[i], 0, comm, &request_send[i]);
252 if (rtc != 0)
goto error;
256 for (i = 0; i < n_neighbor_pe; i++) {
258 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
259 neighbor_pe[i], 0, comm, &request_recv[i]);
260 if (rtc != 0)
goto error;
263 long long *_sendbuf = (
long long *)sendbuf;
264 long long *_recvbuf = (
long long *)recvbuf;
267 for (i = 0; i < n_neighbor_pe; i++) {
269 sendbuf_index[i + 1] - sendbuf_index[i], datatype,
270 neighbor_pe[i], 0, comm, &request_send[i]);
271 if (rtc != 0)
goto error;
275 for (i = 0; i < n_neighbor_pe; i++) {
277 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
278 neighbor_pe[i], 0, comm, &request_recv[i]);
279 if (rtc != 0)
goto error;
287 if (n_neighbor_pe > 0) {
288 rtc =
HECMW_Waitall(n_neighbor_pe, request_recv, status_recv);
289 if (rtc != 0)
goto error;
292 if (n_neighbor_pe > 0) {
293 rtc =
HECMW_Waitall(n_neighbor_pe, request_send, status_send);
294 if (rtc != 0)
goto error;
314 int sendbuf_size,
void *sendbuf,
315 int n_neighbor_pe_recv,
int *neighbor_pe_recv,
316 int *recvbuf_index,
void *recvbuf,
322 if (n_neighbor_pe_send > 0) {
325 if (request_send ==
NULL) {
331 if (status_send ==
NULL) {
336 if (n_neighbor_pe_recv > 0) {
339 if (request_recv ==
NULL) {
345 if (status_recv ==
NULL) {
352 int *_sendbuf = (
int *)sendbuf;
353 int *_recvbuf = (
int *)recvbuf;
356 for (i = 0; i < n_neighbor_pe_send; i++) {
357 rtc =
HECMW_Isend(&_sendbuf[0], sendbuf_size, datatype,
358 neighbor_pe_send[i], 0, comm, &request_send[i]);
359 if (rtc != 0)
goto error;
363 for (i = 0; i < n_neighbor_pe_recv; i++) {
365 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
366 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
367 if (rtc != 0)
goto error;
370 double *_sendbuf = (
double *)sendbuf;
371 double *_recvbuf = (
double *)recvbuf;
374 for (i = 0; i < n_neighbor_pe_send; i++) {
375 rtc =
HECMW_Isend(&_sendbuf[0], sendbuf_size, datatype,
376 neighbor_pe_send[i], 0, comm, &request_send[i]);
377 if (rtc != 0)
goto error;
381 for (i = 0; i < n_neighbor_pe_recv; i++) {
383 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
384 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
385 if (rtc != 0)
goto error;
388 char *_sendbuf = (
char *)sendbuf;
389 char *_recvbuf = (
char *)recvbuf;
392 for (i = 0; i < n_neighbor_pe_send; i++) {
393 rtc =
HECMW_Isend(&_sendbuf[0], sendbuf_size, datatype,
394 neighbor_pe_send[i], 0, comm, &request_send[i]);
395 if (rtc != 0)
goto error;
399 for (i = 0; i < n_neighbor_pe_recv; i++) {
401 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
402 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
403 if (rtc != 0)
goto error;
406 long long *_sendbuf = (
long long *)sendbuf;
407 long long *_recvbuf = (
long long *)recvbuf;
410 for (i = 0; i < n_neighbor_pe_send; i++) {
411 rtc =
HECMW_Isend(&_sendbuf[0], sendbuf_size, datatype,
412 neighbor_pe_send[i], 0, comm, &request_send[i]);
413 if (rtc != 0)
goto error;
417 for (i = 0; i < n_neighbor_pe_recv; i++) {
419 recvbuf_index[i + 1] - recvbuf_index[i], datatype,
420 neighbor_pe_recv[i], 0, comm, &request_recv[i]);
421 if (rtc != 0)
goto error;
429 if (n_neighbor_pe_recv > 0) {
430 rtc =
HECMW_Waitall(n_neighbor_pe_recv, request_recv, status_recv);
431 if (rtc != 0)
goto error;
433 if (n_neighbor_pe_send > 0) {
434 rtc =
HECMW_Waitall(n_neighbor_pe_send, request_send, status_send);
435 if (rtc != 0)
goto error;
459 int n_pe_send = 0, n_pe_recv = 0, *pe_send =
NULL, *pe_recv =
NULL;
460 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL, *recvbuf =
NULL;
467 if(pe_send ==
NULL) {
471 pe_send[0] = comm_dst->
root;
473 sendbuf_index = (
int *)
HECMW_calloc(n_pe_send+1,
sizeof(
int));
474 if(sendbuf_index ==
NULL) {
478 sendbuf_index[1] = count;
480 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int)*sendbuf_index[1]);
481 if(sendbuf ==
NULL) {
485 for(i=0; i<sendbuf_index[1]; i++) {
486 sendbuf[i] = buffer[i];
494 if(pe_recv ==
NULL) {
498 pe_recv[0] = comm_src->
root;
500 recvbuf_index = (
int *)
HECMW_calloc(n_pe_recv+1,
sizeof(
int));
501 if(recvbuf_index ==
NULL) {
505 recvbuf_index[1] = count;
507 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int)*recvbuf_index[1]);
508 if(recvbuf ==
NULL) {
519 memcpy(buffer, recvbuf, size);
544 void **recvbuf,
int recvcount,
HECMW_Datatype datatype,
int direction)
561 if(comm_src ==
NULL || comm_dst ==
NULL)
goto error;
564 int n_src = 0, n_dst = 0, *src =
NULL, *dst =
NULL;
565 int *_sendbuf = (
int *)sendbuf;
566 int *sendindex =
NULL, *recvindex =
NULL;
567 int _recvcount, *_recvbuf =
NULL;
577 dst[0] = comm_dst->root;
580 if(sendindex ==
NULL) {
587 _sendbuf = (
int *)
HECMW_malloc(
sizeof(
int)*sendindex[n_dst]);
588 if(_sendbuf ==
NULL) {
592 _sendbuf[0] = sendcount;
595 if(comm_dst->is_root) {
603 src[0] = comm_src->
root;
606 if(recvindex ==
NULL) {
613 _recvbuf = (
int *)
HECMW_malloc(
sizeof(
int)*recvindex[n_src]);
614 if(_recvbuf ==
NULL) {
621 n_src, src, recvindex, _recvbuf,
HECMW_INT, intercomm->comm);
624 if(comm_dst->is_root) {
625 recvcount = _recvbuf[0];
646 dst[0] = comm_dst->root;
649 if(sendindex ==
NULL) {
653 sendindex[1] = sendcount;
655 _sendbuf = (
int *)
HECMW_malloc(
sizeof(
int)*sendindex[n_dst]+1);
656 if(_sendbuf ==
NULL) {
660 for(i=0; i<sendindex[n_dst]; i++) {
661 _sendbuf[i] = sendbuf[i];
665 if(comm_dst->is_root) {
673 src[0] = comm_src->
root;
676 if(recvindex ==
NULL) {
680 recvindex[1] = recvcount;
682 _recvbuf = (
int *)
HECMW_malloc(
sizeof(
int)*recvindex[n_src]);
683 if(_recvbuf ==
NULL) {
690 n_src, src, recvindex, _recvbuf,
HECMW_INT, intercomm->comm);
693 if(comm_dst->is_member) {
697 if(recvbuf ==
NULL) {
702 if(comm_dst->is_root) {
703 for(i=0; i<recvcount; i++) {
704 recvbuf[i] = _recvbuf[i];
int HECMW_Irecv(void *buffer, int count, HECMW_Datatype datatype, int source, int tag, HECMW_Comm comm, HECMW_Request *request)
int HECMW_Isend(void *buffer, int count, HECMW_Datatype datatype, int dest, int tag, HECMW_Comm comm, HECMW_Request *request)
int HECMW_Waitall(int count, HECMW_Request *array_of_requests, HECMW_Status *array_of_statuses)
HECMW_Comm HECMW_comm_get_comm(void)
int HECMW_Barrier(HECMW_Comm comm)
int HECMW_Bcast(void *buffer, int count, HECMW_Datatype datatype, int root, HECMW_Comm comm)
MPI_Datatype HECMW_Datatype
MPI_Request HECMW_Request
int HECMW_couple_bcast(int n_neighbor_pe_send, int *neighbor_pe_send, int sendbuf_size, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
int HECMW_couple_intra_send_recv(int n_neighbor_pe, int *neighbor_pe, int *sendbuf_index, void *sendbuf, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
int HECMW_couple_inter_send_recv(int n_neighbor_pe_send, int *neighbor_pe_send, int *sendbuf_index, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
int HECMW_couple_inter_barrier(const char *boundary_id)
int HECMW_couple_inter_bcast(const char *boundary_id, void *buffer, int count, HECMW_Datatype datatype, int direction)
#define HECMWCPL_E_MPI_DATATYPE
#define HECMW_COUPLE_UNIT1
#define HECMW_COUPLE_UNIT2_TO_UNIT1
#define HECMW_COUPLE_UNIT1_TO_UNIT2
#define HECMW_COUPLE_UNIT2
#define HECMWCPL_E_INVALID_DIRECTION
void HECMW_couple_free_comm(struct hecmw_couple_comm *comm)
struct hecmw_couple_comm * HECMW_couple_get_intracomm(const char *boundary_id, int unit_specifier)
struct hecmw_couple_comm * HECMW_couple_get_intercomm(const char *boundary_id)
int HECMW_set_error(int errorno, const char *fmt,...)
#define HECMW_calloc(nmemb, size)
#define HECMW_malloc(size)