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.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";
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                     MPI_Win_unlock_all(win);
56                     MPI_Barrier(comm);
57
58                     char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
59
60                     /*wait for the destinations to finish checking and reinitializing the buffers */
61                     MPI_Barrier(comm);
62
63                     MPI_Win_lock_all(0, win);
64                     for (dest = 0; dest < size; dest++)
65                         if (dest != source) {
66                             MPI_Get_accumulate(sendtype.buf, sendtype.count,
67                                                sendtype.datatype, resbuf, recvtype.count,
68                                                recvtype.datatype, dest, 0, recvtype.count,
69                                                recvtype.datatype, MPI_REPLACE, win);
70
71                         }
72                     MPI_Win_unlock_all(win);
73                     MPI_Barrier(comm);
74                     free(resbuf);
75                 }
76                 else {
77                     int err;
78                     MPI_Barrier(comm);
79                     MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
80                     err = MTestCheckRecv(0, &recvtype);
81                     if (err)
82                         errs++;
83                     recvtype.InitBuf(&recvtype);
84                     MPI_Win_unlock(rank, win);
85
86                     /*signal the source that checking and reinitialization is done */
87                     MPI_Barrier(comm);
88
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                     MPI_Win_unlock(rank, win);
95                 }
96
97                 MPI_Win_free(&win);
98                 MTestFreeDatatype(&sendtype);
99                 MTestFreeDatatype(&recvtype);
100             }
101         }
102         MTestFreeComm(&comm);
103     }
104     MTest_Finalize(errs);
105     MPI_Finalize();
106     return 0;
107 }