Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This particular RMA test is filled with stupid calls... We send errors for most of...
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / derived-acc-flush_local.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 one process issues large number
8  * of MPI_Accumulate operations (with large derived datatype) and
9  * issues a MPI_Win_flush_local at end. */
10
11 /* FIXME: we should merge this into a comprehensive test for RMA
12  * operations + MPI_Win_flush_local. */
13
14 #include "mpi.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <time.h>
18
19 #define DATA_SIZE 1000000
20 #define COUNT 5000
21 #define BLOCKLENGTH (DATA_SIZE/COUNT)
22 #define STRIDE BLOCKLENGTH
23 #define OPS_NUM 500
24
25 int main(int argc, char *argv[])
26 {
27     int rank, nproc;
28     int i;
29     MPI_Win win;
30     int *tar_buf = NULL;
31     int *orig_buf = NULL;
32     MPI_Datatype derived_dtp;
33     int errors = 0;
34
35     MPI_Init(&argc, &argv);
36
37     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
38     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
39
40     if (nproc < 3) {
41         fprintf(stderr, "Run this program with at least 3 processes\n");
42         MPI_Abort(MPI_COMM_WORLD, 1);
43     }
44
45     MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
46     MPI_Alloc_mem(sizeof(int) * DATA_SIZE, MPI_INFO_NULL, &tar_buf);
47
48     for (i = 0; i < DATA_SIZE; i++) {
49         orig_buf[i] = 1;
50         tar_buf[i] = 0;
51     }
52
53     MPI_Type_vector(COUNT, BLOCKLENGTH - 1, STRIDE, MPI_INT, &derived_dtp);
54     MPI_Type_commit(&derived_dtp);
55
56     MPI_Win_create(tar_buf, sizeof(int) * DATA_SIZE, sizeof(int),
57                    MPI_INFO_NULL, MPI_COMM_WORLD, &win);
58
59     /***** test between rank 0 and rank 1 *****/
60
61     if (rank == 1) {
62         MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
63
64         for (i = 0; i < OPS_NUM; i++) {
65             MPI_Accumulate(orig_buf, 1, derived_dtp,
66                            0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win);
67             MPI_Win_flush_local(0, win);
68         }
69
70         MPI_Win_unlock(0, win);
71     }
72
73     MPI_Barrier(MPI_COMM_WORLD);
74
75     /* check results */
76     if (rank == 0) {
77         for (i = 0; i < DATA_SIZE - COUNT; i++) {
78             if (tar_buf[i] != OPS_NUM) {
79                 printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM);
80                 errors++;
81             }
82         }
83     }
84
85     for (i = 0; i < DATA_SIZE; i++) {
86         tar_buf[i] = 0;
87     }
88
89     MPI_Barrier(MPI_COMM_WORLD);
90
91     /***** test between rank 0 and rank 2 *****/
92
93     if (rank == 2) {
94         MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
95
96         for (i = 0; i < OPS_NUM; i++) {
97             MPI_Accumulate(orig_buf, 1, derived_dtp,
98                            0, 0, DATA_SIZE - COUNT, MPI_INT, MPI_SUM, win);
99             MPI_Win_flush_local(0, win);
100         }
101
102         MPI_Win_unlock(0, win);
103     }
104
105     MPI_Barrier(MPI_COMM_WORLD);
106
107     /* check results */
108     if (rank == 0) {
109         for (i = 0; i < DATA_SIZE - COUNT; i++) {
110             if (tar_buf[i] != OPS_NUM) {
111                 printf("tar_buf[%d] = %d, expected %d\n", i, tar_buf[i], OPS_NUM);
112                 errors++;
113             }
114         }
115
116         if (errors == 0)
117             printf(" No Errors\n");
118     }
119
120     MPI_Win_free(&win);
121
122     MPI_Type_free(&derived_dtp);
123
124     MPI_Free_mem(orig_buf);
125     MPI_Free_mem(tar_buf);
126
127     MPI_Finalize();
128
129     return 0;
130 }