Blame test/mpi/comm/comm_create_group.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2011 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include "mpitestconf.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <string.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <assert.h>
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int size, rank, i, *excl;
Packit 0848f5
    MPI_Group world_group, even_group;
Packit 0848f5
    MPI_Comm even_comm;
Packit 0848f5
Packit 0848f5
    MPI_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
Packit 0848f5
    if (size % 2) {
Packit 0848f5
        fprintf(stderr, "this program requires a multiple of 2 number of processes\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    excl = malloc((size / 2) * sizeof(int));
Packit 0848f5
    assert(excl);
Packit 0848f5
Packit 0848f5
    /* exclude the odd ranks */
Packit 0848f5
    for (i = 0; i < size / 2; i++)
Packit 0848f5
        excl[i] = (2 * i) + 1;
Packit 0848f5
Packit 0848f5
    /* Create some groups */
Packit 0848f5
    MPI_Comm_group(MPI_COMM_WORLD, &world_group);
Packit 0848f5
    MPI_Group_excl(world_group, size / 2, excl, &even_group);
Packit 0848f5
    MPI_Group_free(&world_group);
Packit 0848f5
Packit 0848f5
    if (rank % 2 == 0) {
Packit 0848f5
        /* Even processes create a group for themselves */
Packit 0848f5
        MPI_Comm_create_group(MPI_COMM_WORLD, even_group, 0, &even_comm);
Packit 0848f5
        MPI_Barrier(even_comm);
Packit 0848f5
        MPI_Comm_free(&even_comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Group_free(&even_group);
Packit 0848f5
    MPI_Barrier(MPI_COMM_WORLD);
Packit 0848f5
Packit 0848f5
    if (rank == 0)
Packit 0848f5
        printf(" No errors\n");
Packit 0848f5
Packit 0848f5
    free(excl);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}