Blame test/mpi/ft/revoke_shrink.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2014 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <stdbool.h>
Packit 0848f5
#include <string.h>
Packit 0848f5
#include <unistd.h>
Packit 0848f5
#include "mpi.h"
Packit 0848f5
Packit 0848f5
MPI_Comm comm_all;
Packit 0848f5
Packit 0848f5
void error_handler(MPI_Comm * communicator, int *error_code, ...)
Packit 0848f5
{
Packit 0848f5
    MPI_Comm *new_comm = malloc(sizeof(MPI_Comm));
Packit 0848f5
Packit 0848f5
    MPIX_Comm_revoke(comm_all);
Packit 0848f5
    MPIX_Comm_shrink(comm_all, new_comm);
Packit 0848f5
Packit 0848f5
    MPI_Comm_free(&comm_all);
Packit 0848f5
Packit 0848f5
    comm_all = *new_comm;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int rank, size, i;
Packit 0848f5
    int sum = 0, val = 1;
Packit 0848f5
    int errs = 0;
Packit 0848f5
    MPI_Errhandler errhandler;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
Packit 0848f5
    if (size < 4) {
Packit 0848f5
        fprintf(stderr, "Must run with at least 4 processes.\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Comm_dup(MPI_COMM_WORLD, &comm_all);
Packit 0848f5
Packit 0848f5
    MPI_Comm_create_errhandler(&error_handler, &errhandler);
Packit 0848f5
    MPI_Comm_set_errhandler(comm_all, errhandler);
Packit 0848f5
Packit 0848f5
    for (i = 0; i < 10; ++i) {
Packit 0848f5
        MPI_Comm_size(comm_all, &size);
Packit 0848f5
        sum = 0;
Packit 0848f5
        if (i == 5 && rank == 1) {
Packit 0848f5
            exit(1);
Packit 0848f5
        }
Packit 0848f5
        else if (i != 5) {
Packit 0848f5
            MPI_Allreduce(&val, &sum, 1, MPI_INT, MPI_SUM, comm_all);
Packit 0848f5
            if (sum != size && rank == 0) {
Packit 0848f5
                errs++;
Packit 0848f5
                fprintf(stderr, "Incorrect answer: %d != %d\n", sum, size);
Packit 0848f5
            }
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (0 == rank && errs) {
Packit 0848f5
        fprintf(stdout, " Found %d errors\n", errs);
Packit 0848f5
    }
Packit 0848f5
    else if (0 == rank) {
Packit 0848f5
        fprintf(stdout, " No errors\n");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Comm_free(&comm_all);
Packit 0848f5
    MPI_Errhandler_free(&errhandler);
Packit 0848f5
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}