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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
/* This test is a simplification of the one in perf/manyrma.c that tests
for correct handling of the case where many RMA operations occur between
synchronization events.
This is one of the ways that RMA may be used, and is used in the
reference implementation of the graph500 benchmark.
*/
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpitest.h"
#define MAX_COUNT 65536*4/16
#define MAX_RMA_SIZE 2 /* 16 in manyrma performance test */
#define MAX_RUNS 8
#define MAX_ITER_TIME 5.0 /* seconds */
typedef enum { SYNC_NONE = 0,
SYNC_ALL = -1, SYNC_FENCE = 1, SYNC_LOCK = 2, SYNC_PSCW = 4
} sync_t;
typedef enum { RMA_NONE = 0, RMA_ALL = -1, RMA_PUT = 1, RMA_ACC = 2, RMA_GET = 4 } rma_t;
/* Note GET not yet implemented */
/* By default, run only a subset of the available tests, to keep the
total runtime reasonably short. Command line arguments may be used
to run other tests. */
sync_t syncChoice = SYNC_FENCE;
rma_t rmaChoice = RMA_ACC;
static int verbose = 0;
void RunAccFence(MPI_Win win, int destRank, int cnt, int sz);
void RunAccLock(MPI_Win win, int destRank, int cnt, int sz);
void RunPutFence(MPI_Win win, int destRank, int cnt, int sz);
void RunPutLock(MPI_Win win, int destRank, int cnt, int sz);
void RunAccPSCW(MPI_Win win, int destRank, int cnt, int sz,
MPI_Group exposureGroup, MPI_Group accessGroup);
void RunPutPSCW(MPI_Win win, int destRank, int cnt, int sz,
MPI_Group exposureGroup, MPI_Group accessGroup);
int main(int argc, char *argv[])
{
int arraysize, i, cnt, sz, maxCount = MAX_COUNT, *arraybuffer;
int wrank, wsize, destRank, srcRank;
MPI_Win win;
MPI_Group wgroup, accessGroup, exposureGroup;
int maxSz = MAX_RMA_SIZE;
double start, end;
MTest_Init(&argc, &argv);
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-put") == 0) {
if (rmaChoice == RMA_ALL)
rmaChoice = RMA_NONE;
rmaChoice |= RMA_PUT;
} else if (strcmp(argv[i], "-acc") == 0) {
if (rmaChoice == RMA_ALL)
rmaChoice = RMA_NONE;
rmaChoice |= RMA_ACC;
} else if (strcmp(argv[i], "-fence") == 0) {
if (syncChoice == SYNC_ALL)
syncChoice = SYNC_NONE;
syncChoice |= SYNC_FENCE;
} else if (strcmp(argv[i], "-lock") == 0) {
if (syncChoice == SYNC_ALL)
syncChoice = SYNC_NONE;
syncChoice |= SYNC_LOCK;
} else if (strcmp(argv[i], "-pscw") == 0) {
if (syncChoice == SYNC_ALL)
syncChoice = SYNC_NONE;
syncChoice |= SYNC_PSCW;
} else if (strcmp(argv[i], "-maxsz") == 0) {
i++;
maxSz = atoi(argv[i]);
} else if (strcmp(argv[i], "-maxcount") == 0) {
i++;
maxCount = atoi(argv[i]);
} else {
fprintf(stderr, "Unrecognized argument %s\n", argv[i]);
fprintf(stderr,
"%s [ -put ] [ -acc ] [ -lock ] [ -fence ] [ -pscw ] [ -maxsz msgsize ]\n",
argv[0]);
MPI_Abort(MPI_COMM_WORLD, 1);
}
}
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
destRank = wrank + 1;
while (destRank >= wsize)
destRank = destRank - wsize;
srcRank = wrank - 1;
if (srcRank < 0)
srcRank += wsize;
/* Create groups for PSCW */
MPI_Comm_group(MPI_COMM_WORLD, &wgroup);
MPI_Group_incl(wgroup, 1, &destRank, &accessGroup);
MPI_Group_incl(wgroup, 1, &srcRank, &exposureGroup);
MPI_Group_free(&wgroup);
arraysize = maxSz * MAX_COUNT;
#ifdef USE_WIN_ALLOCATE
MPI_Win_allocate(arraysize * sizeof(int), (int) sizeof(int), MPI_INFO_NULL,
MPI_COMM_WORLD, &arraybuffer, &win);
if (!arraybuffer) {
fprintf(stderr, "Unable to allocate %d words\n", arraysize);
MPI_Abort(MPI_COMM_WORLD, 1);
}
#else
arraybuffer = (int *) malloc(arraysize * sizeof(int));
if (!arraybuffer) {
fprintf(stderr, "Unable to allocate %d words\n", arraysize);
MPI_Abort(MPI_COMM_WORLD, 1);
}
MPI_Win_create(arraybuffer, arraysize * sizeof(int), (int) sizeof(int),
MPI_INFO_NULL, MPI_COMM_WORLD, &win);
#endif
if (maxCount > MAX_COUNT) {
fprintf(stderr, "MaxCount must not exceed %d\n", MAX_COUNT);
MPI_Abort(MPI_COMM_WORLD, 1);
}
if ((syncChoice & SYNC_FENCE) && (rmaChoice & RMA_ACC)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Accumulate with fence, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunAccFence(win, destRank, cnt, sz);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
if ((syncChoice & SYNC_LOCK) && (rmaChoice & RMA_ACC)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Accumulate with lock, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunAccLock(win, destRank, cnt, sz);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
if ((syncChoice & SYNC_FENCE) && (rmaChoice & RMA_PUT)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Put with fence, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunPutFence(win, destRank, cnt, sz);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
if ((syncChoice & SYNC_LOCK) && (rmaChoice & RMA_PUT)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Put with lock, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunPutLock(win, destRank, cnt, sz);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
if ((syncChoice & SYNC_PSCW) && (rmaChoice & RMA_PUT)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Put with pscw, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunPutPSCW(win, destRank, cnt, sz, exposureGroup, accessGroup);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
if ((syncChoice & SYNC_PSCW) && (rmaChoice & RMA_ACC)) {
for (sz = 1; sz <= maxSz; sz = sz + sz) {
if (wrank == 0 && verbose)
printf("Accumulate with pscw, %d elements\n", sz);
for (cnt = 1; cnt <= maxCount; cnt *= 2) {
start = MPI_Wtime();
RunAccPSCW(win, destRank, cnt, sz, exposureGroup, accessGroup);
end = MPI_Wtime();
if (end - start > MAX_ITER_TIME)
break;
}
}
}
MPI_Win_free(&win);
#ifndef USE_WIN_ALLOCATE
free(arraybuffer);
#endif
MPI_Group_free(&accessGroup);
MPI_Group_free(&exposureGroup);
MTest_Finalize(0);
return 0;
}
void RunAccFence(MPI_Win win, int destRank, int cnt, int sz)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (i = 0; i < sz; i++) {
buf[i] = i;
}
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_fence(0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Accumulate(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, MPI_SUM, win);
j += sz;
}
MPI_Win_fence(0, win);
}
free(buf);
}
void RunAccLock(MPI_Win win, int destRank, int cnt, int sz)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (i = 0; i < sz; i++) {
buf[i] = i;
}
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_lock(MPI_LOCK_SHARED, destRank, 0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Accumulate(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, MPI_SUM, win);
j += sz;
}
MPI_Win_unlock(destRank, win);
}
free(buf);
}
void RunPutFence(MPI_Win win, int destRank, int cnt, int sz)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_fence(0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Put(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, win);
j += sz;
}
MPI_Win_fence(0, win);
}
free(buf);
}
void RunPutLock(MPI_Win win, int destRank, int cnt, int sz)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_lock(MPI_LOCK_SHARED, destRank, 0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Put(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, win);
j += sz;
}
MPI_Win_unlock(destRank, win);
}
free(buf);
}
void RunPutPSCW(MPI_Win win, int destRank, int cnt, int sz,
MPI_Group exposureGroup, MPI_Group accessGroup)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_post(exposureGroup, 0, win);
MPI_Win_start(accessGroup, 0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Put(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, win);
j += sz;
}
MPI_Win_complete(win);
MPI_Win_wait(win);
}
free(buf);
}
void RunAccPSCW(MPI_Win win, int destRank, int cnt, int sz,
MPI_Group exposureGroup, MPI_Group accessGroup)
{
int k, i, j;
int *buf = malloc(sz * sizeof(int));
for (k = 0; k < MAX_RUNS; k++) {
MPI_Barrier(MPI_COMM_WORLD);
MPI_Win_post(exposureGroup, 0, win);
MPI_Win_start(accessGroup, 0, win);
j = 0;
for (i = 0; i < cnt; i++) {
MPI_Accumulate(buf, sz, MPI_INT, destRank, j, sz, MPI_INT, MPI_SUM, win);
j += sz;
}
MPI_Win_complete(win);
MPI_Win_wait(win);
}
free(buf);
}
|