Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
[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++)
39                 A[i] = B[i] = i;
40             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
41
42             for (j = 0; j < 2; j++) {
43                 for (i = 0; i < SIZE1; i++) {
44                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
45                     MPI_Put(A + i, 1, MPI_INT, 1, i, 1, MPI_INT, win);
46                     MPI_Win_unlock(1, win);
47                 }
48
49                 for (i = 0; i < SIZE1; i++) {
50                     MPI_Win_lock(MPI_LOCK_SHARED, 1, j == 0 ? 0 : MPI_MODE_NOCHECK, win);
51                     MPI_Get(B + i, 1, MPI_INT, 1, SIZE1 + i, 1, MPI_INT, win);
52                     MPI_Win_unlock(1, win);
53                 }
54             }
55
56             MPI_Win_free(&win);
57
58             for (i = 0; i < SIZE1; i++)
59                 if (B[i] != (-4) * (i + SIZE1)) {
60                     SQUELCH(printf
61                             ("Get Error: B[%d] is %d, should be %d\n", i, B[i],
62                              (-4) * (i + SIZE1)););
63                     errs++;
64                 }
65         }
66         else {  /* rank=1 */
67             for (i = 0; i < SIZE2; i++)
68                 B[i] = (-4) * i;
69             MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
70
71             MPI_Win_free(&win);
72
73             for (i = 0; i < SIZE1; i++) {
74                 if (B[i] != i) {
75                     SQUELCH(printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i););
76                     errs++;
77                 }
78             }
79         }
80     }
81     MPI_Comm_free(&CommDeuce);
82     MTest_Finalize(errs);
83     MPI_Finalize();
84     return 0;
85 }