1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2012 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 /* tests passive target RMA on 2 processes. tests the lock-single_op-unlock
12 optimization for less common cases:
14 origin datatype derived, target datatype predefined
17 int main(int argc, char *argv[])
19 int wrank, nprocs, *srcbuf, *rmabuf, i;
25 MTest_Init(&argc,&argv);
26 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
27 MPI_Comm_rank(MPI_COMM_WORLD,&wrank);
30 printf("Run this program with 2 or more processes\n");
31 MPI_Abort(MPI_COMM_WORLD, 1);
34 memsize = 10 * 4 * nprocs;
35 /* Create and initialize data areas */
36 srcbuf = (int *)malloc( sizeof(int) * memsize );
37 MPI_Alloc_mem( sizeof(int) * memsize, MPI_INFO_NULL, &rmabuf );
38 if (!srcbuf || !rmabuf) {
39 printf( "Unable to allocate srcbuf and rmabuf of size %d\n", memsize );
40 MPI_Abort( MPI_COMM_WORLD, 1 );
42 for (i=0; i<memsize; i++) {
47 MPI_Win_create( rmabuf, memsize*sizeof(int), sizeof(int), MPI_INFO_NULL,
48 MPI_COMM_WORLD, &win );
50 /* Vector of 10 elements, separated by 4 */
51 MPI_Type_vector( 10, 1, 4, MPI_INT, &vectype );
52 MPI_Type_commit( &vectype );
54 /* Accumulate with a derived origin type and target predefined type*/
56 MPI_Barrier( MPI_COMM_WORLD );
57 MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
58 for (i=0; i<10; i++) {
59 if (rmabuf[i] != -i + 4*i) {
61 printf( "Acc: expected rmabuf[%d] = %d but saw %d\n",
62 i, -i + 4*i, rmabuf[i] );
66 for (i=10; i<memsize; i++) {
67 if (rmabuf[i] != -i) {
69 printf( "Acc: expected rmabuf[%d] = %d but saw %d\n",
74 MPI_Win_unlock( 0, win );
76 else if (wrank == 1) {
77 MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
78 MPI_Accumulate( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, MPI_SUM, win );
79 MPI_Win_unlock( 0, win );
80 MPI_Barrier( MPI_COMM_WORLD );
83 MPI_Barrier( MPI_COMM_WORLD );
86 MPI_Barrier(MPI_COMM_WORLD);
88 /* Put with a derived origin type and target predefined type*/
90 MPI_Barrier( MPI_COMM_WORLD );
91 MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
92 for (i=0; i<10; i++) {
93 if (rmabuf[i] != 4*i) {
95 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
100 for (i=10; i<memsize; i++) {
101 if (rmabuf[i] != -i) {
103 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
108 MPI_Win_unlock( 0, win );
110 else if (wrank == 1) {
111 MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
112 MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
113 MPI_Win_unlock( 0, win );
114 MPI_Barrier( MPI_COMM_WORLD );
117 MPI_Barrier( MPI_COMM_WORLD );
120 MPI_Barrier(MPI_COMM_WORLD);
122 /* Put with a derived origin type and target predefined type, with
123 a get (see the move-to-end optimization) */
125 MPI_Barrier( MPI_COMM_WORLD );
126 MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
127 for (i=0; i<10; i++) {
128 if (rmabuf[i] != 4*i) {
130 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
135 for (i=10; i<memsize; i++) {
136 if (rmabuf[i] != -i) {
138 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
143 MPI_Win_unlock( 0, win );
145 else if (wrank == 1) {
147 MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
148 MPI_Get( &val, 1, MPI_INT, 0, 10, 1, MPI_INT, win );
149 MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
150 MPI_Win_unlock( 0, win );
151 MPI_Barrier( MPI_COMM_WORLD );
154 printf( "Get: Expected -10, got %d\n", val );
158 MPI_Barrier( MPI_COMM_WORLD );
161 MPI_Barrier(MPI_COMM_WORLD);
163 /* Put with a derived origin type and target predefined type, with
164 a get already at the end (see the move-to-end optimization) */
166 MPI_Barrier( MPI_COMM_WORLD );
167 MPI_Win_lock( MPI_LOCK_EXCLUSIVE, 0, 0, win );
168 for (i=0; i<10; i++) {
169 if (rmabuf[i] != 4*i) {
171 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
176 for (i=10; i<memsize; i++) {
177 if (rmabuf[i] != -i) {
179 printf( "Put: expected rmabuf[%d] = %d but saw %d\n",
184 MPI_Win_unlock( 0, win );
186 else if (wrank == 1) {
188 MPI_Win_lock( MPI_LOCK_SHARED, 0, 0, win );
189 MPI_Put( srcbuf, 1, vectype, 0, 0, 10, MPI_INT, win );
190 MPI_Get( &val, 1, MPI_INT, 0, 10, 1, MPI_INT, win );
191 MPI_Win_unlock( 0, win );
192 MPI_Barrier( MPI_COMM_WORLD );
195 printf( "Get: Expected -10, got %d\n", val );
199 MPI_Barrier( MPI_COMM_WORLD );
202 MPI_Win_free( &win );
203 MPI_Free_mem( rmabuf );
205 MPI_Type_free( &vectype );
207 MTest_Finalize(errs);