Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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     int       i, j, rank, nproc;
20     int       errors = 0, all_errors = 0;
21     int       val = 0, one = 1;
22     int       iter;
23     MPI_Aint *val_ptrs;
24     MPI_Win   dyn_win;
25
26     MPI_Init(&argc, &argv);
27
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
30
31     iter = ITER_PER_RANK * nproc;
32
33     val_ptrs = malloc(nproc * sizeof(MPI_Aint));
34     MPI_Get_address(&val, &val_ptrs[rank]);
35
36     MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, val_ptrs, 1, MPI_AINT,
37                   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, dyn_win);
45             MPI_Win_fence(MPI_MODE_NOSUCCEED, dyn_win);
46     }
47
48     MPI_Barrier(MPI_COMM_WORLD);
49
50     /* Read and verify my data */
51     if ( val != iter ) {
52         errors++;
53         printf("%d -- Got %d, expected %d\n", rank, val, iter);
54     }
55
56     MPI_Win_detach(dyn_win, &val);
57     MPI_Win_free(&dyn_win);
58
59     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
60
61     if (rank == 0 && all_errors == 0)
62         printf(" No Errors\n");
63
64     free(val_ptrs);
65     MPI_Finalize();
66
67     return 0;
68 }