Blame test/mpi/rma/test1_dt.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
#include "mpi.h"
Packit 0848f5
#include "stdio.h"
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include "squelch.h"
Packit 0848f5
Packit 0848f5
/* tests a series of puts, gets, and accumulate on 2 processes using fence */
Packit 0848f5
/* Same as test1.c but uses derived datatypes to receive data */
Packit 0848f5
Packit 0848f5
#define SIZE 100
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int rank, nprocs, A[SIZE], B[SIZE], i;
Packit 0848f5
    MPI_Comm CommDeuce;
Packit 0848f5
    MPI_Win win;
Packit 0848f5
    MPI_Datatype contig_2ints;
Packit 0848f5
    int errs = 0;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
Packit 0848f5
    if (nprocs < 2) {
Packit 0848f5
        printf("Run this program with 2 or more processes\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
Packit 0848f5
Packit 0848f5
    if (rank < 2) {
Packit 0848f5
Packit 0848f5
        if (rank == 0) {
Packit 0848f5
            for (i = 0; i < SIZE; i++)
Packit 0848f5
                A[i] = B[i] = i;
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            for (i = 0; i < SIZE; i++) {
Packit 0848f5
                A[i] = (-3) * i;
Packit 0848f5
                B[i] = (-4) * i;
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Type_contiguous(2, MPI_INT, &contig_2ints);
Packit 0848f5
        MPI_Type_commit(&contig_2ints);
Packit 0848f5
Packit 0848f5
        MPI_Win_create(B, SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
Packit 0848f5
Packit 0848f5
        MPI_Win_fence(0, win);
Packit 0848f5
Packit 0848f5
        if (rank == 0) {
Packit 0848f5
            for (i = 0; i < SIZE - 2; i += 2)
Packit 0848f5
                MPI_Put(A + i, 2, MPI_INT, 1, i, 1, contig_2ints, win);
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            for (i = 0; i < SIZE - 2; i += 2)
Packit 0848f5
                MPI_Get(A + i, 2, MPI_INT, 0, i, 1, contig_2ints, win);
Packit 0848f5
Packit 0848f5
            MPI_Accumulate(A + SIZE - 2, 2, MPI_INT, 0, SIZE - 2, 1, contig_2ints, MPI_SUM, win);
Packit 0848f5
        }
Packit 0848f5
        MPI_Win_fence(0, win);
Packit 0848f5
Packit 0848f5
        if (rank == 1) {
Packit 0848f5
            for (i = 0; i < SIZE - 2; i++) {
Packit 0848f5
                if (A[i] != B[i]) {
Packit 0848f5
                    SQUELCH(printf("Put/Get Error: A[i]=%d, B[i]=%d\n", A[i], B[i]););
Packit 0848f5
                    errs++;
Packit 0848f5
                }
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            if (B[SIZE - 1] != SIZE - 1 - 3 * (SIZE - 1)) {
Packit 0848f5
                SQUELCH(printf
Packit 0848f5
                        ("Accumulate Error: B[SIZE-1] is %d, should be %d\n", B[SIZE - 1],
Packit 0848f5
                         SIZE - 1 - 3 * (SIZE - 1)););
Packit 0848f5
                errs++;
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Win_free(&win);
Packit 0848f5
        MPI_Type_free(&contig_2ints);
Packit 0848f5
    }
Packit 0848f5
    MPI_Comm_free(&CommDeuce);
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}