|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2015 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* This test is going to test atomic GET (GACC/FOP+MPI_NO_OP).
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* There are totally three processes involved in this test. Both
|
|
Packit |
0848f5 |
* rank 1 and rank 2 issue RMA operations to rank 0. Rank 2 issues
|
|
Packit |
0848f5 |
* atomic PUT (ACC+MPI_REPLACE), whereas rank 1 issues atomic
|
|
Packit |
0848f5 |
* GET (GACC/FOP+MPI_NO_OP). The datatype used in the test is
|
|
Packit |
0848f5 |
* pair-type. The initial value of pair-type data in origin buffer
|
|
Packit |
0848f5 |
* of atomic PUT is set so that the two basic values equal with
|
|
Packit |
0848f5 |
* each other. Due to the atomicity of GET, the expected resulting
|
|
Packit |
0848f5 |
* data should also have equivalent basic values. */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#define LOOP 100
|
|
Packit |
0848f5 |
#define DATA_SIZE 100
|
|
Packit |
0848f5 |
#define OPS_NUM 10000
|
|
Packit |
0848f5 |
#define GACC_SZ 10
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
typedef struct pair_struct {
|
|
Packit |
0848f5 |
long double a;
|
|
Packit |
0848f5 |
int b;
|
|
Packit |
0848f5 |
} pair_struct_t;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int rank, nproc;
|
|
Packit |
0848f5 |
int i, j, k;
|
|
Packit |
0848f5 |
int errors = 0, curr_errors = 0;
|
|
Packit |
0848f5 |
MPI_Win win;
|
|
Packit |
0848f5 |
pair_struct_t *tar_buf = NULL;
|
|
Packit |
0848f5 |
pair_struct_t *orig_buf = NULL;
|
|
Packit |
0848f5 |
pair_struct_t *result_buf = NULL;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* This test needs to work with 3 processes. */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
|
|
Packit |
0848f5 |
MPI_Alloc_mem(sizeof(pair_struct_t) * DATA_SIZE, MPI_INFO_NULL, &result_buf);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_allocate(sizeof(pair_struct_t) * DATA_SIZE, sizeof(pair_struct_t),
|
|
Packit |
0848f5 |
MPI_INFO_NULL, MPI_COMM_WORLD, &tar_buf, &win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (j = 0; j < LOOP * 6; j++) {
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* initialize data */
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE; i++) {
|
|
Packit |
0848f5 |
tar_buf[i].a = 0.0;
|
|
Packit |
0848f5 |
tar_buf[i].b = 0;
|
|
Packit |
0848f5 |
result_buf[i].a = 0.0;
|
|
Packit |
0848f5 |
result_buf[i].b = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_unlock(rank, win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_fence(0, win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == 2) {
|
|
Packit |
0848f5 |
if (j < 2 * LOOP) {
|
|
Packit |
0848f5 |
/* Work with FOP test (Test #1 to Test #2) */
|
|
Packit |
0848f5 |
for (i = 0; i < OPS_NUM; i++) {
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int curr_val = j * OPS_NUM + i;
|
|
Packit |
0848f5 |
orig_buf[0].a = (long double) (curr_val);
|
|
Packit |
0848f5 |
orig_buf[0].b = curr_val;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Accumulate(orig_buf, 1, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, 1, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Work with GACC test (Test #3 to Test #6) */
|
|
Packit |
0848f5 |
for (i = 0; i < OPS_NUM / GACC_SZ; i++) {
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (k = 0; k < GACC_SZ; k++) {
|
|
Packit |
0848f5 |
int curr_val = j * OPS_NUM + i * GACC_SZ + k;
|
|
Packit |
0848f5 |
orig_buf[k].a = (long double) (curr_val);
|
|
Packit |
0848f5 |
orig_buf[k].b = curr_val;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_REPLACE, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (rank == 1) {
|
|
Packit |
0848f5 |
/* equals to an atomic GET */
|
|
Packit |
0848f5 |
if (j < LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE; i++) {
|
|
Packit |
0848f5 |
/* Test #1: FOP + MPI_NO_OP */
|
|
Packit |
0848f5 |
MPI_Fetch_and_op(orig_buf, &(result_buf[i]), MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (j < 2 * LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE; i++) {
|
|
Packit |
0848f5 |
/* Test #2: FOP + MPI_NO_OP + NULL origin buffer address */
|
|
Packit |
0848f5 |
MPI_Fetch_and_op(NULL, &(result_buf[i]), MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (j < 3 * LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
|
|
Packit |
0848f5 |
/* Test #3: GACC + MPI_NO_OP */
|
|
Packit |
0848f5 |
MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
&(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (j < 4 * LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
|
|
Packit |
0848f5 |
/* Test #4: GACC + MPI_NO_OP + NULL origin buffer address */
|
|
Packit |
0848f5 |
MPI_Get_accumulate(NULL, GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
&(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (j < 5 * LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
|
|
Packit |
0848f5 |
/* Test #5: GACC + MPI_NO_OP + zero origin count */
|
|
Packit |
0848f5 |
MPI_Get_accumulate(orig_buf, 0, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
&(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else if (j < 6 * LOOP) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE / GACC_SZ; i++) {
|
|
Packit |
0848f5 |
/* Test #5: GACC + MPI_NO_OP + NULL origin datatype */
|
|
Packit |
0848f5 |
MPI_Get_accumulate(orig_buf, GACC_SZ, MPI_DATATYPE_NULL,
|
|
Packit |
0848f5 |
&(result_buf[i * GACC_SZ]), GACC_SZ, MPI_LONG_DOUBLE_INT,
|
|
Packit |
0848f5 |
0, 0, GACC_SZ, MPI_LONG_DOUBLE_INT, MPI_NO_OP, win);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_fence(0, win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* check results */
|
|
Packit |
0848f5 |
if (rank == 1) {
|
|
Packit |
0848f5 |
for (i = 0; i < DATA_SIZE; i++) {
|
|
Packit |
0848f5 |
if (result_buf[i].a != (long double) (result_buf[i].b)) {
|
|
Packit |
0848f5 |
if (curr_errors < 10) {
|
|
Packit |
0848f5 |
printf("LOOP %d: result_buf[%d].a = %Lf, result_buf[%d].b = %d\n",
|
|
Packit |
0848f5 |
j, i, result_buf[i].a, i, result_buf[i].b);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
curr_errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (j % LOOP == 0) {
|
|
Packit |
0848f5 |
errors += curr_errors;
|
|
Packit |
0848f5 |
curr_errors = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_free(&win);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Free_mem(orig_buf);
|
|
Packit |
0848f5 |
MPI_Free_mem(result_buf);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == 1) {
|
|
Packit |
0848f5 |
if (errors == 0)
|
|
Packit |
0848f5 |
printf(" No Errors\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|