Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / lockcontention.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
11 /* This is a modified version of test4.c. Sent by Liwei Peng, Microsoft. */
12
13 /* tests passive target RMA on 3 processes. tests the lock-single_op-unlock
14    optimization. */
15
16
17 #define SIZE1 10
18 #define SIZE2 20
19
20 int main(int argc, char *argv[])
21 {
22     int rank, nprocs, A[SIZE2], B[SIZE2], i;
23     MPI_Comm CommThree;
24     MPI_Win win;
25     int errs = 0;
26     int trank = 1;
27
28     MTest_Init(&argc, &argv);
29     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
30     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31
32     if (nprocs < 3) {
33         fprintf(stderr, "Run this program with 3 or more processes\n");
34         MPI_Abort(MPI_COMM_WORLD, 1);
35     }
36
37     MPI_Comm_split(MPI_COMM_WORLD, (rank < 3), rank, &CommThree);
38
39     if (rank < 3) {
40         if (rank == 0) {
41             for (i = 0; i < SIZE2; i++) {
42                 A[i] = B[i] = i;
43             }
44         }
45         else if (rank == 2) {
46             for (i = 0; i < SIZE2; i++) {
47                 A[i] = B[i] = -1;
48             }
49         }
50         else if (rank == 1) {
51             for (i = 0; i < SIZE2; i++) {
52                 B[i] = (-4) * i;
53             }
54         }
55
56         MPI_Win_create(B, SIZE2 * sizeof(int), sizeof(int), MPI_INFO_NULL, CommThree, &win);
57
58         if (rank == 0) {
59             for (i = 0; i < SIZE1; i++) {
60                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
61                 MPI_Put(A + i, 1, MPI_INT, trank, i, 1, MPI_INT, win);
62                 /*  MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win);
63                  * MPI_Put(A+i, 1, MPI_INT, trank, i, 1, MPI_INT, win); */
64                 MPI_Win_unlock(trank, win);
65             }
66
67             MPI_Win_free(&win);
68         }
69         else if (rank == 2) {
70             for (i = 0; i < SIZE1; i++) {
71                 MPI_Win_lock(MPI_LOCK_EXCLUSIVE, trank, 0, win);
72                 MPI_Get(A + i, 1, MPI_INT, trank, SIZE1 + i, 1, MPI_INT, win);
73                 MPI_Win_unlock(trank, win);
74             }
75
76             MPI_Win_free(&win);
77
78             for (i = 0; i < SIZE1; i++)
79                 if (A[i] != (-4) * (i + SIZE1)) {
80                     printf("Get Error: A[%d] is %d, should be %d\n", i, A[i], (-4) * (i + SIZE1));
81                     errs++;
82                 }
83         }
84
85         else if (rank == 1) {   /*target */
86             MPI_Win_free(&win);
87
88             for (i = 0; i < SIZE1; i++) {
89                 if (B[i] != i) {
90                     printf("Put Error: B[%d] is %d, should be %d\n", i, B[i], i);
91                     errs++;
92                 }
93             }
94         }
95     }
96     MPI_Comm_free(&CommThree);
97
98     MTest_Finalize(errs);
99     MPI_Finalize();
100     return 0;
101 }