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.
14 static char MTEST_Descrip[] = "RMA to self";
17 int main( int argc, char *argv[] )
24 int *sbuf, scount, vcount;
27 MTest_Init( &argc, &argv );
29 comm = MPI_COMM_WORLD;
31 MPI_Comm_rank( comm, &rank );
32 MPI_Comm_size( comm, &size );
34 /* Allocate and initialize sbuf */
37 sbuf = (int *)malloc( scount * sizeof(int) );
39 fprintf( stderr, "Could not allocate send buffer f size %d\n",
41 MPI_Abort( MPI_COMM_WORLD, 0 );
43 for (i=0; i<scount; i++) sbuf[i] = i;
45 MPI_Alloc_mem( count*sizeof(int), MPI_INFO_NULL, &winbuf );
47 /* This is a simple vector type */
49 MPI_Type_vector( vcount, 1, 2, MPI_INT, &vectype );
50 MPI_Type_commit( &vectype );
51 MPI_Win_create( winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL,
54 /* Check with different combination of types, including non-contig on
58 memset( winbuf, 0, count*sizeof(int) );
59 MPI_Win_lock( MPI_LOCK_EXCLUSIVE, rank, 0, win );
60 MPI_Put( sbuf, 1, vectype, rank, 0, 1, vectype, win );
61 MPI_Win_unlock( rank, win );
64 for (i=0; i<vcount; i++) {
65 if (winbuf[j] != sbuf[j]) {
67 fprintf( stderr, "VecPut: winbuf[%d] = %d, should = %d\n",
68 winbuf[j], j, sbuf[j] );
73 memset( winbuf, 0, count*sizeof(int) );
74 MPI_Win_lock( MPI_LOCK_SHARED, rank, 0, win );
75 MPI_Accumulate( sbuf, 1, vectype, rank, 0, 1, vectype, MPI_SUM, win );
76 MPI_Win_unlock( rank, win );
79 for (i=0; i<vcount; i++) {
80 if (winbuf[j] != sbuf[j]) {
82 fprintf( stderr, "VecAcc: winbuf[%d] = %d, should = %d\n",
83 winbuf[j], j, sbuf[j] );
88 /* Now, use get to fetch back the results that we just wrote */
89 memset( sbuf, 0, count*sizeof(int) );
90 MPI_Win_lock( MPI_LOCK_SHARED, rank, 0, win );
91 MPI_Get( sbuf, 1, vectype, rank, 0, 1, vectype, win );
92 MPI_Win_unlock( rank, win );
95 for (i=0; i<vcount; i++) {
96 if (winbuf[j] != sbuf[j]) {
98 fprintf( stderr, "VecAcc: winbuf[%d] = %d, should = %d\n",
99 winbuf[j], j, sbuf[j] );
104 MPI_Win_free( &win );
105 MPI_Free_mem( winbuf );
107 MPI_Type_free( &vectype );
109 MTest_Finalize( errs );