Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lock_contention_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 lock contention while streaming ACC-like operations";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0;
19     int rank, size;
20     int target = 1;
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
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 != target) {
45                     sendtype.InitBuf(&sendtype);
46
47                     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
48                     MPI_Accumulate(sendtype.buf, sendtype.count,
49                                    sendtype.datatype, target, 0,
50                                    recvtype.count, recvtype.datatype, MPI_REPLACE, win);
51                     MPI_Win_unlock(target, win);
52                     MPI_Barrier(comm);
53
54                     char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
55
56                     /*wait for the destination to finish checking and reinitializing the buffer */
57                     MPI_Barrier(comm);
58
59                     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, target, 0, win);
60                     MPI_Get_accumulate(sendtype.buf, sendtype.count,
61                                        sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
62                                        target, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
63                                        win);
64                     MPI_Win_unlock(target, win);
65                     MPI_Barrier(comm);
66                     free(resbuf);
67                 }
68                 else {  /* Target checks the result */
69                     int err;
70                     MPI_Barrier(comm);
71                     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
72                     err = MTestCheckRecv(0, &recvtype);
73                     if (err)
74                         errs++;
75                     recvtype.InitBuf(&recvtype);
76                     MPI_Win_unlock(rank, win);
77
78                     /*signal the source that checking and reinitialization is done */
79                     MPI_Barrier(comm);
80
81                     MPI_Barrier(comm);
82                     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
83                     err = MTestCheckRecv(0, &recvtype);
84                     if (err)
85                         errs++;
86                     MPI_Win_unlock(rank, win);
87                 }
88
89                 MPI_Win_free(&win);
90                 MTestFreeDatatype(&sendtype);
91                 MTestFreeDatatype(&recvtype);
92             }
93         }
94         MTestFreeComm(&comm);
95     }
96     MTest_Finalize(errs);
97     MPI_Finalize();
98     return 0;
99 }