Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[TESTS] SMPI/MPICH3: Fix failing rma test
[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     /* 
37      * TODO cheinrich: These assignments were originally after the MPI_Win_lock
38      * and before the MPI_Win_unlock call. However, with compile time optimizations on,
39      * this seems to cause issues with at least gcc. If valgrind or gcc is activated,
40      * everything works fine though.
41      *
42      * I don't know what causes these issues, but moving this here solves the problem for now.
43      */
44     baseptr[0] = 1;
45     baseptr[1] = 2;
46
47     /* Initialize window buffer */
48     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
49     MPI_Win_unlock(rank, win);
50
51     /* Issue request-based get with testall. */
52     MPI_Win_lock_all(0, win);
53     MPI_Rget(&val1, 1, MPI_INT, 0, 0, 1, MPI_INT, win, &reqs[0]);
54     MPI_Rget(&val2, 1, MPI_INT, 0, 1, 1, MPI_INT, win, &reqs[1]);
55
56     do {
57         mpi_errno = MPI_Testall(2, reqs, &flag, stats);
58     } while (flag == 0);
59
60     /* Check get value. */
61     if (val1 != 1 || val2 != 2) {
62         printf("%d - Got val1 = %d, val2 = %d, expected 1, 2\n", rank, val1, val2);
63         fflush(stdout);
64         errs++;
65     }
66
67     /* Check return error code. */
68     if (mpi_errno != MPI_SUCCESS) {
69         printf("%d - Got return errno %d, expected MPI_SUCCESS(%d)\n",
70                rank, mpi_errno, MPI_SUCCESS);
71         fflush(stdout);
72         errs++;
73     }
74
75     MPI_Win_unlock_all(win);
76     MPI_Barrier(MPI_COMM_WORLD);
77
78     MPI_Win_free(&win);
79
80     MTest_Finalize(errs);
81     MPI_Finalize();
82
83     return errs != 0;
84 }