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 / lock_nested.c
1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3  * (C) 2016 by Argonne National Laboratory.
4  *     See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <mpi.h>
11
12 #define BUFSIZE 4
13
14 /* This program tests nested lock. Process 0 locks the other processes
15  * one by one, then unlock each of them.*/
16
17 int main(int argc, char *argv[])
18 {
19     int rank = 0, nprocs = 0, dst = 0;
20     int winbuf[BUFSIZE];
21     MPI_Win win = MPI_WIN_NULL;
22
23     MPI_Init(&argc, &argv);
24     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
26
27     memset(winbuf, 0, sizeof(int) * BUFSIZE);
28     MPI_Win_create(winbuf, sizeof(int) * BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
29
30     if (rank == 0) {
31         /* lock each process */
32         for (dst = 0; dst < nprocs; dst++) {
33             MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win);
34         }
35
36         /* unlock each process */
37         for (dst = nprocs - 1; dst >= 0; dst--) {
38             MPI_Win_unlock(dst, win);
39         }
40     }
41
42     MPI_Barrier(MPI_COMM_WORLD);
43     MPI_Win_free(&win);
44
45     if (rank == 0) {
46         fprintf(stdout, " No Errors\n");
47         fflush(stdout);
48     }
49
50     MPI_Finalize();
51     return 0;
52 }