Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[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++)
52                 A[i] = B[i] = i;
53             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
54
55             for (i = 0; i < SIZE1; i++) {
56                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
57                 MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
58                 MPI_Win_unlock(1, win);
59             }
60
61             for (i = 0; i < SIZE1; i++) {
62                 MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
63                 MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
64                 MPI_Win_unlock(1, win);
65             }
66
67             MPI_Win_free(&win);
68
69             for (i = 0; i < SIZE1; i++)
70                 if (B[i] != (-4) * (i + SIZE1)) {
71                     SQUELCH(printf
72                             ("Get Error: B[%d] is %d, should be %d\n", i, B[i],
73                              (-4) * (i + SIZE1)););
74                     errs++;
75                 }
76         }
77         else {  /* rank=1 */
78             for (i = 0; i < SIZE2; i++)
79                 B[i] = (-4) * i;
80             MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
81
82             MPI_Win_free(&win);
83
84             for (i = 0; i < SIZE1; i++) {
85                 if (B[i] != i) {
86                     SQUELCH(printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i););
87                     errs++;
88                 }
89             }
90         }
91
92         MPI_Free_mem(A);
93         MPI_Free_mem(B);
94     }
95     MPI_Comm_free(&CommDeuce);
96     MTest_Finalize(errs);
97     MPI_Finalize();
98     return 0;
99 }