Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lockall_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_all+flush";
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
50                     for (dest = 0; dest < size; dest++)
51                         if (dest != source) {
52                             MPI_Accumulate(sendtype.buf, sendtype.count,
53                                            sendtype.datatype, dest, 0,
54                                            recvtype.count, recvtype.datatype, MPI_REPLACE, win);
55                             MPI_Win_flush(dest, win);
56                         }
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 destinations to finish checking and reinitializing the buffers */
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                             MPI_Win_flush(dest, win);
76                         }
77                     /*signal to dest that the ops are flushed so that it starts checking the result */
78                     MPI_Barrier(comm);
79                     /*make sure dest finishes checking the result before issuing unlock */
80                     MPI_Barrier(comm);
81                     MPI_Win_unlock_all(win);
82                     free(resbuf);
83                 }
84                 else {
85                     int err;
86                     MPI_Barrier(comm);
87                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
88                     err = MTestCheckRecv(0, &recvtype);
89                     if (err)
90                         errs++;
91                     recvtype.InitBuf(&recvtype);
92                     MPI_Barrier(comm);
93                     MPI_Win_unlock(rank, win);
94
95                     /*signal the source that checking and reinitialization is done */
96                     MPI_Barrier(comm);
97
98                     MPI_Barrier(comm);
99                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
100                     err = MTestCheckRecv(0, &recvtype);
101                     if (err)
102                         errs++;
103                     MPI_Barrier(comm);
104                     MPI_Win_unlock(rank, win);
105                 }
106
107                 MPI_Win_free(&win);
108                 MTestFreeDatatype(&sendtype);
109                 MTestFreeDatatype(&recvtype);
110             }
111         }
112         MTestFreeComm(&comm);
113     }
114     MTest_Finalize(errs);
115     MPI_Finalize();
116     return 0;
117 }