1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
3 * (C) 2016 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
14 /* This program tests nested lock. Process 0 locks the other processes
15 * one by one, then unlock each of them.*/
17 int main(int argc, char *argv[])
19 int rank = 0, nprocs = 0, dst = 0;
21 MPI_Win win = MPI_WIN_NULL;
23 MPI_Init(&argc, &argv);
24 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
27 memset(winbuf, 0, sizeof(int) * BUFSIZE);
28 MPI_Win_create(winbuf, sizeof(int) * BUFSIZE, sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
31 /* lock each process */
32 for (dst = 0; dst < nprocs; dst++) {
33 MPI_Win_lock(MPI_LOCK_SHARED, dst, 0, win);
36 /* unlock each process */
37 for (dst = nprocs - 1; dst >= 0; dst--) {
38 MPI_Win_unlock(dst, win);
42 MPI_Barrier(MPI_COMM_WORLD);
46 fprintf(stdout, " No Errors\n");