Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some tests to avoid useless global variables
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / get_acc_local.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <mpi.h>
10
11 #include "mpitest.h"
12
13 int errors = 0;
14 const int NITER = 1000;
15 const int acc_val = 3;
16
17 int main(int argc, char **argv)
18 {
19     int rank, nproc;
20     int out_val, i, counter = 0;
21     MPI_Win win;
22
23     MPI_Init(&argc, &argv);
24
25     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
27
28     MPI_Win_create(&counter, sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win);
29
30     for (i = 0; i < NITER; i++) {
31         MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
32         MPI_Get_accumulate(&acc_val, 1, MPI_INT, &out_val, 1, MPI_INT,
33                            rank, 0, 1, MPI_INT, MPI_SUM, win);
34         MPI_Win_unlock(rank, win);
35
36         if (out_val != acc_val * i) {
37             errors++;
38             printf("Error: got %d, expected %d at iter %d\n", out_val, acc_val * i, i);
39             break;
40         }
41     }
42
43     MPI_Win_free(&win);
44
45     if (errors == 0 && rank == 0)
46         printf(" No errors\n");
47
48     MPI_Finalize();
49
50     return 0;
51 }