Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lockall_dt_flushall.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_all+flush_all";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int rank, size;
20     int minsize = 2, count;
21     MPI_Comm comm;
22     MPI_Win win;
23     MPI_Aint lb, extent;
24     MTestDatatype sendtype, recvtype;
25
26     MTest_Init(&argc, &argv);
27
28     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
29         if (comm == MPI_COMM_NULL)
30             continue;
31
32         MPI_Comm_rank(comm, &rank);
33         MPI_Comm_size(comm, &size);
34         int source = 0;
35
36         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
37             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
38                 recvtype.printErrors = 1;
39                 recvtype.InitBuf(&recvtype);
40                 MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
41
42                 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
43                                (int) extent, MPI_INFO_NULL, comm, &win);
44                 if (rank == source) {
45                     int dest;
46                     sendtype.InitBuf(&sendtype);
47
48                     MPI_Win_lock_all(0, win);
49                     for (dest = 0; dest < size; dest++)
50                         if (dest != source) {
51                             MPI_Accumulate(sendtype.buf, sendtype.count,
52                                            sendtype.datatype, dest, 0,
53                                            recvtype.count, recvtype.datatype, MPI_REPLACE, win);
54                         }
55
56                     MPI_Win_flush_all(win);
57                     /*signal to dest that the ops are flushed so that it starts checking the result */
58                     MPI_Barrier(comm);
59                     /*make sure dest finishes checking the result before issuing unlock */
60                     MPI_Barrier(comm);
61                     MPI_Win_unlock_all(win);
62
63                     char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
64
65                     /*wait for the destination to finish checking and reinitializing the buffer */
66                     MPI_Barrier(comm);
67
68                     MPI_Win_lock_all(0, win);
69                     for (dest = 0; dest < size; dest++)
70                         if (dest != source) {
71                             MPI_Get_accumulate(sendtype.buf, sendtype.count,
72                                                sendtype.datatype, resbuf, recvtype.count,
73                                                recvtype.datatype, dest, 0, recvtype.count,
74                                                recvtype.datatype, MPI_REPLACE, win);
75
76                         }
77                     MPI_Win_flush_all(win);
78                     /*signal to dest that the ops are flushed so that it starts checking the result */
79                     MPI_Barrier(comm);
80                     /*make sure dest finishes checking the result before issuing unlock */
81                     MPI_Barrier(comm);
82                     MPI_Win_unlock_all(win);
83                     free(resbuf);
84                 }
85                 else {
86                     int err;
87                     MPI_Barrier(comm);
88                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
89                     err = MTestCheckRecv(0, &recvtype);
90                     if (err)
91                         errs++;
92                     recvtype.InitBuf(&recvtype);
93                     MPI_Barrier(comm);
94                     MPI_Win_unlock(rank, win);
95
96                     /*signal the source that checking and reinitialization is done */
97                     MPI_Barrier(comm);
98
99                     MPI_Barrier(comm);
100                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
101                     err = MTestCheckRecv(0, &recvtype);
102                     if (err)
103                         errs++;
104                     MPI_Barrier(comm);
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 }