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.
14 static char MTEST_Descrip[] = "Test for streaming ACC-like operations with lock+flush_local";
17 int main(int argc, char *argv[])
21 int rank, size, source, dest;
22 int minsize = 2, count;
26 MTestDatatype sendtype, recvtype;
28 MTest_Init(&argc, &argv);
30 while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
31 if (comm == MPI_COMM_NULL)
33 /* Determine the sender and receiver */
34 MPI_Comm_rank(comm, &rank);
35 MPI_Comm_size(comm, &size);
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);
45 MPI_Win_create(recvtype.buf, lb + recvtype.count * extent,
46 (int) extent, MPI_INFO_NULL, comm, &win);
48 MPI_Aint slb, sextent;
49 MPI_Type_get_extent(sendtype.datatype, &slb, &sextent);
50 sendtype.InitBuf(&sendtype);
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);
62 sendtype.InitBuf(&sendtype);
63 char *resbuf = (char *) calloc(lb + extent * recvtype.count, sizeof(char));
65 /*wait for the destination to finish checking and reinitializing the buffer */
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,
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);
80 else if (rank == dest) {
83 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
84 err = MTestCheckRecv(0, &recvtype);
87 recvtype.InitBuf(&recvtype);
88 MPI_Win_unlock(dest, win);
90 /*signal the source that checking and reinitialization is done */
94 MPI_Win_lock(MPI_LOCK_SHARED, dest, 0, win);
95 err = MTestCheckRecv(0, &recvtype);
98 MPI_Win_unlock(dest, win);
102 MTestFreeDatatype(&sendtype);
103 MTestFreeDatatype(&recvtype);
106 MTestFreeComm(&comm);
108 MTest_Finalize(errs);