/* *************************************************************************** C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example 2.8 : mpicpp-diag-comm.C Objective : Mpi program to create a communicator consisting of processors that lie on the diagonal in the square grid of processors, arranged in the form of a matrix Input : Communicator consisting of all the processors Condition : Number of Processes should be perfect square and less than 8. Created : August-2013 E-mail : hpcfte@cdac.in ***************************************************************************** */ #include #include #include //#include #include #include "mpi.h" using namespace std; int main(int argc,char *argv[]) { int index; int numprocs,myrank; int newnumprocs,newmyrank; int *process_rank,diag; MPI::Group groupworld,new_group; MPI::Intracomm group_diag; /* ....MPI Initialisation....*/ MPI::Init(argc, argv); numprocs = MPI::COMM_WORLD.Get_size(); myrank = MPI::COMM_WORLD.Get_rank(); /* Calculating no. of procs in new Comm..*/ diag = (int)sqrt((float)numprocs); /* Validation if no of procs in old comm is perfect square...*/ if(diag*diag != numprocs) { if(myrank == 0) cout<<"\n There should be square number of processors."<