Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / strided_get_indexed.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 /* One-Sided MPI 2-D Strided Get Test
8  *
9  * Author: James Dinan <dinan@mcs.anl.gov>
10  * Date  : December, 2010
11  *
12  * This code performs N strided get operations from a 2d patch of a shared
13  * array.  The array has dimensions [X, Y] and the subarray has dimensions
14  * [SUB_X, SUB_Y] and begins at index [0, 0].  The input and output buffers are
15  * specified using an MPI indexed type.
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <math.h>
21 #include <mpi.h>
22 #include "mpitest.h"
23 #include "squelch.h"
24
25 #define XDIM 8
26 #define YDIM 1024
27 #define SUB_XDIM 8
28 #define SUB_YDIM 256
29
30 int main(int argc, char **argv)
31 {
32     int i, j, rank, nranks, peer, bufsize, errors;
33     double *win_buf, *loc_buf;
34     MPI_Win buf_win;
35
36     int idx_rem[SUB_YDIM];
37     int blk_len[SUB_YDIM];
38     MPI_Datatype loc_type, rem_type;
39
40     MTest_Init(&argc, &argv);
41
42     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
43     MPI_Comm_size(MPI_COMM_WORLD, &nranks);
44
45     bufsize = XDIM * YDIM * sizeof(double);
46     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
47     MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &loc_buf);
48
49     for (i = 0; i < XDIM * YDIM; i++) {
50         *(win_buf + i) = 1.0 + rank;
51         *(loc_buf + i) = -1.0;
52     }
53
54     MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
55
56     peer = (rank + 1) % nranks;
57
58     /* Build the datatype */
59
60     for (i = 0; i < SUB_YDIM; i++) {
61         idx_rem[i] = i * XDIM;
62         blk_len[i] = SUB_XDIM;
63     }
64
65     MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &loc_type);
66     MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &rem_type);
67
68     MPI_Type_commit(&loc_type);
69     MPI_Type_commit(&rem_type);
70
71     /* Perform get operation */
72
73     MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
74
75     MPI_Get(loc_buf, 1, loc_type, peer, 0, 1, rem_type, buf_win);
76
77     /* Use the datatype only on the remote side (must have SUB_XDIM == XDIM) */
78     /* MPI_Get(loc_buf, SUB_XDIM*SUB_YDIM, MPI_DOUBLE, peer, 0, 1, rem_type, buf_win); */
79
80     MPI_Win_unlock(peer, buf_win);
81
82     MPI_Type_free(&loc_type);
83     MPI_Type_free(&rem_type);
84
85     MPI_Barrier(MPI_COMM_WORLD);
86
87     /* Verify that the results are correct */
88
89     errors = 0;
90     for (i = 0; i < SUB_XDIM; i++) {
91         for (j = 0; j < SUB_YDIM; j++) {
92             const double actual = *(loc_buf + i + j * XDIM);
93             const double expected = (1.0 + peer);
94             if (fabs(actual - expected) > 1.0e-10) {
95                 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
96                                rank, j, i, expected, actual););
97                 errors++;
98                 fflush(stdout);
99             }
100         }
101     }
102     for (i = SUB_XDIM; i < XDIM; i++) {
103         for (j = 0; j < SUB_YDIM; j++) {
104             const double actual = *(loc_buf + i + j * XDIM);
105             const double expected = -1.0;
106             if (fabs(actual - expected) > 1.0e-10) {
107                 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
108                                rank, j, i, expected, actual););
109                 errors++;
110                 fflush(stdout);
111             }
112         }
113     }
114     for (i = 0; i < XDIM; i++) {
115         for (j = SUB_YDIM; j < YDIM; j++) {
116             const double actual = *(loc_buf + i + j * XDIM);
117             const double expected = -1.0;
118             if (fabs(actual - expected) > 1.0e-10) {
119                 SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
120                                rank, j, i, expected, actual););
121                 errors++;
122                 fflush(stdout);
123             }
124         }
125     }
126
127     MPI_Win_free(&buf_win);
128     MPI_Free_mem(win_buf);
129     MPI_Free_mem(loc_buf);
130
131     MTest_Finalize(errors);
132     MPI_Finalize();
133     return MTestReturnValue(errors);
134 }