Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / locknull.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2008 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "mpitest.h"
11 #include <string.h>
12
13 /*
14 static char MTEST_Descrip[] = "Locks with no RMA operations";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     int rank, size, i;
21     MPI_Comm comm;
22     MPI_Win win;
23     int *winbuf, count;
24
25     MTest_Init(&argc, &argv);
26
27     comm = MPI_COMM_WORLD;
28
29     MPI_Comm_rank(comm, &rank);
30     MPI_Comm_size(comm, &size);
31
32     /* Allocate and initialize buf */
33     count = 1000;
34
35     MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
36
37     MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
38
39     /* Clear winbuf */
40     memset(winbuf, 0, count * sizeof(int));
41
42     /* Note that for i == rank, this is a useful operation - it allows
43      * the programmer to use direct loads and stores, rather than
44      * put/get/accumulate, to access the local memory window. */
45     for (i = 0; i < size; i++) {
46         MPI_Win_lock(MPI_LOCK_EXCLUSIVE, i, 0, win);
47         MPI_Win_unlock(i, win);
48     }
49
50     for (i = 0; i < size; i++) {
51         MPI_Win_lock(MPI_LOCK_SHARED, i, 0, win);
52         MPI_Win_unlock(i, win);
53     }
54
55     MPI_Win_free(&win);
56     MPI_Free_mem(winbuf);
57
58     /* If this test completes, no error has been found */
59     /* A more complete test may ensure that local locks in fact block
60      * remote, exclusive locks */
61     MTest_Finalize(errs);
62
63     MPI_Finalize();
64     return 0;
65 }