Blame test/mpi/rma/strided_getacc_indexed.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2001 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* One-Sided MPI 2-D Strided Accumulate Test
Packit 0848f5
 *
Packit 0848f5
 * Author: James Dinan <dinan@mcs.anl.gov>
Packit 0848f5
 * Date  : December, 2010
Packit 0848f5
 *
Packit 0848f5
 * This code performs N strided put operations followed by get operations into
Packit 0848f5
 * a 2d patch of a shared array.  The array has dimensions [X, Y] and the
Packit 0848f5
 * subarray has dimensions [SUB_X, SUB_Y] and begins at index [0, 0].  The
Packit 0848f5
 * input and output buffers are specified using an MPI indexed type.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <math.h>
Packit 0848f5
#include <mpi.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include "squelch.h"
Packit 0848f5
Packit 0848f5
#define XDIM 8
Packit 0848f5
#define YDIM 1024
Packit 0848f5
#define SUB_XDIM 1
Packit 0848f5
#define SUB_YDIM 2
Packit 0848f5
#define ITERATIONS 10
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int i, j, rank, nranks, peer, bufsize, errors;
Packit 0848f5
    double *win_buf, *src_buf, *dst_buf;
Packit 0848f5
    MPI_Win buf_win;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &nranks);
Packit 0848f5
Packit 0848f5
    bufsize = XDIM * YDIM * sizeof(double);
Packit 0848f5
    MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &win_buf);
Packit 0848f5
    MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &src_buf);
Packit 0848f5
    MPI_Alloc_mem(bufsize, MPI_INFO_NULL, &dst_buf);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < XDIM * YDIM; i++) {
Packit 0848f5
        *(win_buf + i) = -1.0;
Packit 0848f5
        *(src_buf + i) = 1.0 + rank;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Win_create(win_buf, bufsize, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &buf_win);
Packit 0848f5
Packit 0848f5
    peer = (rank + 1) % nranks;
Packit 0848f5
Packit 0848f5
    /* Perform ITERATIONS strided accumulate operations */
Packit 0848f5
Packit 0848f5
    for (i = 0; i < ITERATIONS; i++) {
Packit 0848f5
        int idx_rem[SUB_YDIM];
Packit 0848f5
        int blk_len[SUB_YDIM];
Packit 0848f5
        MPI_Datatype src_type, dst_type;
Packit 0848f5
Packit 0848f5
        for (j = 0; j < SUB_YDIM; j++) {
Packit 0848f5
            idx_rem[j] = j * XDIM;
Packit 0848f5
            blk_len[j] = SUB_XDIM;
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &src_type);
Packit 0848f5
        MPI_Type_indexed(SUB_YDIM, blk_len, idx_rem, MPI_DOUBLE, &dst_type);
Packit 0848f5
Packit 0848f5
        MPI_Type_commit(&src_type);
Packit 0848f5
        MPI_Type_commit(&dst_type);
Packit 0848f5
Packit 0848f5
        /* PUT */
Packit 0848f5
        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
Packit 0848f5
        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
Packit 0848f5
                           1, dst_type, MPI_REPLACE, buf_win);
Packit 0848f5
        MPI_Win_unlock(peer, buf_win);
Packit 0848f5
Packit 0848f5
        /* GET */
Packit 0848f5
        MPI_Win_lock(MPI_LOCK_EXCLUSIVE, peer, 0, buf_win);
Packit 0848f5
        MPI_Get_accumulate(src_buf, 1, src_type, dst_buf, 1, src_type, peer, 0,
Packit 0848f5
                           1, dst_type, MPI_NO_OP, buf_win);
Packit 0848f5
        MPI_Win_unlock(peer, buf_win);
Packit 0848f5
Packit 0848f5
        MPI_Type_free(&src_type);
Packit 0848f5
        MPI_Type_free(&dst_type);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    /* Verify that the results are correct */
Packit 0848f5
Packit 0848f5
    MPI_Win_lock(MPI_LOCK_EXCLUSIVE, rank, 0, buf_win);
Packit 0848f5
    errors = 0;
Packit 0848f5
    for (i = 0; i < SUB_XDIM; i++) {
Packit 0848f5
        for (j = 0; j < SUB_YDIM; j++) {
Packit 0848f5
            const double actual = *(win_buf + i + j * XDIM);
Packit 0848f5
            const double expected = (1.0 + ((rank + nranks - 1) % nranks));
Packit 0848f5
            if (fabs(actual - expected) > 1.0e-10) {
Packit 0848f5
                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
Packit 0848f5
                               rank, j, i, expected, actual););
Packit 0848f5
                errors++;
Packit 0848f5
                fflush(stdout);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    for (i = SUB_XDIM; i < XDIM; i++) {
Packit 0848f5
        for (j = 0; j < SUB_YDIM; j++) {
Packit 0848f5
            const double actual = *(win_buf + i + j * XDIM);
Packit 0848f5
            const double expected = -1.0;
Packit 0848f5
            if (fabs(actual - expected) > 1.0e-10) {
Packit 0848f5
                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
Packit 0848f5
                               rank, j, i, expected, actual););
Packit 0848f5
                errors++;
Packit 0848f5
                fflush(stdout);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    for (i = 0; i < XDIM; i++) {
Packit 0848f5
        for (j = SUB_YDIM; j < YDIM; j++) {
Packit 0848f5
            const double actual = *(win_buf + i + j * XDIM);
Packit 0848f5
            const double expected = -1.0;
Packit 0848f5
            if (fabs(actual - expected) > 1.0e-10) {
Packit 0848f5
                SQUELCH(printf("%d: Data validation failed at [%d, %d] expected=%f actual=%f\n",
Packit 0848f5
                               rank, j, i, expected, actual););
Packit 0848f5
                errors++;
Packit 0848f5
                fflush(stdout);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    MPI_Win_unlock(rank, buf_win);
Packit 0848f5
Packit 0848f5
    MPI_Win_free(&buf_win);
Packit 0848f5
    MPI_Free_mem(win_buf);
Packit 0848f5
    MPI_Free_mem(src_buf);
Packit 0848f5
    MPI_Free_mem(dst_buf);
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errors);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return MTestReturnValue(errors);
Packit 0848f5
}