Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test2.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 "mpitest.h"
9 #include "squelch.h"
10
11 /* tests put and get with post/start/complete/wait on 2 processes */
12
13 #define SIZE1 100
14 #define SIZE2 200
15
16 int main(int argc, char *argv[]) 
17
18     int rank, destrank, nprocs, A[SIZE2], B[SIZE2], i;
19     MPI_Comm CommDeuce;
20     MPI_Group comm_group, group;
21     MPI_Win win;
22     int errs = 0;
23
24     MTest_Init(&argc,&argv); 
25     MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
26     MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
27
28     if (nprocs < 2) {
29         printf("Run this program with 2 or more processes\n");
30         MPI_Abort(MPI_COMM_WORLD, 1);
31     }
32
33     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
34
35     if (rank < 2)
36     {
37         MPI_Comm_group(CommDeuce, &comm_group);
38
39         if (rank == 0) {
40             for (i=0; i<SIZE2; i++) A[i] = B[i] = i;
41             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
42             destrank = 1;
43             MPI_Group_incl(comm_group, 1, &destrank, &group);
44             MPI_Win_start(group, 0, win);
45             for (i=0; i<SIZE1; i++)
46                 MPI_Put(A+i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
47             for (i=0; i<SIZE1; i++)
48                 MPI_Get(B+i, 1, MPI_INT, 1, SIZE1+i, 1, MPI_INT, win);
49
50             MPI_Win_complete(win);
51
52             for (i=0; i<SIZE1; i++)
53                 if (B[i] != (-4)*(i+SIZE1)) {
54                     SQUELCH( printf("Get Error: B[i] is %d, should be %d\n", B[i], (-4)*(i+SIZE1)); );
55                     errs++;
56                 }
57         }
58         else if (rank == 1) {
59             for (i=0; i<SIZE2; i++) B[i] = (-4)*i;
60             MPI_Win_create(B, SIZE2*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
61             destrank = 0;
62             MPI_Group_incl(comm_group, 1, &destrank, &group);
63             MPI_Win_post(group, 0, win);
64             MPI_Win_wait(win);
65
66             for (i=0; i<SIZE1; i++) {
67                 if (B[i] != i) {
68                     SQUELCH( printf("Put Error: B[i] is %d, should be %d\n", B[i], i); );
69                     errs++;
70                 }
71             }
72         }
73
74         MPI_Group_free(&group);
75         MPI_Group_free(&comm_group);
76         MPI_Win_free(&win);
77     }
78     MPI_Comm_free(&CommDeuce);
79     MTest_Finalize(errs);
80     MPI_Finalize();
81     return 0; 
82