0

我有 16 个进程,每个进程都在随机化一个数字。

我为进程创建了笛卡尔拓扑,现在我知道每个等级(进程)的坐标是什么。

我想知道“矩阵”在哪里,如何获得笛卡尔拓扑中每个进程的值?

这是代码:

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;
    }
}
4

1 回答 1

1

没有矩阵。这只是一种约定,使争论左、右、上和下的过程更容易理解。

如果你想获得当前进程的坐标,你已经有了代码。只需输入排名,而不是 i。

于 2013-12-04T13:29:16.060 回答