Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / rget-testall.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2017 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <mpi.h>
10 #include "mpitest.h"
11
12 /* This test checks request-based get with MPI_Testall. Both the return value of
13  * MPI_Testall and status.MPI_ERROR should be correctly set.
14  *
15  * Thanks for Joseph Schuchart reporting this bug in MPICH and contributing
16  * the prototype of this test program. */
17
18 int main(int argc, char **argv)
19 {
20     int rank, size;
21     MPI_Win win = MPI_WIN_NULL;
22     int *baseptr = NULL;
23     int errs = 0, mpi_errno = MPI_SUCCESS;
24     int val1 = 0, val2 = 0, flag = 0;
25     MPI_Request reqs[2];
26     MPI_Status stats[2];
27
28     MTest_Init(&argc, &argv);
29     MPI_Comm_size(MPI_COMM_WORLD, &size);
30     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31
32     MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
33
34     MPI_Win_allocate(2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &baseptr, &win);
35
36     /* Initialize window buffer */
37     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
38     baseptr[0] = 1;
39     baseptr[1] = 2;
40     MPI_Win_unlock(rank, win);
41
42     /* Issue request-based get with testall. */
43     MPI_Win_lock_all(0, win);
44     MPI_Rget(&val1, 1, MPI_INT, 0, 0, 1, MPI_INT, win, &reqs[0]);
45     MPI_Rget(&val2, 1, MPI_INT, 0, 1, 1, MPI_INT, win, &reqs[1]);
46
47     do {
48         mpi_errno = MPI_Testall(2, reqs, &flag, stats);
49     } while (flag == 0);
50
51     /* Check get value. */
52     if (val1 != 1 || val2 != 2) {
53         printf("%d - Got val1 = %d, val2 = %d, expected 1, 2\n", rank, val1, val2);
54         fflush(stdout);
55         errs++;
56     }
57
58     /* Check return error code. */
59     if (mpi_errno != MPI_SUCCESS) {
60         printf("%d - Got return errno %d, expected MPI_SUCCESS(%d)\n",
61                rank, mpi_errno, MPI_SUCCESS);
62         fflush(stdout);
63         errs++;
64     }
65
66     MPI_Win_unlock_all(win);
67     MPI_Barrier(MPI_COMM_WORLD);
68
69     MPI_Win_free(&win);
70
71     MTest_Finalize(errs);
72     MPI_Finalize();
73
74     return errs != 0;
75 }