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_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+flush_local";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     int err = 0;
21     int rank, size, source, dest;
22     int minsize = 2, count;
23     MPI_Comm comm;
24     MPI_Win win;
25     MPI_Aint lb, extent;
26     MTestDatatype sendtype, recvtype;
27
28     MTest_Init(&argc, &argv);
29
30     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
31         if (comm == MPI_COMM_NULL)
32             continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank(comm, &rank);
35         MPI_Comm_size(comm, &size);
36         source = 0;
37         dest = size - 1;
38
39         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
40             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
41                 recvtype.printErrors = 1;
42                 recvtype.InitBuf(&recvtype);
43                 MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
44
45                 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
46                                (int) extent, MPI_INFO_NULL, comm, &win);
47                 if (rank == source) {
48                     MPI_Aint slb, sextent;
49                     MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
50                     sendtype.InitBuf(&sendtype);
51
52                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
53                     MPI_Accumulate(sendtype.buf, sendtype.count,
54                                    sendtype.datatype, dest, 0,
55                                    recvtype.count, recvtype.datatype, MPI_REPLACE, win);
56                     MPI_Win_flush_local(dest, win);
57                     /* reset the send buffer to test local completion */
58                     memset(sendtype.buf, 0, slb + sextent * sendtype.count);
59                     MPI_Win_unlock(dest, win);
60                     MPI_Barrier(comm);
61
62                     sendtype.InitBuf(&sendtype);
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(MPI_LOCK_SHARED, dest, 0, win);
69                     MPI_Get_accumulate(sendtype.buf, sendtype.count,
70                                        sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
71                                        dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
72                                        win);
73                     MPI_Win_flush_local(dest, win);
74                     /* reset the send buffer to test local completion */
75                     memset(sendtype.buf, 0, slb + sextent * sendtype.count);
76                     MPI_Win_unlock(dest, win);
77                     MPI_Barrier(comm);
78                     free(resbuf);
79                 }
80                 else if (rank == dest) {
81
82                     MPI_Barrier(comm);
83                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
84                     err = MTestCheckRecv(0, &recvtype);
85                     if (err)
86                         errs++;
87                     recvtype.InitBuf(&recvtype);
88                     MPI_Win_unlock(dest, win);
89
90                     /*signal the source that checking and reinitialization is done */
91                     MPI_Barrier(comm);
92
93                     MPI_Barrier(comm);
94                     MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
95                     err = MTestCheckRecv(0, &recvtype);
96                     if (err)
97                         errs++;
98                     MPI_Win_unlock(dest, win);
99                 }
100
101                 MPI_Win_free(&win);
102                 MTestFreeDatatype(&sendtype);
103                 MTestFreeDatatype(&recvtype);
104             }
105         }
106         MTestFreeComm(&comm);
107     }
108     MTest_Finalize(errs);
109     MPI_Finalize();
110     return 0;
111 }