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,
78 MPI_INFO_NULL, comm, &win );
79 MPI_Win_fence( 0, win );
81 /* To improve reporting of problems about operations, we
82 change the error handler to errors return */
83 MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
85 err = MPI_Put( srcBuf, 1, originType, dest, 0,
86 totsize, MPI_INT, win );
87 errs += CheckMPIErr( err );
88 err = MPI_Win_fence( 0, win );
89 errs += CheckMPIErr( err );
91 else if (rank == dest) {
92 MPI_Win_fence( 0, win );
93 for (i=0; i<totsize; i++) {
94 if (recvBuf[i] != i) {
97 printf( "recvBuf[%d] = %d should = %d\n",
104 MPI_Win_fence( 0, win );
107 MPI_Type_free( &originType );
108 MPI_Win_free( &win );
112 MTest_Finalize( errs );
117 int CheckMPIErr( int err )
120 if (err != MPI_SUCCESS) {
121 MTestPrintError( err );