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+flush";
16 int main(int argc, char *argv[])
20 int rank, size, source, dest;
21 int minsize = 2, count;
25 MTestDatatype sendtype, recvtype;
27 MTest_Init(&argc, &argv);
29 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
30 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 recvtype.InitBuf(&recvtype);
41 MPI_Type_get_extent(recvtype.datatype, &lb, &extent);
43 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
44 (int) extent, MPI_INFO_NULL, comm, &win);
46 sendtype.InitBuf(&sendtype);
48 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
49 MPI_Accumulate(sendtype.buf, sendtype.count,
50 sendtype.datatype, dest, 0,
51 recvtype.count, recvtype.datatype, MPI_REPLACE, win);
52 MPI_Win_flush(dest, win);
53 /*signal to dest that the ops are flushed so that it starts checking the result */
55 /*make sure dest finishes checking the result before issuing unlock */
57 MPI_Win_unlock(dest, win);
59 char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
61 /*wait for the destination to finish checking and reinitializing the buffer */
64 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
65 MPI_Get_accumulate(sendtype.buf, sendtype.count,
66 sendtype.datatype, resbuf, recvtype.count, recvtype.datatype,
67 dest, 0, recvtype.count, recvtype.datatype, MPI_REPLACE,
69 MPI_Win_flush(dest, win);
70 /*signal to dest that the ops are flushed so that it starts checking the result */
72 /*make sure dest finishes checking the result before issuing unlock */
74 MPI_Win_unlock(dest, win);
77 else if (rank == dest) {
80 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
81 err = MTestCheckRecv(0, &recvtype);
84 recvtype.InitBuf(&recvtype);
86 MPI_Win_unlock(dest, win);
88 /*signal the source that checking and reinitialization is done */
92 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
93 err = MTestCheckRecv(0, &recvtype);
97 MPI_Win_unlock(dest, win);
101 MTestFreeDatatype(&sendtype);
102 MTestFreeDatatype(&recvtype);
105 MTestFreeComm(&comm);
107 MTest_Finalize(errs);