Blame test/mpi/comm/ic2.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2012 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/* regression test for ticket #1574
Packit 0848f5
 *
Packit 0848f5
 * Based on test code from N. Radclif @ Cray. */
Packit 0848f5
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <mpi.h>
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    MPI_Comm c0, c1, ic;
Packit 0848f5
    MPI_Group g0, g1, gworld;
Packit 0848f5
    int a, b, c, d;
Packit 0848f5
    int rank, size, remote_leader, tag;
Packit 0848f5
    int ranks[2];
Packit 0848f5
    int errs = 0;
Packit 0848f5
Packit 0848f5
    tag = 5;
Packit 0848f5
    c0 = c1 = ic = MPI_COMM_NULL;
Packit 0848f5
    g0 = g1 = gworld = MPI_GROUP_NULL;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
Packit 0848f5
    if (size < 33) {
Packit 0848f5
        printf("ERROR: this test requires at least 33 processes\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
        return 1;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* group of c0
Packit 0848f5
     * NOTE: a>=32 is essential for exercising the loop bounds bug from tt#1574 */
Packit 0848f5
    a = 32;
Packit 0848f5
    b = 24;
Packit 0848f5
Packit 0848f5
    /* group of c1 */
Packit 0848f5
    c = 25;
Packit 0848f5
    d = 26;
Packit 0848f5
Packit 0848f5
    MPI_Comm_group(MPI_COMM_WORLD, &gworld);
Packit 0848f5
Packit 0848f5
    ranks[0] = a;
Packit 0848f5
    ranks[1] = b;
Packit 0848f5
    MPI_Group_incl(gworld, 2, ranks, &g0;;
Packit 0848f5
    MPI_Comm_create(MPI_COMM_WORLD, g0, &c0;;
Packit 0848f5
Packit 0848f5
    ranks[0] = c;
Packit 0848f5
    ranks[1] = d;
Packit 0848f5
    MPI_Group_incl(gworld, 2, ranks, &g1;;
Packit 0848f5
    MPI_Comm_create(MPI_COMM_WORLD, g1, &c1;;
Packit 0848f5
Packit 0848f5
    if (rank == a || rank == b) {
Packit 0848f5
        remote_leader = c;
Packit 0848f5
        MPI_Intercomm_create(c0, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
Packit 0848f5
    }
Packit 0848f5
    else if (rank == c || rank == d) {
Packit 0848f5
        remote_leader = a;
Packit 0848f5
        MPI_Intercomm_create(c1, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Group_free(&g0;;
Packit 0848f5
    MPI_Group_free(&g1;;
Packit 0848f5
    MPI_Group_free(&gworld);
Packit 0848f5
Packit 0848f5
    if (c0 != MPI_COMM_NULL)
Packit 0848f5
        MPI_Comm_free(&c0;;
Packit 0848f5
    if (c1 != MPI_COMM_NULL)
Packit 0848f5
        MPI_Comm_free(&c1;;
Packit 0848f5
    if (ic != MPI_COMM_NULL)
Packit 0848f5
        MPI_Comm_free(&ic);
Packit 0848f5
Packit 0848f5
Packit 0848f5
    MPI_Reduce((rank == 0 ? MPI_IN_PLACE : &errs), &errs, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
Packit 0848f5
    if (rank == 0) {
Packit 0848f5
        if (errs) {
Packit 0848f5
            printf("found %d errors\n", errs);
Packit 0848f5
        }
Packit 0848f5
        else {
Packit 0848f5
            printf(" No errors\n");
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}