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 / lockall_dt_flushlocalall.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 <string.h>
11 #include "mpitest.h"
12
13 /*
14 static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock_all+flush_local_all";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     int rank, size;
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
33         MPI_Comm_rank(comm, &rank);
34         MPI_Comm_size(comm, &size);
35         int source = 0;
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                     int dest;
47                     MPI_Aint slb, sextent;
48                     MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
49                     sendtype.InitBuf(&sendtype);
50
51                     MPI_Win_lock_all(0, win);
52                     for (dest = 0; dest < size; dest++)
53                         if (dest != source) {
54                             MPI_Accumulate(sendtype.buf, sendtype.count,
55                                            sendtype.datatype, dest, 0,
56                                            recvtype.count, recvtype.datatype, MPI_REPLACE, win);
57                         }
58
59                     MPI_Win_flush_local_all(win);
60                     /* reset the send buffer to test local completion */
61                     memset(sendtype.buf, 0, slb + sextent * sendtype.count);
62                     MPI_Win_unlock_all(win);
63                     MPI_Barrier(comm);
64
65                     sendtype.InitBuf(&sendtype);
66                     char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
67
68                     /*wait for the destination to finish checking and reinitializing the buffer */
69                     MPI_Barrier(comm);
70
71                     MPI_Win_lock_all(0, win);
72                     for (dest = 0; dest < size; dest++)
73                         if (dest != source) {
74                             MPI_Get_accumulate(sendtype.buf, sendtype.count,
75                                                sendtype.datatype, resbuf, recvtype.count,
76                                                recvtype.datatype, dest, 0, recvtype.count,
77                                                recvtype.datatype, MPI_REPLACE, win);
78
79                         }
80                     MPI_Win_flush_local_all(win);
81                     /* reset the send buffer to test local completion */
82                     memset(sendtype.buf, 0, slb + sextent * sendtype.count);
83                     MPI_Win_unlock_all(win);
84                     MPI_Barrier(comm);
85                     free(resbuf);
86                 }
87                 else {
88                     int err;
89                     MPI_Barrier(comm);
90                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
91                     err = MTestCheckRecv(0, &recvtype);
92                     if (err)
93                         errs++;
94                     recvtype.InitBuf(&recvtype);
95                     MPI_Win_unlock(rank, win);
96
97                     /*signal the source that checking and reinitialization is done */
98                     MPI_Barrier(comm);
99
100                     MPI_Barrier(comm);
101                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
102                     err = MTestCheckRecv(0, &recvtype);
103                     if (err)
104                         errs++;
105                     MPI_Win_unlock(rank, win);
106                 }
107
108                 MPI_Win_free(&win);
109                 MTestFreeDatatype(&sendtype);
110                 MTestFreeDatatype(&recvtype);
111             }
112         }
113         MTestFreeComm(&comm);
114     }
115     MTest_Finalize(errs);
116     MPI_Finalize();
117     return 0;
118 }