Allink
v0.1
|
00001 #ifndef SINGPROC_H 00002 #define SINGPROC_H 00003 #ifdef USE_MPI 00004 #include <mpi.h> 00006 class SingProc{ 00007 private: 00008 int *Dim; 00009 int *Period; 00010 int *Remain; 00011 int *PCoord; 00012 public: 00013 SingProc(int ExtSize,int ExtRank){ 00014 Rank = ExtRank; 00015 Size = ExtSize; 00016 NDim = 1; 00017 Dim = (int *)calloc(NDim,sizeof(int)); 00018 Period = (int *)calloc(NDim,sizeof(int)); 00019 Remain = (int *)calloc(NDim,sizeof(int)); 00020 PCoord = (int *)calloc(NDim,sizeof(int)); 00021 Dim[0] = Size; 00022 Period[0] = 1; 00023 MPI_Cart_create(MPI_COMM_WORLD, NDim, Dim, Period, 1, &CommGrid); 00024 Remain[0] = 1; 00025 MPI_Cart_sub(CommGrid,Remain,&CommRow); 00026 Remain[0] = 0; 00027 MPI_Cart_sub(CommGrid,Remain,&CommCol); 00028 MPI_Cart_coords(CommGrid,Rank,NDim,PCoord); 00029 Col = PCoord[0]; 00030 Row = 0; 00031 //printf("Proc num %d di %d in (%d,%d)\n",Rank,Size,Row,Col); 00032 } 00033 SingProc(int ExtSize,int ExtRank,int ExtNRow,int ExtNCol){ 00034 Rank = ExtRank; 00035 Size = ExtSize; 00036 NDim = 2; 00037 Dim = (int *)calloc(NDim,sizeof(int)); 00038 Period = (int *)calloc(NDim,sizeof(int)); 00039 Remain = (int *)calloc(NDim,sizeof(int)); 00040 PCoord = (int *)calloc(NDim,sizeof(int)); 00041 Dim[0] = ExtNRow; Dim[1] = ExtNCol; 00042 Period[0] = 0;Period[0] = 0; 00043 //if(NRow*NCol != Size){printf("The number of processor must be a square of a number: n^2\n");exit(0);} 00044 MPI_Cart_create(MPI_COMM_WORLD, NDim, Dim, Period, 1, &CommGrid); 00045 Remain[0] = 1;Remain[1] = 0; 00046 MPI_Cart_sub(CommGrid,Remain,&CommRow); 00047 Remain[0] = 0;Remain[1] = 1; 00048 MPI_Cart_sub(CommGrid,Remain,&CommCol); 00049 MPI_Cart_coords(CommGrid,Rank,NDim,PCoord); 00050 Row=PCoord[0]; 00051 Col=PCoord[1]; 00052 // printf("Proc num %d di %d in (%d,%d)\n",Rank,Size,Row,Col); 00053 } 00054 int Rank; 00055 int Size; 00056 MPI_Comm CommGrid; 00057 MPI_Comm CommRow; 00058 MPI_Comm CommCol; 00059 int Col; 00060 int Row; 00061 int NDim; 00062 }; 00063 #endif//USE_MPI 00064 00065 #endif//SINGPROC