Blame test/mpi/errors/faults/collf1.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2009 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 <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test survivability from faults with collective communication";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int wrank, wsize, rank, size, color;
Packit 0848f5
    int tmp;
Packit 0848f5
    MPI_Comm newcomm;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &wsize);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
Packit 0848f5
Packit 0848f5
    /* Color is 0 or 1; 1 will be the processes that "fault" */
Packit 0848f5
    color = (wrank > 0) && (wrank <= wsize / 2);
Packit 0848f5
    MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &newcomm);
Packit 0848f5
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
    if (color) {
Packit 0848f5
        /* Simulate a fault on some processes */
Packit 0848f5
        exit(1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* Can we still use newcomm? */
Packit 0848f5
    MPI_Comm_size(newcomm, &size);
Packit 0848f5
    MPI_Comm_rank(newcomm, &rank;;
Packit 0848f5
Packit 0848f5
    MPI_Allreduce(&rank, &tmp, 1, MPI_INT, MPI_SUM, newcomm);
Packit 0848f5
    if (tmp != (size * (size + 1)) / 2) {
Packit 0848f5
        printf("Allreduce gave %d but expected %d\n", tmp, (size * (size + 1)) / 2);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Comm_free(&newcomm);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    printf(" No Errors\n");
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}