Blame test/mpi/ft/bcast.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *
Packit Service c5cf8c
 *  (C) 2003 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
#include "mpi.h"
Packit Service c5cf8c
#include <stdio.h>
Packit Service c5cf8c
#include <stdlib.h>
Packit Service c5cf8c
#include <string.h>
Packit Service c5cf8c
#include "mpitest.h"
Packit Service c5cf8c
Packit Service c5cf8c
/*
Packit Service c5cf8c
 * This test attempts collective bcast communication after a process in
Packit Service c5cf8c
 * the communicator has failed.
Packit Service c5cf8c
 */
Packit Service c5cf8c
int main(int argc, char **argv)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int rank, size, rc, errclass, toterrs, errs = 0;
Packit Service c5cf8c
    int deadprocs[] = { 1 };
Packit Service c5cf8c
    char buf[100000];
Packit Service c5cf8c
    MPI_Group world, newgroup;
Packit Service c5cf8c
    MPI_Comm newcomm;
Packit Service c5cf8c
Packit Service c5cf8c
    MTest_Init(&argc, &argv);
Packit Service c5cf8c
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit Service c5cf8c
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit Service c5cf8c
    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Comm_group(MPI_COMM_WORLD, &world);
Packit Service c5cf8c
    MPI_Group_excl(world, 1, deadprocs, &newgroup);
Packit Service c5cf8c
    MPI_Comm_create_group(MPI_COMM_WORLD, newgroup, 0, &newcomm);
Packit Service c5cf8c
Packit Service c5cf8c
    if (size < 3) {
Packit Service c5cf8c
        fprintf(stderr, "Must run with at least 3 processes\n");
Packit Service c5cf8c
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    if (rank == 1) {
Packit Service c5cf8c
        exit(EXIT_FAILURE);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    if (rank == 0) {
Packit Service c5cf8c
        strcpy(buf, "a1b2c3d4e");
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* do a small bcast first */
Packit Service c5cf8c
    rc = MPI_Bcast(buf, 10, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
Packit Service c5cf8c
#if defined (MPICH) && (MPICH_NUMVERSION >= 30100102)
Packit Service c5cf8c
    MPI_Error_class(rc, &errclass);
Packit Service c5cf8c
    if ((rc) && (errclass != MPIX_ERR_PROC_FAILED)) {
Packit Service c5cf8c
        fprintf(stderr, "Wrong error code (%d) returned. Expected MPIX_ERR_PROC_FAILED\n",
Packit Service c5cf8c
                errclass);
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
    /* reset the non-root buffers */
Packit Service c5cf8c
    if (rank != 0)
Packit Service c5cf8c
        memset(buf, 0, sizeof(buf));
Packit Service c5cf8c
Packit Service c5cf8c
    /* do a larger bcast */
Packit Service c5cf8c
    rc = MPI_Bcast(buf, 100000, MPI_CHAR, 0, MPI_COMM_WORLD);
Packit Service c5cf8c
Packit Service c5cf8c
#if defined (MPICH) && (MPICH_NUMVERSION >= 30100102)
Packit Service c5cf8c
    MPI_Error_class(rc, &errclass);
Packit Service c5cf8c
    if ((rc) && (errclass != MPIX_ERR_PROC_FAILED)) {
Packit Service c5cf8c
        fprintf(stderr, "Wrong error code (%d) returned. Expected MPIX_ERR_PROC_FAILED\n",
Packit Service c5cf8c
                errclass);
Packit Service c5cf8c
        errs++;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
    MPI_Group_free(&world);
Packit Service c5cf8c
    MPI_Group_free(&newgroup);
Packit Service c5cf8c
    MPI_Comm_free(&newcomm);
Packit Service c5cf8c
    MTest_Finalize(errs);
Packit Service c5cf8c
Packit Service c5cf8c
    return MTestReturnValue(errs);
Packit Service c5cf8c
}