Blame test/mpi/comm/cmsplit.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2003 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 comm split";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int rank, size, color, srank;
Packit 0848f5
    MPI_Comm comm, scomm;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    MPI_Comm_dup(MPI_COMM_WORLD, &comm);
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(comm, &rank;;
Packit 0848f5
    MPI_Comm_size(comm, &size);
Packit 0848f5
Packit 0848f5
    if (size < 4) {
Packit 0848f5
        fprintf(stderr, "This test requires at least four processes.");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 1);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    color = MPI_UNDEFINED;
Packit 0848f5
    if (rank < 2)
Packit 0848f5
        color = 1;
Packit 0848f5
    MPI_Comm_split(comm, color, size - rank, &scomm);
Packit 0848f5
Packit 0848f5
    if (rank < 2) {
Packit 0848f5
        /* Check that the ranks are ordered correctly */
Packit 0848f5
        MPI_Comm_rank(scomm, &srank);
Packit 0848f5
        if (srank != 1 - rank) {
Packit 0848f5
            errs++;
Packit 0848f5
        }
Packit 0848f5
        MPI_Comm_free(&scomm);
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
        if (scomm != MPI_COMM_NULL) {
Packit 0848f5
            errs++;
Packit 0848f5
        }
Packit 0848f5
    }
Packit 0848f5
    MPI_Comm_free(&comm);
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}