Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add tests for isendrecv and isendrecv_replace
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / isendrecv_replace.c
1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5
6 #include "mpi.h"
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /* Similar test as isendirecv.c, but use MPI_Isendrecv_replace */
12
13 int errs = 0;
14 int elems = 20;
15 int rank, nproc, dest;
16 float *buf;
17 MPI_Comm comm;
18 MPI_Request *reqs;
19
20 static void test_sendrecv(int offset)
21 {
22     for (int i = 0; i < nproc; i++) {
23         for (int j = 0; j < elems; j++) {
24             buf[i * elems + j] = rank * 100.0 + j;
25         }
26     }
27
28     for (int i = 0; i < nproc; i++) {
29         int j = (i + offset) % nproc;
30         MPI_Isendrecv_replace(&buf[elems * j], elems, MPI_FLOAT, i, 0, j, 0, comm, &reqs[i]);
31     }
32
33     MPI_Waitall(nproc, reqs, MPI_STATUSES_IGNORE);
34
35     for (int i = 0; i < nproc; i++) {
36         for (int j = 0; j < elems; j++) {
37             if (buf[i * elems + j] != i * 100.0 + j) {
38                 if (errs < 10) {
39                     fprintf(stderr, "buf(%d, %d) mismatch, got %f, expect %f\n", i, j,
40                             buf[i * elems + j], (float) (i * 100.0 + j));
41                 }
42                 errs++;
43             }
44         }
45     }
46 }
47
48 /* sendrecv may use the same or different source and destination,
49  * offset defines the offset between them */
50
51 int main(int argc, char *argv[])
52 {
53     MTest_Init(&argc, &argv);
54
55     comm = MPI_COMM_WORLD;
56     MPI_Comm_rank(comm, &rank);
57     MPI_Comm_size(comm, &nproc);
58
59     reqs = malloc(nproc * sizeof(MPI_Request));
60     buf = malloc(elems * nproc * sizeof(float));
61
62     for (int offset = 0; offset < nproc - 1; offset++) {
63         test_sendrecv(offset);
64     }
65
66     free(reqs);
67     free(buf);
68     MTest_Finalize(errs);
69     return MTestReturnValue(errs);
70 }