如何使用 MPI_CART 将流程映射到超立方体

发布于 2024-08-24 07:39:39 字数 435 浏览 9 评论 0原文

我正在尝试使用 MPI 为 2^n 处理器实现双调排序。

为了方便起见,我想使用 n 维 hypercube 来这样做。使用 MPI_Cart_Create 我可以创建自组织维度。这样做将最大限度地提高我的流程效率,并减少我必须吐出的 LOC 数量才能完成它。

谷歌搜索和文献总是告诉我们同样的事情:

请注意,n 维超立方体 是一个 n 维环面,其中 2 每个坐标方向的进程。 因此,对超立方体的特殊支持 结构不是必需的。

我还没有看到任何单个示例 + 每个坐标方向有 2 个进程的 n 维环面,这对我来说似乎只是神秘。有人需要建议吗?

谢谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2024-08-31 07:39:39

嗯,找到了,

这将是一个 4 维超立方体。这个模式非常简单。在 n 维超立方体中,每个点都有 N 个邻居,它们在此代码中表示。请注意,应使用此代码而不是异或位掩码,因为 MPI 可以重新排序进程以适应集群的物理布局。

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";

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文