Blame test/mpi/comm/ic1.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2001 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
 * A simple test of the intercomm create routine, with a communication test
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    MPI_Comm intercomm;
Packit 0848f5
    int remote_rank, rank, size, errs = 0;
Packit 0848f5
    volatile int trigger;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    trigger = 1;
Packit 0848f5
/*    while (trigger) ; */
Packit 0848f5
Packit 0848f5
    MPI_Comm_size(MPI_COMM_WORLD, &size);
Packit 0848f5
    if (size < 2) {
Packit 0848f5
        printf("Size must be at least 2\n");
Packit 0848f5
        MPI_Abort(MPI_COMM_WORLD, 0);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
Packit 0848f5
Packit 0848f5
    /* Make an intercomm of the first two elements of comm_world */
Packit 0848f5
    if (rank < 2) {
Packit 0848f5
        int lrank = rank, rrank = -1;
Packit 0848f5
        MPI_Status status;
Packit 0848f5
Packit 0848f5
        remote_rank = 1 - rank;
Packit 0848f5
        MPI_Intercomm_create(MPI_COMM_SELF, 0, MPI_COMM_WORLD, remote_rank, 27, &intercomm);
Packit 0848f5
Packit 0848f5
        /* Now, communicate between them */
Packit 0848f5
        MPI_Sendrecv(&lrank, 1, MPI_INT, 0, 13, &rrank, 1, MPI_INT, 0, 13, intercomm, &status);
Packit 0848f5
Packit 0848f5
        if (rrank != remote_rank) {
Packit 0848f5
            errs++;
Packit 0848f5
            printf("%d Expected %d but received %d\n", rank, remote_rank, rrank);
Packit 0848f5
        }
Packit 0848f5
Packit 0848f5
        MPI_Comm_free(&intercomm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* The next test should create an intercomm with groups of different
Packit 0848f5
     * sizes FIXME */
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}