Allink  v0.1
SingProc.h
1 #ifndef SINGPROC_H
2 #define SINGPROC_H
3 #ifdef USE_MPI
4 #include <mpi.h>
6 class SingProc{
7  private:
8  int *Dim;
9  int *Period;
10  int *Remain;
11  int *PCoord;
12  public:
13  SingProc(int ExtSize,int ExtRank){
14  Rank = ExtRank;
15  Size = ExtSize;
16  NDim = 1;
17  Dim = (int *)calloc(NDim,sizeof(int));
18  Period = (int *)calloc(NDim,sizeof(int));
19  Remain = (int *)calloc(NDim,sizeof(int));
20  PCoord = (int *)calloc(NDim,sizeof(int));
21  Dim[0] = Size;
22  Period[0] = 1;
23  MPI_Cart_create(MPI_COMM_WORLD, NDim, Dim, Period, 1, &CommGrid);
24  Remain[0] = 1;
25  MPI_Cart_sub(CommGrid,Remain,&CommRow);
26  Remain[0] = 0;
27  MPI_Cart_sub(CommGrid,Remain,&CommCol);
28  MPI_Cart_coords(CommGrid,Rank,NDim,PCoord);
29  Col = PCoord[0];
30  Row = 0;
31  //printf("Proc num %d di %d in (%d,%d)\n",Rank,Size,Row,Col);
32  }
33  SingProc(int ExtSize,int ExtRank,int ExtNRow,int ExtNCol){
34  Rank = ExtRank;
35  Size = ExtSize;
36  NDim = 2;
37  Dim = (int *)calloc(NDim,sizeof(int));
38  Period = (int *)calloc(NDim,sizeof(int));
39  Remain = (int *)calloc(NDim,sizeof(int));
40  PCoord = (int *)calloc(NDim,sizeof(int));
41  Dim[0] = ExtNRow; Dim[1] = ExtNCol;
42  Period[0] = 0;Period[0] = 0;
43  //if(NRow*NCol != Size){printf("The number of processor must be a square of a number: n^2\n");exit(0);}
44  MPI_Cart_create(MPI_COMM_WORLD, NDim, Dim, Period, 1, &CommGrid);
45  Remain[0] = 1;Remain[1] = 0;
46  MPI_Cart_sub(CommGrid,Remain,&CommRow);
47  Remain[0] = 0;Remain[1] = 1;
48  MPI_Cart_sub(CommGrid,Remain,&CommCol);
49  MPI_Cart_coords(CommGrid,Rank,NDim,PCoord);
50  Row=PCoord[0];
51  Col=PCoord[1];
52  // printf("Proc num %d di %d in (%d,%d)\n",Rank,Size,Row,Col);
53  }
54  int Rank;
55  int Size;
56  MPI_Comm CommGrid;
57  MPI_Comm CommRow;
58  MPI_Comm CommCol;
59  int Col;
60  int Row;
61  int NDim;
62 };
63 #endif//USE_MPI
64 
65 #endif//SINGPROC
Basics class to start a MPI grid.
Definition: SingProc.h:6