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_am.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 /* same as test4.c but uses alloc_mem */
16
17 #define SIZE1 100
18 #define SIZE2 200
19
20 int main(int argc, char *argv[]) 
21
22     int rank, nprocs, *A, *B, i; 
23     MPI_Comm CommDeuce;
24     MPI_Win win;
25     int errs = 0;
26
27     MTest_Init(&argc,&argv); 
28     MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
29     MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
30
31     if (nprocs < 2) {
32         printf("Run this program with 2 or more processes\n");
33         MPI_Abort(MPI_COMM_WORLD, 1);
34     }
35
36     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
37
38     if (rank < 2) {
39         i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &A);
40         if (i) {
41             printf("Can't allocate memory in test program\n");
42             MPI_Abort(MPI_COMM_WORLD, 1);
43         }
44         i = MPI_Alloc_mem(SIZE2 * sizeof(int), MPI_INFO_NULL, &B);
45         if (i) {
46             printf("Can't allocate memory in test program\n");
47             MPI_Abort(MPI_COMM_WORLD, 1);
48         }
49
50         if (rank == 0) {
51             for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
52             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
53
54             for (i=0; i<SIZE1; i++) {
55                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
56                 MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
57                 MPI_Win_unlock(1, win);
58             }
59
60             for (i=0; i<SIZE1; i++) {
61                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
62                 MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
63                 MPI_Win_unlock(1, win);
64             }
65
66             MPI_Win_free(&win);
67
68             for (i=0; i<SIZE1; i++)
69                 if (B[i] != (-4)*(i+SIZE1)) {
70                     SQUELCH( printf("Get Error: B[%d] is %d, should be %d\n", i, B[i], (-4)*(i+SIZE1)); );
71                     errs++;
72                 }
73         }
74         else {  /* rank=1 */
75             for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
76             MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
77
78             MPI_Win_free(&win);
79
80             for (i=0; i<SIZE1; i++) {
81                 if (B[i] != i) {
82                     SQUELCH( printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i); );
83                     errs++;
84                 }
85             }
86         }
87
88         MPI_Free_mem(A);
89         MPI_Free_mem(B);
90     }
91     MPI_Comm_free(&CommDeuce);
92     MTest_Finalize(errs);
93     MPI_Finalize(); 
94     return 0; 
95