Frage

I have a 16 processes and each process is randomizing a number.

I created a cartesian topology for the processes and now I know what are the coordinates of each rank (process).

I wonder where is the "matrix", how can I get the value of each process in the cartesian topolgy?

here is the code:

int dim[2],period[2],coord[2],reorder,myValue;
dim[0] = 4; dim[1] = 4;
period[0] = 1; period[1] = 0;
reorder = 1;
myValue = rand() % 100 + 1;

MPI_Cart_create(MPI_COMM_WORLD,2,dim,period,reorder,&comm);

if (rank == 0) // root
{
    //prints the coordinates of each process , i = process rank
            for (int i = 0 ; i < DIM*DIM; i++)
    {
        MPI_Cart_coords(comm,i,2,coord);
        cout << coord[0] << coord[1] << i  << endl;
    }
}
War es hilfreich?

Lösung

There is no matrix. It's just a convention that makes arguing about the processes that are left, right, above and below easier to understand.

If you want to get the coordinates for the current process you already have the code. Just put in rank, instead of i.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top