Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / racc_local_comp.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2014 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <mpi.h>
8 #include <stdio.h>
9 #include <assert.h>
10 #include "mpitest.h"
11
12 #define ITER 100
13 #define MAX_SIZE 65536
14
15 int main(int argc, char *argv[])
16 {
17     int rank, nproc, i;
18     int errors = 0, all_errors = 0;
19     int *buf = NULL, *winbuf = NULL;
20     MPI_Win window;
21
22     MPI_Init(&argc, &argv);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
25
26     if (nproc < 2) {
27         if (rank == 0)
28             printf("Error: must be run with two or more processes\n");
29         MPI_Abort(MPI_COMM_WORLD, 1);
30     }
31
32     MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf);
33     MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf);
34     MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL,
35                    MPI_COMM_WORLD, &window);
36     buf[0] = 0;
37     winbuf[0]=0;
38     MPI_Win_lock_all(0, window);
39     /* Test Raccumulate local completion with small data.
40      * Small data is always copied to header packet as immediate data. */
41     if (rank == 1) {
42         for (i = 0; i < ITER; i++) {
43             MPI_Request acc_req;
44             int val = -1;
45
46             buf[0] = rank * i;
47             MPI_Raccumulate(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_MAX, window, &acc_req);
48             MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
49
50             /* reset local buffer to check local completion */
51             buf[0] = 0;
52             MPI_Win_flush(0, window);
53
54             MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
55             MPI_Win_flush(0, window);
56
57             if (val != rank * i) {
58                 printf("%d - Got %d in small Raccumulate test, expected %d (%d * %d)\n", rank, val,
59                        rank * i, rank, i);
60                 errors++;
61             }
62         }
63     }
64
65     MPI_Barrier(MPI_COMM_WORLD);
66
67     /* Test Raccumulate local completion with large data .
68      * Large data is not suitable for 1-copy optimization, and always sent out
69      * from user buffer. */
70     if (rank == 1) {
71         for (i = 0; i < ITER; i++) {
72             MPI_Request acc_req;
73             int val0 = -1, val1 = -1, val2 = -1;
74             int j;
75
76             /* initialize data */
77             for (j = 0; j < MAX_SIZE; j++) {
78                 buf[j] = rank + j + i;
79             }
80
81             MPI_Raccumulate(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, MPI_REPLACE, window,
82                             &acc_req);
83             MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
84
85             /* reset local buffer to check local completion */
86             buf[0] = 0;
87             buf[MAX_SIZE - 1] = 0;
88             buf[MAX_SIZE / 2] = 0;
89             MPI_Win_flush(0, window);
90
91             /* get remote values which are modified in local buffer after wait */
92             MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
93             MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window);
94             MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window);
95             MPI_Win_flush(0, window);
96
97             if (val0 != rank + i) {
98                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
99                        val0, rank + i);
100                 errors++;
101             }
102             if (val1 != rank + MAX_SIZE - 1 + i) {
103                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
104                        val1, rank + MAX_SIZE - 1 + i);
105                 errors++;
106             }
107             if (val2 != rank + MAX_SIZE / 2 + i) {
108                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
109                        val2, rank + MAX_SIZE / 2 + i);
110                 errors++;
111             }
112         }
113     }
114
115     MPI_Win_unlock_all(window);
116     MPI_Barrier(MPI_COMM_WORLD);
117
118     MPI_Win_free(&window);
119     if (buf)
120         MPI_Free_mem(buf);
121     if (winbuf)
122         MPI_Free_mem(winbuf);
123
124     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
125
126     if (rank == 0 && all_errors == 0)
127         printf(" No Errors\n");
128
129     MPI_Finalize();
130
131     return 0;
132 }