|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* (C) 2013 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <mpi.h>
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char **argv)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int i, rank, size, color;
|
|
Packit |
0848f5 |
MPI_Group group;
|
|
Packit |
0848f5 |
MPI_Comm primary[2], secondary[2], tmp;
|
|
Packit |
0848f5 |
MPI_Request req[2];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Each pair of processes creates a communicator */
|
|
Packit |
0848f5 |
for (i = 0; i < size; i++) {
|
|
Packit |
0848f5 |
if (rank == i)
|
|
Packit |
0848f5 |
MPI_Comm_split(MPI_COMM_WORLD, 0, 0, &primary[0]);
|
|
Packit |
0848f5 |
else if (rank == (i + 1) % size)
|
|
Packit |
0848f5 |
MPI_Comm_split(MPI_COMM_WORLD, 0, 0, &secondary[0]);
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
MPI_Comm_split(MPI_COMM_WORLD, 1, 0, &tmp);
|
|
Packit |
0848f5 |
MPI_Comm_free(&tmp);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Each pair dups the communicator such that the dups are
|
|
Packit |
0848f5 |
* overlapping. If this were done with MPI_Comm_dup, this should
|
|
Packit |
0848f5 |
* deadlock. */
|
|
Packit |
0848f5 |
MPI_Comm_idup(primary[0], &primary[1], &req[0]);
|
|
Packit |
0848f5 |
MPI_Comm_idup(secondary[0], &secondary[1], &req[1]);
|
|
Packit |
0848f5 |
MPI_Waitall(2, req, MPI_STATUSES_IGNORE);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
for (i = 0; i < 2; i++) {
|
|
Packit |
0848f5 |
MPI_Comm_free(&primary[i]);
|
|
Packit |
0848f5 |
MPI_Comm_free(&secondary[i]);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == 0)
|
|
Packit |
0848f5 |
printf(" No Errors\n");
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|