3

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,

matdumsa
  • 16,005
  • 1
  • 22
  • 18

1 Answers1

7

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
  • 16,005
  • 1
  • 22
  • 18
  • mmm nice work, i have task with cube and i should make process communication between vertexes . I tried to use MPI_Sendrecv() but it does't work, in your task did you have communication? – Sergey Nov 07 '10 at 22:36
  • 1
    MPI_Cart_shift(nthCube, nDim-1-s,1,&rank_source, &rank_dest); – matdumsa Nov 08 '10 at 16:48
  • in nDim-1-s - what means s, and it is correct to use MPI_Sendrecv() because may be locking – Sergey Nov 09 '10 at 15:53
  • I would also be interested in a quick explanation of how MPI_Cart_shift works in your code. This definitely looks like the correct way to implement a hypercube, but I am still learning and some more info would be very helpful. – C. Zach Martin Sep 26 '13 at 19:53
  • found what I needed here: http://www.mcs.anl.gov/research/projects/mpi/tutorial/gropp/node64.html#Node64 – C. Zach Martin Sep 26 '13 at 20:17