Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
emptty said it is better like this. Obey!
[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
37     MPI_Win_lock_all(0, window);
38     buf[0] = 0;
39     winbuf[0]=0;
40     /* Test Raccumulate local completion with small data.
41      * Small data is always copied to header packet as immediate data. */
42     if (rank == 1) {
43         for (i = 0; i < ITER; i++) {
44             MPI_Request acc_req;
45             int val = -1;
46
47             buf[0] = rank * i;
48             MPI_Raccumulate(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_MAX, window, &acc_req);
49             MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
50
51             /* reset local buffer to check local completion */
52             buf[0] = 0;
53             MPI_Win_flush(0, window);
54
55             MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
56             MPI_Win_flush(0, window);
57
58             if (val != rank * i) {
59                 printf("%d - Got %d in small Raccumulate test, expected %d (%d * %d)\n", rank, val,
60                        rank * i, rank, i);
61                 errors++;
62             }
63         }
64     }
65
66     MPI_Barrier(MPI_COMM_WORLD);
67
68     /* Test Raccumulate local completion with large data .
69      * Large data is not suitable for 1-copy optimization, and always sent out
70      * from user buffer. */
71     if (rank == 1) {
72         for (i = 0; i < ITER; i++) {
73             MPI_Request acc_req;
74             int val0 = -1, val1 = -1, val2 = -1;
75             int j;
76
77             /* initialize data */
78             for (j = 0; j < MAX_SIZE; j++) {
79                 buf[j] = rank + j + i;
80             }
81
82             MPI_Raccumulate(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, MPI_REPLACE, window,
83                             &acc_req);
84             MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
85
86             /* reset local buffer to check local completion */
87             buf[0] = 0;
88             buf[MAX_SIZE - 1] = 0;
89             buf[MAX_SIZE / 2] = 0;
90             MPI_Win_flush(0, window);
91
92             /* get remote values which are modified in local buffer after wait */
93             MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
94             MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window);
95             MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window);
96             MPI_Win_flush(0, window);
97
98             if (val0 != rank + i) {
99                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
100                        val0, rank + i);
101                 errors++;
102             }
103             if (val1 != rank + MAX_SIZE - 1 + i) {
104                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
105                        val1, rank + MAX_SIZE - 1 + i);
106                 errors++;
107             }
108             if (val2 != rank + MAX_SIZE / 2 + i) {
109                 printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
110                        val2, rank + MAX_SIZE / 2 + i);
111                 errors++;
112             }
113         }
114     }
115
116     MPI_Win_unlock_all(window);
117     MPI_Barrier(MPI_COMM_WORLD);
118
119     MPI_Win_free(&window);
120     if (buf)
121         MPI_Free_mem(buf);
122     if (winbuf)
123         MPI_Free_mem(winbuf);
124
125     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
126
127     if (rank == 0 && all_errors == 0)
128         printf(" No Errors\n");
129
130     MPI_Finalize();
131
132     return 0;
133 }