|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2007 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 |
* This program tests that MPI_Comm_split applies to intercommunicators;
|
|
Packit |
0848f5 |
* this is an extension added in MPI-2
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int errs = 0;
|
|
Packit |
0848f5 |
int size, isLeft;
|
|
Packit |
0848f5 |
MPI_Comm intercomm, newcomm;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
if (size < 4) {
|
|
Packit |
0848f5 |
printf("This test requires at least 4 processes\n");
|
|
Packit |
0848f5 |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
while (MTestGetIntercomm(&intercomm, &isLeft, 2)) {
|
|
Packit |
0848f5 |
int key, color;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (intercomm == MPI_COMM_NULL)
|
|
Packit |
0848f5 |
continue;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Split this intercomm. The new intercomms contain the
|
|
Packit |
0848f5 |
* processes that had odd (resp even) rank in their local group
|
|
Packit |
0848f5 |
* in the original intercomm */
|
|
Packit |
0848f5 |
MTestPrintfMsg(1, "Created intercomm %s\n", MTestGetIntercommName());
|
|
Packit |
0848f5 |
MPI_Comm_rank(intercomm, &key);
|
|
Packit |
0848f5 |
color = (key % 2);
|
|
Packit |
0848f5 |
MPI_Comm_split(intercomm, color, key, &newcomm);
|
|
Packit |
0848f5 |
/* Make sure that the new communicator has the appropriate pieces */
|
|
Packit |
0848f5 |
if (newcomm != MPI_COMM_NULL) {
|
|
Packit |
0848f5 |
int orig_rsize, orig_size, new_rsize, new_size;
|
|
Packit |
0848f5 |
int predicted_size, flag, commok = 1;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_test_inter(intercomm, &flag;;
|
|
Packit |
0848f5 |
if (!flag) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Output communicator is not an intercomm\n");
|
|
Packit |
0848f5 |
commok = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Comm_remote_size(intercomm, &orig_rsize);
|
|
Packit |
0848f5 |
MPI_Comm_remote_size(newcomm, &new_rsize);
|
|
Packit |
0848f5 |
MPI_Comm_size(intercomm, &orig_size);
|
|
Packit |
0848f5 |
MPI_Comm_size(newcomm, &new_size);
|
|
Packit |
0848f5 |
/* The local size is 1/2 the original size, +1 if the
|
|
Packit |
0848f5 |
* size was odd and the color was even. More precisely,
|
|
Packit |
0848f5 |
* let n be the orig_size. Then
|
|
Packit |
0848f5 |
* color 0 color 1
|
|
Packit |
0848f5 |
* orig size even n/2 n/2
|
|
Packit |
0848f5 |
* orig size odd (n+1)/2 n/2
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* However, since these are integer valued, if n is even,
|
|
Packit |
0848f5 |
* then (n+1)/2 = n/2, so this table is much simpler:
|
|
Packit |
0848f5 |
* color 0 color 1
|
|
Packit |
0848f5 |
* orig size even (n+1)/2 n/2
|
|
Packit |
0848f5 |
* orig size odd (n+1)/2 n/2
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
predicted_size = (orig_size + !color) / 2;
|
|
Packit |
0848f5 |
if (predicted_size != new_size) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Predicted size = %d but found %d for %s (%d,%d)\n",
|
|
Packit |
0848f5 |
predicted_size, new_size, MTestGetIntercommName(), orig_size, orig_rsize);
|
|
Packit |
0848f5 |
commok = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
predicted_size = (orig_rsize + !color) / 2;
|
|
Packit |
0848f5 |
if (predicted_size != new_rsize) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Predicted remote size = %d but found %d for %s (%d,%d)\n",
|
|
Packit |
0848f5 |
predicted_size, new_rsize, MTestGetIntercommName(), orig_size, orig_rsize);
|
|
Packit |
0848f5 |
commok = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
/* ... more to do */
|
|
Packit |
0848f5 |
if (commok) {
|
|
Packit |
0848f5 |
errs += MTestTestComm(newcomm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
int orig_rsize;
|
|
Packit |
0848f5 |
/* If the newcomm is null, then this means that remote group
|
|
Packit |
0848f5 |
* for this color is of size zero (since all processes in this
|
|
Packit |
0848f5 |
* test have been given colors other than MPI_UNDEFINED).
|
|
Packit |
0848f5 |
* Confirm that here */
|
|
Packit |
0848f5 |
/* FIXME: ToDo */
|
|
Packit |
0848f5 |
MPI_Comm_remote_size(intercomm, &orig_rsize);
|
|
Packit |
0848f5 |
if (orig_rsize == 1) {
|
|
Packit |
0848f5 |
if (color == 0) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Returned null intercomm when non-null expected\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (newcomm != MPI_COMM_NULL)
|
|
Packit |
0848f5 |
MPI_Comm_free(&newcomm);
|
|
Packit |
0848f5 |
MPI_Comm_free(&intercomm);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MTest_Finalize(errs);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|