#include #include int main(int argc, char* argv[]) { int rank; int context; char order; int nprow = 2, npcol = 2; MPI_Comm comm = MPI_COMM_WORLD; MPI_Comm subcomm; MPI_Group worldgroup, subgroup; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_group(comm, &worldgroup); // It works with this criterion //int criterion = (rank < 4); //int ranks1[4] = {0, 1, 2, 3}; //int ranks2[4] = {4, 5, 6, 7}; // It won't work with this criterion int criterion = (rank % 2 == 0); int ranks1[4] = {0, 2, 4, 6}; int ranks2[4] = {1, 3, 5, 7}; if(criterion){ MPI_Group_incl(worldgroup, 4, ranks1, &subgroup); } else { MPI_Group_incl(worldgroup, 4, ranks2, &subgroup); } MPI_Barrier(comm); MPI_Comm_create(comm, subgroup, &subcomm); if(criterion){ context = Csys2blacs_handle(subcomm); printf("rank=%d, context=%d\n", rank, context); fflush(stdout); MPI_Barrier(subcomm); // This call causes trouble. Apparently it cannot // create a grid with non-contiguous ranks // or ranks not starting with 0 Cblacs_gridinit(&context, &order, nprow, npcol); } MPI_Barrier(comm); printf("Hello, world! %d\n", rank); // won't happen fflush(stdout); MPI_Finalize(); return 0; }