views:

113

answers:

1

Hi, I am trying to implement bitonic sorting using MPI for 2^n processors.

I would like to use an n-dimensional hypercube to do so for convenience. Using MPI_Cart_Create I can create self-organising dimensions. Doing so will maximize efficiency of my process and also reduce the number of LOC I have to spit to get it done..

Googling AND the litterature always tell the same thing:

Note that an n -dimensional hypercube is an n -dimensional torus with 2 processes per coordinate direction. Thus, special support for hypercube structures is not necessary.

I haven’t seen any single example + n -dimensional torus with 2 processes per coordinate direction seems nothing but mystery to me. Would anyone have to suggest?

Thanks,

+1  A: 

Well, found it

so that would be for a 4-d hypercube.. The pattern is pretty straight-forward. In n-dimensional hypercube each point have N neighbour and they are represented in this code. Note that this code should used instead of xoring bit mask because MPI can re-order the processes to fit the physical layout of your clusters.

int rank, size; //I am process RANK and we are a total of SIZE
MPI_Init(&argc, &argv); 

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

myFairShareOfNumber = totalNumber / size;

MPI_Comm nthCube;
int nDim=4;
int processPerDim [4]= {2,2,2,2};
int period [4]= {1,1,1,1};

MPI_Cart_create(MPI_COMM_WORLD, nDim, processPerDim, period, true, &nthCube);

int rankInDim;
MPI_Comm_rank(nthCube, &rankInDim);

int rank_source, rank_desta, rank_destb, rank_destc, rank_destd;
MPI_Cart_shift(nthCube, 0,1,&rank_source, &rank_desta);
MPI_Cart_shift(nthCube, 1,1,&rank_source, &rank_destb);
MPI_Cart_shift(nthCube, 2,1,&rank_source, &rank_destc);
MPI_Cart_shift(nthCube, 3,1,&rank_source, &rank_destd);
cerr << "I am known in the world as " << rankInDim << " my adjacents are -> " << rank_desta << "-" << rank_destb << "-" << rank_destc << "-" << rank_destd <<"\n";
matdumsa