|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* One-Sided MPI 2-D Strided Put Test
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* Author: James Dinan <dinan@mcs.anl.gov>
|
|
Packit Service |
c5cf8c |
* Date : March, 2011
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* This code performs N strided put operations into a 2d patch of a shared
|
|
Packit Service |
c5cf8c |
* array. The array has dimensions [X, Y] and the subarray has dimensions
|
|
Packit Service |
c5cf8c |
* [SUB_X, SUB_Y] and begins at index [0, 0]. The input and output buffers are
|
|
Packit Service |
c5cf8c |
* specified using an MPI datatype.
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* This test generates a datatype that is relative to an arbitrary base address
|
|
Packit Service |
c5cf8c |
* in memory and tests the RMA implementation's ability to perform the correct
|
|
Packit Service |
c5cf8c |
* transfer.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <stdint.h>
|
|
Packit Service |
c5cf8c |
#include <mpi.h>
|
|
Packit Service |
c5cf8c |
#include "mpitest.h"
|
|
Packit Service |
c5cf8c |
#include "squelch.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define XDIM 1024
|
|
Packit Service |
c5cf8c |
#define YDIM 1024
|
|
Packit Service |
c5cf8c |
#define SUB_XDIM 1024
|
|
Packit Service |
c5cf8c |
#define SUB_YDIM 1024
|
|
Packit Service |
c5cf8c |
#define ITERATIONS 10
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, j, rank, nranks, peer, bufsize, errs;
|
|
Packit Service |
c5cf8c |
double *win_buf, *src_buf, *dst_buf;
|
|
Packit Service |
c5cf8c |
MPI_Win buf_win;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &nranks);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
bufsize = XDIM * YDIM * sizeof(double);
|
|
Packit Service |
c5cf8c |
MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
|
|
Packit Service |
c5cf8c |
/* Alloc_mem is not required for the origin buffers for RMA operations -
|
|
Packit Service |
c5cf8c |
* just for the Win_create memory */
|
|
Packit Service |
c5cf8c |
MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
|
|
Packit Service |
c5cf8c |
MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < XDIM * YDIM; i++) {
|
|
Packit Service |
c5cf8c |
*(win_buf + i) = 1.0 + rank;
|
|
Packit Service |
c5cf8c |
*(src_buf + i) = 1.0 + rank;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
peer = (rank + 1) % nranks;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Perform ITERATIONS strided put operations */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < ITERATIONS; i++) {
|
|
Packit Service |
c5cf8c |
MPI_Aint idx_loc[SUB_YDIM];
|
|
Packit Service |
c5cf8c |
int idx_rem[SUB_YDIM];
|
|
Packit Service |
c5cf8c |
int blk_len[SUB_YDIM];
|
|
Packit Service |
c5cf8c |
MPI_Datatype src_type, dst_type;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
void *base_ptr = dst_buf;
|
|
Packit Service |
c5cf8c |
MPI_Aint base_int;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Get_address(base_ptr, &base_int);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (j = 0; j < SUB_YDIM; j++) {
|
|
Packit Service |
c5cf8c |
MPI_Get_address(&src_buf[j * XDIM], &idx_loc[j]);
|
|
Packit Service |
c5cf8c |
idx_loc[j] = idx_loc[j] - base_int;
|
|
Packit Service |
c5cf8c |
idx_rem[j] = j * XDIM * sizeof(double);
|
|
Packit Service |
c5cf8c |
blk_len[j] = SUB_XDIM * sizeof(double);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_create_hindexed(SUB_YDIM, blk_len, idx_loc, MPI_BYTE, &src_type);
|
|
Packit Service |
c5cf8c |
MPI_Type_create_indexed_block(SUB_YDIM, SUB_XDIM * sizeof(double), idx_rem, MPI_BYTE,
|
|
Packit Service |
c5cf8c |
&dst_type);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&src_type);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&dst_type);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
|
|
Packit Service |
c5cf8c |
MPI_Put(base_ptr, 1, src_type, peer, 0, 1, dst_type, buf_win);
|
|
Packit Service |
c5cf8c |
MPI_Win_unlock(peer, buf_win);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&src_type);
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&dst_type);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Verify that the results are correct */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
|
|
Packit Service |
c5cf8c |
errs = 0;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < SUB_XDIM; i++) {
|
|
Packit Service |
c5cf8c |
for (j = 0; j < SUB_YDIM; j++) {
|
|
Packit Service |
c5cf8c |
const double actual = *(win_buf + i + j * XDIM);
|
|
Packit Service |
c5cf8c |
const double expected = (1.0 + ((rank + nranks - 1) % nranks));
|
|
Packit Service |
c5cf8c |
if (actual - expected > 1e-10) {
|
|
Packit Service |
c5cf8c |
SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
|
|
Packit Service |
c5cf8c |
rank, j, i, expected, actual););
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = SUB_XDIM; i < XDIM; i++) {
|
|
Packit Service |
c5cf8c |
for (j = 0; j < SUB_YDIM; j++) {
|
|
Packit Service |
c5cf8c |
const double actual = *(win_buf + i + j * XDIM);
|
|
Packit Service |
c5cf8c |
const double expected = 1.0 + rank;
|
|
Packit Service |
c5cf8c |
if (actual - expected > 1e-10) {
|
|
Packit Service |
c5cf8c |
SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
|
|
Packit Service |
c5cf8c |
rank, j, i, expected, actual););
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
for (i = 0; i < XDIM; i++) {
|
|
Packit Service |
c5cf8c |
for (j = SUB_YDIM; j < YDIM; j++) {
|
|
Packit Service |
c5cf8c |
const double actual = *(win_buf + i + j * XDIM);
|
|
Packit Service |
c5cf8c |
const double expected = 1.0 + rank;
|
|
Packit Service |
c5cf8c |
if (actual - expected > 1e-10) {
|
|
Packit Service |
c5cf8c |
SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
|
|
Packit Service |
c5cf8c |
rank, j, i, expected, actual););
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fflush(stdout);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Win_unlock(rank, buf_win);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Win_free(&buf_win);
|
|
Packit Service |
c5cf8c |
MPI_Free_mem(win_buf);
|
|
Packit Service |
c5cf8c |
MPI_Free_mem(src_buf);
|
|
Packit Service |
c5cf8c |
MPI_Free_mem(dst_buf);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MTest_Finalize(errs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return MTestReturnValue(errs);
|
|
Packit Service |
c5cf8c |
}
|