我有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;
}
}
没有矩阵。这只是一种惯例,使关于左、右、上、下过程的争论更容易理解。
如果您想获得当前流程的坐标,您已经有了代码。只是放在排名中,而不是i。