1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
/* This test checks accumulate ordering in three cases:
* 1) Default (most restricted)
* 2) None (no ordering)
* 3) Mixture of REPLACE and MIN_LOC/MAX_LOC.
* (In CH4/OFI, REPLACE may go through OFI but MIN_LOC/MAX_LOC has to go through active message.)
*/
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <limits.h>
#include "mpitest.h"
typedef struct {
int val;
int loc;
} twoint_t;
#define ARRAY_LEN (8192/(sizeof(twoint_t)))
static int errs = 0;
static void verify_result(twoint_t * data, int len, twoint_t expected, const char *test_name)
{
int i;
for (i = 0; i < len; i++) {
if ((data[i].val != expected.val) || (data[i].loc != expected.loc)) {
errs++;
printf("%s: Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
test_name, expected.loc, expected.val, data[i].loc, data[i].val);
}
}
}
/* Check non-deterministic result of none ordering.
* Expected result has two possibilities. */
static void verify_nondeterministic_result(twoint_t * data,
int len, twoint_t * expected, const char *test_name)
{
int i;
for (i = 0; i < len; i++) {
if (!((data[i].loc == expected[0].loc && data[0].val == expected[0].val)
|| (data[i].loc == expected[1].loc && data[i].val == expected[1].val))) {
errs++;
printf
("%s: Expected: { loc = %d, val = %d } or { loc = %d, val = %d }; Actual: { loc = %d, val = %d }\n",
test_name, expected[0].loc, expected[0].val, expected[1].loc, expected[1].val,
data[i].loc, data[i].val);
}
}
}
int main(int argc, char **argv)
{
int me, nproc, i;
twoint_t *data;
twoint_t *mine = NULL;
twoint_t *mine_plus = NULL;
twoint_t *expected = NULL;
MPI_Win win;
MPI_Info info_in;
MTest_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &me);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
if (nproc < 2) {
printf("Run this program with 2 or more processes\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
data = (twoint_t *) calloc(ARRAY_LEN, sizeof(twoint_t));
if (me == 0) {
/* length of 2 in order to store all results for none ordering. */
expected = (twoint_t *) malloc(2 * sizeof(twoint_t));
}
if (me == nproc - 1) {
mine = (twoint_t *) malloc(ARRAY_LEN * sizeof(twoint_t));
mine_plus = (twoint_t *) malloc(ARRAY_LEN * sizeof(twoint_t));
for (i = 0; i < ARRAY_LEN; i++) {
mine[i].val = me + 1;
mine[i].loc = me;
mine_plus[i].val = me + 2;
mine_plus[i].loc = me + 1;
}
}
/* 1. Default ordering */
MPI_Win_create(data, sizeof(twoint_t) * ARRAY_LEN, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
MPI_Win_fence(0, win);
/* Rank np-1 performs 2 WRITE to rank 0. */
/* 1.a. Single data test */
if (me == nproc - 1) {
MPI_Accumulate(mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine_plus, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
expected[0].loc = nproc;
expected[0].val = nproc + 1;
verify_result(data, 1, expected[0], "Single data test case for default ordering");
}
if (me == 0) {
data[0].loc = 0;
data[0].val = 0;
}
MPI_Win_fence(0, win);
/* 1.b. Large array test */
if (me == nproc - 1) {
MPI_Accumulate(mine, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine_plus, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
verify_result(data, ARRAY_LEN, expected[0], "Large array test case for default ordering");
}
/* MPI Implementation may ignore window info changes once created.
* Thus we should free current window and create a new window with required info. */
MPI_Win_free(&win);
/* 2. None ordering */
if (me == 0) {
/* reset data on rank 0. */
memset((void *) data, 0, ARRAY_LEN * sizeof(twoint_t));
}
MPI_Info_create(&info_in);
MPI_Info_set(info_in, "accumulate_ordering", "none");
MPI_Win_create(data, sizeof(twoint_t) * ARRAY_LEN, 1, info_in, MPI_COMM_WORLD, &win);
MPI_Info_free(&info_in);
MPI_Win_fence(0, win);
/* Rank np-1 performs 2 WRITE to rank 0. */
/* 2.a. Single data test */
if (me == nproc - 1) {
MPI_Accumulate(mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine_plus, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
expected[0].loc = nproc - 1;
expected[0].val = nproc;
expected[1].loc = nproc;
expected[1].val = nproc + 1;
verify_nondeterministic_result(data, 1, expected,
"Single data test case for none ordering");
}
if (me == 0) {
data[0].loc = 0;
data[0].val = 0;
}
MPI_Win_fence(0, win);
/* 2.b. Large array test */
if (me == nproc - 1) {
MPI_Accumulate(mine, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine_plus, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
verify_nondeterministic_result(data, ARRAY_LEN, expected,
"Large array test case for none ordering");
}
MPI_Win_free(&win);
/* 3. Mix MAX_LOC/MIN_LOC and MPI_REPLACE */
if (me == 0) {
/* reset data on rank 0. */
memset((void *) data, 0, ARRAY_LEN * sizeof(twoint_t));
}
MPI_Win_create(data, sizeof(twoint_t) * ARRAY_LEN, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
MPI_Win_fence(0, win);
/* Rank np-1 performs 2 WRITE to rank 0. */
/* Test MAXLOC */
/* 3.a. Single data test */
if (me == nproc - 1) {
MPI_Accumulate(mine_plus, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MAXLOC, win);
MPI_Accumulate(mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
expected[0].loc = nproc - 1;
expected[0].val = nproc;
verify_result(data, 1, expected[0], "Single data test case for MAXLOC and REPLACE");
}
if (me == 0) {
data[0].loc = 0;
data[0].val = 0;
}
MPI_Win_fence(0, win);
/* 3.b. Large array test */
if (me == nproc - 1) {
MPI_Accumulate(mine_plus, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_MAXLOC, win);
MPI_Accumulate(mine, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
verify_result(data, ARRAY_LEN, expected[0], "Large array test case for MAXLOC and REPLACE");
}
/* Test MINLOC */
if (me == 0) {
for (i = 0; i < ARRAY_LEN; i++) {
data[i].loc = INT_MAX;
data[i].val = INT_MAX;
}
}
MPI_Win_fence(0, win);
/* Rank np-1 performs 2 WRITE to rank 0. */
/* 3.c. Single data test */
if (me == nproc - 1) {
MPI_Accumulate(mine_plus, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
expected[0].loc = nproc - 1;
expected[0].val = nproc;
verify_result(data, 1, expected[0], "Single data test case for REPLACE and MINLOC");
}
if (me == 0) {
data[0].loc = INT_MAX;
data[0].val = INT_MAX;
}
MPI_Win_fence(0, win);
/* 3.d. Large array test */
if (me == nproc - 1) {
MPI_Accumulate(mine_plus, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_REPLACE, win);
MPI_Accumulate(mine, ARRAY_LEN, MPI_2INT, 0, 0, ARRAY_LEN, MPI_2INT, MPI_MINLOC, win);
}
MPI_Win_fence(0, win);
if (me == 0) {
verify_result(data, ARRAY_LEN, expected[0], "Single data test case for REPLACE and MINLOC");
}
MPI_Win_free(&win);
if (me == nproc - 1) {
free(mine);
free(mine_plus);
}
if (me == 0)
free(expected);
MTest_Finalize(errs);
free(data);
return MTestReturnValue(errs);
}
|