Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / large-small-acc.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2015 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* This code tests the case when a large ACC is issued, and then
8  * several small ACCs is issued between the same origin and target.
9  * The purpose of this test is to check if the ordering of ACCs
10  * is guaranteed. */
11
12 #include "mpi.h"
13 #include <stdio.h>
14 #include <stdint.h>
15
16 #define LOOP 5
17 #define DATA_COUNT 8192
18
19 int main(int argc, char *argv[])
20 {
21     int rank, nprocs;
22     MPI_Win win;
23     uint64_t buf[DATA_COUNT], orig_buf[DATA_COUNT];
24     uint64_t small_orig_buf_1 = 2, small_orig_buf_2[2] = { 3, 3 };
25     int i, j, error = 0;
26
27     MPI_Init(&argc, &argv);
28     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
29     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30
31     for (j = 0; j < LOOP; j++) {
32
33         error = 0;
34
35         for (i = 0; i < DATA_COUNT; i++) {
36             buf[i] = 0;
37             orig_buf[i] = 1;
38         }
39
40         MPI_Win_create(buf, sizeof(uint64_t) * DATA_COUNT, sizeof(uint64_t),
41                        MPI_INFO_NULL, MPI_COMM_WORLD, &win);
42
43         MPI_Win_fence(0, win);
44
45         if (rank == 0) {
46             /* ACC (atomic PUT) to win_buf[0...DATA_COUNT-1] */
47             MPI_Accumulate(orig_buf, DATA_COUNT, MPI_UINT64_T, 1, 0, DATA_COUNT, MPI_UINT64_T,
48                            MPI_REPLACE, win);
49             /* ACC (atomic PUT) to win_buf[0] */
50             MPI_Accumulate(&small_orig_buf_1, 1, MPI_UINT64_T, 1, 0, 1, MPI_UINT64_T, MPI_REPLACE,
51                            win);
52             /* ACC (atomic PUT) to win_buf[1,2] */
53             MPI_Accumulate(&small_orig_buf_2, 2, MPI_UINT64_T, 1, 1, 2, MPI_UINT64_T, MPI_REPLACE,
54                            win);
55         }
56
57         MPI_Win_fence(0, win);
58
59         if (rank == 1) {
60             for (i = 0; i < DATA_COUNT; i++) {
61                 if (i == 0) {
62                     if (buf[i] != 2) {
63                         error++;
64                     }
65                 }
66                 else if (i == 1 || i == 2) {
67                     if (buf[i] != 3) {
68                         error++;
69                     }
70                 }
71                 else {
72                     if (buf[i] != 1) {
73                         error++;
74                     }
75                 }
76             }
77         }
78
79         MPI_Win_free(&win);
80     }
81
82     if (rank == 1 && error == 0) {
83         printf(" No Errors\n");
84     }
85
86     MPI_Finalize();
87     return 0;
88 }