Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MPICH3 rma tests (15 out of 88 should be passing now)
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test4.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h" 
7 #include "stdio.h"
8 #include "stdlib.h"
9 #include "mpitest.h"
10 #include "squelch.h"
11
12 /* tests passive target RMA on 2 processes. tests the lock-single_op-unlock 
13    optimization. */
14
15 #define SIZE1 100
16 #define SIZE2 200
17
18 int main(int argc, char *argv[]) 
19
20     int rank, nprocs, A[SIZE2], B[SIZE2], i, j;
21     MPI_Comm CommDeuce;
22     MPI_Win win;
23     int errs = 0;
24
25     MTest_Init(&argc,&argv); 
26     MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
27     MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
28
29     if (nprocs < 2) {
30         printf("Run this program with 2 or more processes\n");
31         MPI_Abort(MPI_COMM_WORLD, 1);
32     }
33
34     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
35
36     if (rank < 2) {
37         if (rank == 0) {
38             for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
39             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
40
41             for (j = 0; j < 2; j++) {
42                 for (i=0; i<SIZE1; i++) {
43                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
44                     MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
45                     MPI_Win_unlock(1, win);
46                 }
47
48                 for (i=0; i<SIZE1; i++) {
49                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
50                     MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
51                     MPI_Win_unlock(1, win);
52                 }
53             }
54
55             MPI_Win_free(&win);
56
57             for (i=0; i<SIZE1; i++)
58                 if (B[i] != (-4)*(i+SIZE1)) {
59                     SQUELCH( printf("Get Error: B[%d] is %d, should be %d\n", i, B[i], (-4)*(i+SIZE1)); );
60                     errs++;
61                 }
62         }
63         else {  /* rank=1 */
64             for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
65             MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
66
67             MPI_Win_free(&win);
68
69             for (i=0; i<SIZE1; i++) {
70                 if (B[i] != i) {
71                     SQUELCH( printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i); );
72                     errs++;
73                 }
74             }
75         }
76     }
77     MPI_Comm_free(&CommDeuce);
78     MTest_Finalize(errs);
79     MPI_Finalize(); 
80     return 0; 
81