Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lock_dt_flush.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2015 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int err = 0;
20     int rank, size, source, dest;
21     int minsize = 2, count;
22     MPI_Comm comm;
23     MPI_Win win;
24     MPI_Aint lb, extent;
25     MTestDatatype sendtype, recvtype;
26
27     MTest_Init(&argc, &argv);
28
29     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
30         if (comm == MPI_COMM_NULL)
31             continue;
32         MPI_Comm_rank(comm, &rank);
33         MPI_Comm_size(comm, &size);
34         source = 0;
35         dest = size - 1;
36
37         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
38             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
39                 recvtype.printErrors = 1;
40                 recvtype.InitBuf(&recvtype);
41                 MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
42
43                 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
44                                (int) extent, MPI_INFO_NULL, comm, &win);
45                 if (rank == source) {
46                     sendtype.InitBuf(&sendtype);
47
48                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
49                     MPI_Accumulate(sendtype.buf, sendtype.count,
50                                    sendtype.datatype, dest, 0,
51                                    recvtype.count, recvtype.datatype, MPI_REPLACE, win);
52                     MPI_Win_flush(dest, win);
53                     /*signal to dest that the ops are flushed so that it starts checking the result */
54                     MPI_Barrier(comm);
55                     /*make sure dest finishes checking the result before issuing unlock */
56                     MPI_Barrier(comm);
57                     MPI_Win_unlock(dest, win);
58
59                     char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
60
61                     /*wait for the destination to finish checking  and reinitializing the buffer */
62                     MPI_Barrier(comm);
63
64                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
65                     MPI_Get_accumulate(sendtype.buf, sendtype.count,
66                                        sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
67                                        dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
68                                        win);
69                     MPI_Win_flush(dest, win);
70                     /*signal to dest that the ops are flushed so that it starts checking the result */
71                     MPI_Barrier(comm);
72                     /*make sure dest finishes checking the result before issuing unlock */
73                     MPI_Barrier(comm);
74                     MPI_Win_unlock(dest, win);
75                     free(resbuf);
76                 }
77                 else if (rank == dest) {
78
79                     MPI_Barrier(comm);
80                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
81                     err = MTestCheckRecv(0, &recvtype);
82                     if (err)
83                         errs++;
84                     recvtype.InitBuf(&recvtype);
85                     MPI_Barrier(comm);
86                     MPI_Win_unlock(dest, win);
87
88                     /*signal the source that checking and reinitialization is done */
89                     MPI_Barrier(comm);
90
91                     MPI_Barrier(comm);
92                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
93                     err = MTestCheckRecv(0, &recvtype);
94                     if (err)
95                         errs++;
96                     MPI_Barrier(comm);
97                     MPI_Win_unlock(dest, win);
98                 }
99
100                 MPI_Win_free(&win);
101                 MTestFreeDatatype(&sendtype);
102                 MTestFreeDatatype(&recvtype);
103             }
104         }
105         MTestFreeComm(&comm);
106     }
107     MTest_Finalize(errs);
108     MPI_Finalize();
109     return 0;
110 }