Blame test/mpi/errors/coll/noalias.c

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
#include <stdio.h>
Packit Service c5cf8c
#include <stdlib.h>
Packit Service c5cf8c
#include "mpi.h"
Packit Service c5cf8c
#include "mpitest.h"
Packit Service c5cf8c
#include "mpicolltest.h"
Packit Service c5cf8c
Packit Service c5cf8c
int main(int argc, char *argv[])
Packit Service c5cf8c
{
Packit Service c5cf8c
    int err, errs = 0, len, i;
Packit Service c5cf8c
    int rank = -1, size = -1;
Packit Service c5cf8c
    int *buf;
Packit Service c5cf8c
    int *recvbuf;
Packit Service c5cf8c
    char msg[MPI_MAX_ERROR_STRING];
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Init(&argc, &argv);
Packit Service c5cf8c
    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit Service c5cf8c
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit Service c5cf8c
Packit Service c5cf8c
    buf = malloc(size * sizeof(int));
Packit Service c5cf8c
    recvbuf = malloc(size * sizeof(int));
Packit Service c5cf8c
    for (i = 0; i < size; ++i) {
Packit Service c5cf8c
        buf[i] = i;
Packit Service c5cf8c
        recvbuf[i] = -1;
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    err = MTest_Allreduce(buf, buf, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
Packit Service c5cf8c
    if (!err) {
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
        if (rank == 0)
Packit Service c5cf8c
            printf("Did not detect aliased arguments in MPI_Allreduce\n");
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        /* Check that we can get a message for this error */
Packit Service c5cf8c
        /* (This works if it does not SEGV or hang) */
Packit Service c5cf8c
        MPI_Error_string(err, msg, &len;;
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* This case is a bit stranger than the MPI_Allreduce case above, because
Packit Service c5cf8c
     * the recvbuf argument is only relevant at the root.  So without an extra
Packit Service c5cf8c
     * communication step to return errors everywhere, it will be typical for
Packit Service c5cf8c
     * rank 0 (the root) to return an error and all other ranks will return
Packit Service c5cf8c
     * MPI_SUCCESS.  In many implementations this can leave the non-root
Packit Service c5cf8c
     * processes hung or yield unmatched unexpected messages on the root.  So we
Packit Service c5cf8c
     * do our best to carry on in this case by posting a second non-erroneous
Packit Service c5cf8c
     * MPI_Reduce on any process that got back an error from the intentionally
Packit Service c5cf8c
     * erroneous MPI_Reduce. */
Packit Service c5cf8c
    err = MTest_Reduce(buf, ((rank == 0) ? buf : NULL), 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        if (!err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            if (rank == 0)
Packit Service c5cf8c
                printf("Did not detect aliased arguments in MPI_Reduce\n");
Packit Service c5cf8c
        } else {
Packit Service c5cf8c
            /* Check that we can get a message for this error */
Packit Service c5cf8c
            /* (This works if it does not SEGV or hang) */
Packit Service c5cf8c
            MPI_Error_string(err, msg, &len;;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (err) {
Packit Service c5cf8c
        /* post a correct MPI_Reduce on any processes that got an error earlier */
Packit Service c5cf8c
        err = MTest_Reduce(buf, recvbuf, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
        if (err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            printf("make-up reduce failed on rank %d\n", rank);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* this case should _not_ trigger an error, thanks to Kenneth Inghram for
Packit Service c5cf8c
     * reporting this bug in MPICH */
Packit Service c5cf8c
    err =
Packit Service c5cf8c
        MTest_Reduce(((rank == 0) ? MPI_IN_PLACE : buf), buf, 1, MPI_INT, MPI_SUM, 0,
Packit Service c5cf8c
                     MPI_COMM_WORLD);
Packit Service c5cf8c
    if (err) {
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
        printf
Packit Service c5cf8c
            ("Incorrectly reported aliased arguments in MPI_Reduce with MPI_IN_PLACE on rank %d\n",
Packit Service c5cf8c
             rank);
Packit Service c5cf8c
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit Service c5cf8c
        printf("FAILED TO MPI_ABORT!!!\n");
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* check for aliasing detection in MPI_Gather (tt#1006) */
Packit Service c5cf8c
    err = MTest_Gather(buf, 1, MPI_INT, buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        if (!err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            printf("Did not detect aliased arguments in MPI_Gather\n");
Packit Service c5cf8c
        } else {
Packit Service c5cf8c
            /* Check that we can get a message for this error */
Packit Service c5cf8c
            /* (This works if it does not SEGV or hang) */
Packit Service c5cf8c
            MPI_Error_string(err, msg, &len;;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (err) {
Packit Service c5cf8c
        /* post a correct MPI_Gather on any processes that got an error earlier */
Packit Service c5cf8c
        err = MTest_Gather(buf, 1, MPI_INT, recvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
        if (err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            printf("make-up gather failed on rank %d\n", rank);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* check for aliasing detection in MPI_Scatter (tt#1006) */
Packit Service c5cf8c
    err = MPI_Scatter(buf, 1, MPI_INT, buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        if (!err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            printf("Did not detect aliased arguments in MPI_Scatter\n");
Packit Service c5cf8c
        } else {
Packit Service c5cf8c
            /* Check that we can get a message for this error */
Packit Service c5cf8c
            /* (This works if it does not SEGV or hang) */
Packit Service c5cf8c
            MPI_Error_string(err, msg, &len;;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
    if (err) {
Packit Service c5cf8c
        /* post a correct MPI_Scatter on any processes that got an error earlier */
Packit Service c5cf8c
        err = MPI_Scatter(buf, 1, MPI_INT, recvbuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
        if (err) {
Packit Service c5cf8c
            errs++;
Packit Service c5cf8c
            printf("make-up scatter failed on rank %d\n", rank);
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    free(recvbuf);
Packit Service c5cf8c
    free(buf);
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Finalize(errs);
Packit Service c5cf8c
    return MTestReturnValue(errs);
Packit Service c5cf8c
}