2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
11 /* Similar test as isendirecv.c, but use MPI_Isendrecv */
15 int rank, nproc, dest;
17 float *in_buf, *out_buf;
20 /* sendrecv may use the same or different source and destination,
21 * offset defines the offset between them */
22 static void test_sendrecv(int offset)
24 for (int i = 0; i < nproc; i++) {
25 for (int j = 0; j < elems; j++) {
26 in_buf[i * elems + j] = -1.0;
27 out_buf[i * elems + j] = rank * 10000.0 + i * 100.0 + j;
31 for (int i = 0; i < nproc; i++) {
32 int j = (i + offset) % nproc;
33 MPI_Isendrecv(&out_buf[elems * i], elems, MPI_FLOAT, i, 0,
34 &in_buf[elems * j], elems, MPI_FLOAT, j, 0, comm, &reqs[i]);
37 MPI_Waitall(nproc, reqs, MPI_STATUSES_IGNORE);
39 for (int i = 0; i < nproc; i++) {
40 for (int j = 0; j < elems; j++) {
41 if (in_buf[i * elems + j] != i * 10000.0 + rank * 100.0 + j) {
48 int main(int argc, char *argv[])
50 MTest_Init(&argc, &argv);
52 comm = MPI_COMM_WORLD;
53 MPI_Comm_rank(comm, &rank);
54 MPI_Comm_size(comm, &nproc);
56 reqs = malloc(nproc * sizeof(MPI_Request));
57 in_buf = malloc(elems * nproc * sizeof(float));
58 out_buf = malloc(elems * nproc * sizeof(float));
60 for (int offset = 0; offset < nproc - 1; offset++) {
61 test_sendrecv(offset);
68 return MTestReturnValue(errs);