1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
15 static char MTEST_Descrip[] = "Put with Fence for an indexed datatype";
18 int CheckMPIErr(int err);
20 int main(int argc, char *argv[])
23 int i, rank, size, source, dest;
25 int *recvBuf = 0, *srcBuf = 0;
29 MPI_Datatype originType;
33 MTest_Init(&argc, &argv);
35 /* Select the communicator and datatypes */
36 comm = MPI_COMM_WORLD;
38 /* Create the datatype */
39 /* One MPI Implementation fails this test with sufficiently large
40 * values of blksize - it appears to convert this type to an
41 * incorrect contiguous move */
46 displs[1] = blksize + 1;
47 MPI_Type_indexed(2, counts, displs, MPI_INT, &originType);
48 MPI_Type_commit(&originType);
50 totsize = 2 * blksize;
52 /* Determine the sender and receiver */
53 MPI_Comm_rank(comm, &rank);
54 MPI_Comm_size(comm, &size);
58 recvBuf = (int *) malloc(totsize * sizeof(int));
59 srcBuf = (int *) malloc((totsize + 1) * sizeof(int));
61 if (!recvBuf || !srcBuf) {
62 fprintf(stderr, "Could not allocate buffers\n");
63 MPI_Abort(MPI_COMM_WORLD, 1);
66 /* Initialize the send and recv buffers */
67 for (i = 0; i < totsize; i++) {
70 for (i = 0; i < blksize; i++) {
72 srcBuf[blksize + 1 + i] = blksize + i;
76 MPI_Type_extent(MPI_INT, &extent);
77 MPI_Win_create(recvBuf, totsize * extent, extent, MPI_INFO_NULL, comm, &win);
78 MPI_Win_fence(0, win);
80 /* To improve reporting of problems about operations, we
81 * change the error handler to errors return */
82 MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
84 err = MPI_Put(srcBuf, 1, originType, dest, 0, totsize, MPI_INT, win);
85 errs += CheckMPIErr(err);
86 err = MPI_Win_fence(0, win);
87 errs += CheckMPIErr(err);
89 else if (rank == dest) {
90 MPI_Win_fence(0, win);
91 for (i = 0; i < totsize; i++) {
92 if (recvBuf[i] != i) {
95 printf("recvBuf[%d] = %d should = %d\n", i, recvBuf[i], i);
101 MPI_Win_fence(0, win);
104 MPI_Type_free(&originType);
109 MTest_Finalize(errs);
114 int CheckMPIErr(int err)
117 if (err != MPI_SUCCESS) {
118 MTestPrintError(err);