Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / test3_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 the example in Fig 6.8, pg 142, MPI-2 standard. Process 1 has
13    a blocking MPI_Recv between the Post and Wait. Therefore, this
14    example will not run if the one-sided operations are simply
15    implemented on top of MPI_Isends and Irecvs. They either need to be
16    implemented inside the progress engine or using threads with Isends
17    and Irecvs. In MPICH-2, they are implemented in the progress engine. */
18
19 /* same as test3.c but uses alloc_mem */
20
21 #define SIZE 1048576
22
23 int main(int argc, char *argv[]) 
24
25     int rank, destrank, nprocs, *A, *B, i;
26     MPI_Comm CommDeuce;
27     MPI_Group comm_group, group;
28     MPI_Win win;
29     int errs = 0;
30
31     MTest_Init(&argc,&argv); 
32     MPI_Comm_size(MPI_COMM_WORLD,&nprocs); 
33     MPI_Comm_rank(MPI_COMM_WORLD,&rank); 
34
35     if (nprocs < 2) {
36         printf("Run this program with 2 or more processes\n");
37         MPI_Abort(MPI_COMM_WORLD, 1);
38     }
39
40     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
41
42     if (rank < 2) {
43         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &A);
44         if (i) {
45             printf("Can't allocate memory in test program\n");
46             MPI_Abort(MPI_COMM_WORLD, 1);
47         }
48         i = MPI_Alloc_mem(SIZE * sizeof(int), MPI_INFO_NULL, &B);
49         if (i) {
50             printf("Can't allocate memory in test program\n");
51             MPI_Abort(MPI_COMM_WORLD, 1);
52         }
53
54         MPI_Comm_group(CommDeuce, &comm_group);
55
56         if (rank == 0) {
57             for (i=0; i<SIZE; i++) {
58                 A[i] = i;
59                 B[i] = SIZE + i;
60             }
61             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
62             destrank = 1;
63             MPI_Group_incl(comm_group, 1, &destrank, &group);
64             MPI_Win_start(group, 0, win);
65             MPI_Put(A, SIZE, MPI_INT, 1, 0, SIZE, MPI_INT, win);
66             MPI_Win_complete(win);
67             MPI_Send(B, SIZE, MPI_INT, 1, 100, MPI_COMM_WORLD);
68         }
69         else {  /* rank=1 */
70             for (i=0; i<SIZE; i++) A[i] = B[i] = (-4)*i;
71             MPI_Win_create(B, SIZE*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
72             destrank = 0;
73             MPI_Group_incl(comm_group, 1, &destrank, &group);
74             MPI_Win_post(group, 0, win);
75             MPI_Recv(A, SIZE, MPI_INT, 0, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
76             MPI_Win_wait(win);
77
78             for (i=0; i<SIZE; i++) {
79                 if (B[i] != i) {
80                     SQUELCH( printf("Rank 1: Put Error: B[i] is %d, should be %d\n", B[i], i); );
81                     errs++;
82                 }
83                 if (A[i] != SIZE + i) {
84                     SQUELCH( printf("Rank 1: Send/Recv Error: A[i] is %d, should be %d\n", A[i], SIZE+i); );
85                     errs++;
86                 }
87             }
88         }
89
90         MPI_Group_free(&group);
91         MPI_Group_free(&comm_group);
92         MPI_Win_free(&win);
93         MPI_Free_mem(A);
94         MPI_Free_mem(B);
95     }
96     MPI_Comm_free(&CommDeuce);
97     MTest_Finalize(errs);
98     MPI_Finalize(); 
99     return 0; 
100