Create Row Group
MPI_Group group_world, first_row_group;
int *process_ranks, my_rank_in_first_row;
/* Make a list of the processes in the new communicator */
q = (int) sqrt((double) p);
process_ranks = (int*) malloc(q*sizeof(int));
for (proc = 0; proc < q; proc++) {process_ranks[proc] = proc;}
/* Get the group underlying MPI_COMM_WORLD, Create the new group+communicator*/
MPI_Comm_group(MPI_COMM_WORLD, &group_world);
MPI_Group_incl(group_world, q, process_ranks, &first_row_group);
MPI_Comm_create(MPI_COMM_WORLD, first_row_group, &first_row_comm);
/* Now check whether we can do collective ops in first_row_comm */
MPI_Comm_rank(first_row_comm, &my_rank_in_first_row);
if (my_rank_in_first_row == 0) test = 1;
MPI_Bcast(&test, 1, MPI_INT, 0, first_row_comm);
MPI_Reduce(&test, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
if (!my_rank_in_first_row == 0) {printf("q = %d, sum = %d\n", q, sum);}