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

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2006 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
#include "mpicolltest.h"
Packit 0848f5
Packit 0848f5
/* Very simple test that Bcast handled mismatched lengths (while not a
Packit 0848f5
   common user error, we've seen it several times, so good handling of
Packit 0848f5
   this helps to reduce bug reports)
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int verbose = 0;
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int buf[10], ierr, errs = 0;
Packit 0848f5
    int rank;
Packit 0848f5
    char str[MPI_MAX_ERROR_STRING + 1];
Packit 0848f5
    int slen;
Packit 0848f5
Packit 0848f5
    MTEST_VG_MEM_INIT(buf, 10 * sizeof(int));
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        ierr = MTest_Bcast(buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        ierr = MTest_Bcast(buf, 10, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
    if (ierr == MPI_SUCCESS) {
Packit 0848f5
        if (rank != 0) {
Packit 0848f5
            /* The root process may not detect that a too-long buffer
Packit 0848f5
             * was provided by the non-root processes, but those processes
Packit 0848f5
             * should detect this. */
Packit 0848f5
            errs++;
Packit 0848f5
            printf("Did not detect mismatched length (long) on process %d\n", rank);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        if (verbose) {
Packit 0848f5
            MPI_Error_string(ierr, str, &slen);
Packit 0848f5
            printf("Found expected error; message is: %s\n", str);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        ierr = MTest_Bcast(buf, 10, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        ierr = MTest_Bcast(buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
Packit 0848f5
    }
Packit 0848f5
    if (ierr == MPI_SUCCESS) {
Packit 0848f5
        if (rank != 0) {
Packit 0848f5
            /* The root process may not detect that a too-short buffer
Packit 0848f5
             * was provided by the non-root processes, but those processes
Packit 0848f5
             * should detect this. */
Packit 0848f5
            errs++;
Packit 0848f5
            printf("Did not detect mismatched length (short) on process %d\n", rank);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        if (verbose) {
Packit 0848f5
            MPI_Error_string(ierr, str, &slen);
Packit 0848f5
            printf("Found expected error; message is: %s\n", str);
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_ARE_FATAL);
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}