1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2015 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
13 static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock";
16 int main(int argc, char *argv[])
19 int rank, size, source, dest;
20 int minsize = 2, count;
24 MTestDatatype sendtype, recvtype;
26 MTest_Init(&argc, &argv);
28 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
29 if (comm == MPI_COMM_NULL)
32 MPI_Comm_rank(comm, &rank);
33 MPI_Comm_size(comm, &size);
37 MTEST_DATATYPE_FOR_EACH_COUNT(count) {
38 while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
39 recvtype.printErrors = 1;
40 /* Make sure that everyone has a recv buffer */
41 recvtype.InitBuf(&recvtype);
42 MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
44 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
45 (int) extent, MPI_INFO_NULL, comm, &win);
47 sendtype.InitBuf(&sendtype);
49 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
50 MPI_Accumulate(sendtype.buf, sendtype.count,
51 sendtype.datatype, dest, 0,
52 recvtype.count, recvtype.datatype, MPI_REPLACE, win);
53 MPI_Win_unlock(dest, win);
56 char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
58 /*wait for the destination to finish checking and reinitializing the buffer */
61 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
62 MPI_Get_accumulate(sendtype.buf, sendtype.count,
63 sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
64 dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
66 MPI_Win_unlock(dest, win);
70 else if (rank == dest) {
73 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
74 err = MTestCheckRecv(0, &recvtype);
77 recvtype.InitBuf(&recvtype);
78 MPI_Win_unlock(dest, win);
80 /*signal the source that checking and reinitialization is done */
84 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
85 err = MTestCheckRecv(0, &recvtype);
88 MPI_Win_unlock(dest, win);
92 MTestFreeDatatype(&sendtype);
93 MTestFreeDatatype(&recvtype);