Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / win_dynamic_acc.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <assert.h>
11 #include <mpi.h>
12 #include "mpitest.h"
13
14 #define ITER_PER_RANK 25
15
16 const int verbose = 0;
17
18 int main(int argc, char **argv)
19 {
20     int i, rank, nproc;
21     int errors = 0, all_errors = 0;
22     int val = 0, one = 1;
23     int iter;
24     MPI_Aint *val_ptrs;
25     MPI_Win dyn_win;
26
27     MPI_Init(&argc, &argv);
28
29     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
31
32     iter = ITER_PER_RANK * nproc;
33
34     val_ptrs = malloc(nproc * sizeof(MPI_Aint));
35     MPI_Get_address(&val, &val_ptrs[rank]);
36
37     MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, val_ptrs, 1, MPI_AINT, MPI_COMM_WORLD);
38
39     MPI_Win_create_dynamic(MPI_INFO_NULL, MPI_COMM_WORLD, &dyn_win);
40     MPI_Win_attach(dyn_win, &val, sizeof(int));
41
42     for (i = 0; i < iter; i++) {
43         MPI_Win_fence(MPI_MODE_NOPRECEDE, dyn_win);
44         MPI_Accumulate(&one, 1, MPI_INT, i % nproc, val_ptrs[i % nproc], 1, MPI_INT, MPI_SUM,
45                        dyn_win);
46         MPI_Win_fence(MPI_MODE_NOSUCCEED, dyn_win);
47     }
48
49     MPI_Barrier(MPI_COMM_WORLD);
50
51     /* Read and verify my data */
52     if (val != iter) {
53         errors++;
54         printf("%d -- Got %d, expected %d\n", rank, val, iter);
55     }
56
57     MPI_Win_detach(dyn_win, &val);
58     MPI_Win_free(&dyn_win);
59
60     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
61
62     if (rank == 0 && all_errors == 0)
63         printf(" No Errors\n");
64
65     free(val_ptrs);
66     MPI_Finalize();
67
68     return 0;
69 }