Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This particular RMA test is filled with stupid calls... We send errors for most of...
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lockall_dt_flushlocal.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";
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
53                     for (dest = 0; dest < size; dest++)
54                         if (dest != source) {
55                             MPI_Accumulate(sendtype.buf, sendtype.count,
56                                            sendtype.datatype, dest, 0,
57                                            recvtype.count, recvtype.datatype, MPI_REPLACE, win);
58                             MPI_Win_flush_local(dest, win);
59                         }
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 destinations to finish checking and reinitializing the buffers */
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                             MPI_Win_flush_local(dest, win);
79                         }
80                     /* reset the send buffer to test local completion */
81                     memset(sendtype.buf, 0, slb + sextent * sendtype.count);
82                     MPI_Win_unlock_all(win);
83                     MPI_Barrier(comm);
84                     free(resbuf);
85                 }
86                 else {
87                     int err;
88                     MPI_Barrier(comm);
89                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
90                     err = MTestCheckRecv(0, &recvtype);
91                     if (err)
92                         errs++;
93                     recvtype.InitBuf(&recvtype);
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_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 }