Blame test/mpi/rma/contig_displ.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2001 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <mpi.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
/* Run with 1 process.
Packit 0848f5
Packit 0848f5
   This program does an MPI_Get with an indexed datatype. The datatype
Packit 0848f5
   comprises a single integer at an initial displacement of 1 integer.
Packit 0848f5
   That is, the first integer in the array is to be skipped.
Packit 0848f5
Packit 0848f5
   This program found a bug in IBM's MPI in which MPI_Get ignored the
Packit 0848f5
   displacement and got the first integer instead of the second.
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    int rank, nprocs, mpi_err, *array;
Packit 0848f5
    int getval, disp, errs = 0;
Packit 0848f5
    MPI_Win win;
Packit 0848f5
    MPI_Datatype type;
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, &nprocs);
Packit 0848f5
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        /* To improve reporting of problems about operations, we
Packit 0848f5
         * change the error handler to errors return */
Packit 0848f5
        MPI_Comm_set_errhandler(MPI_COMM_SELF, MPI_ERRORS_RETURN);
Packit 0848f5
Packit 0848f5
        /* create an indexed datatype that points to the second integer
Packit 0848f5
         * in an array (the first integer is skipped). */
Packit 0848f5
        disp = 1;
Packit 0848f5
        mpi_err = MPI_Type_create_indexed_block(1, 1, &disp, MPI_INT, &type);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
        mpi_err = MPI_Type_commit(&type);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        /* allocate window of size 2 integers */
Packit 0848f5
        mpi_err = MPI_Alloc_mem(2 * sizeof(int), MPI_INFO_NULL, &array);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        /* create window object */
Packit 0848f5
        mpi_err =
Packit 0848f5
            MPI_Win_create(array, 2 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &win);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        /* initialize array */
Packit 0848f5
        array[0] = 100;
Packit 0848f5
        array[1] = 200;
Packit 0848f5
Packit 0848f5
        getval = 0;
Packit 0848f5
Packit 0848f5
        /* To improve reporting of problems about operations, we
Packit 0848f5
         * change the error handler to errors return */
Packit 0848f5
        MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
Packit 0848f5
Packit 0848f5
        mpi_err = MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        /* get the current value of element array[1] */
Packit 0848f5
        mpi_err = MPI_Get(&getval, 1, MPI_INT, 0, 0, 1, type, win);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        mpi_err = MPI_Win_unlock(0, win);
Packit 0848f5
        if (mpi_err != MPI_SUCCESS)
Packit 0848f5
            goto err_return;
Packit 0848f5
Packit 0848f5
        /* getval should contain the value of array[1] */
Packit 0848f5
        if (getval != array[1]) {
Packit 0848f5
            errs++;
Packit 0848f5
            printf("getval=%d, should be %d\n", getval, array[1]);
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Free_mem(array);
Packit 0848f5
        MPI_Win_free(&win);
Packit 0848f5
        MPI_Type_free(&type);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
Packit 0848f5
  err_return:
Packit 0848f5
    printf("MPI function error returned an error\n");
Packit 0848f5
    MTestPrintError(mpi_err);
Packit 0848f5
    errs++;
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 1;
Packit 0848f5
}