MPI 中的条件广播

发布于 2025-01-20 06:12:25 字数 313 浏览 3 评论 0原文

我想编写一个MPI程序,每个过程都有一个布尔值启动最初设置为false。然后,排名0检查大型2D布尔数组的值(ij)是正确的 ture。如果启动的等级0的值是正确的,那么我希望等级0将启动的新值广播到其他过程,间接告诉他们每个过程以启动另一种方法的执行。

我该如何有效地做到这一点?很高兴听到任何想法。

- 谢谢

PS。我考虑过将2D布尔数组发送到每个过程,但是在某些情况下,2D阵列可以非常很大,我担心我的代码不会很好地扩展。

I want to write an MPI Program where each process has a boolean value initiate which is initially set to false. Then, rank 0 checks if the value (i,j) of a large 2D Boolean Array is true and if it is then rank 0 sets its value of initiate to true. If rank 0's value of initiate is true then I would like rank 0 to broadcast the new value of initiate to other processes, indirectly telling each of them to kickstart execution of another method.

How could I go about doing this efficiently? Would appreciate to hear any ideas.

-Thanks

PS. I considered sending the 2d boolean array to every process, but that 2d array can be very big under certain circumstances and I am worried that my code would not scale well.

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

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

发布评论

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

评论(1

清浅ˋ旧时光 2025-01-27 06:12:25

我假设您想利用等待时间。详细阐述 Gilles Gouaillardet 的评论,您可以构建一种“中断”类型的结构。

bool initiate = false;

if (rank == 0)
  for(int k = 0; k < I * J; k++)
    if(!bool_arr[k]) {
      initiate = true;
      break;
    }

MPI_Request request;
MPI_Ibcast(&initiate, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD, &request);

for (int iter = 0; iter < numiter; iter++) {

    ; // DO WHATEVER YOU WANT!

    // TEST IF THE BROADCAST COMPLETE ONCE IN A WHILE
    bool complete;
    MPI_Test(&request, &complete, MPI_STATUS_IGNORE);
    if (complete && initiate) {
      function();
      initiate = false; // Avoid calling function() twice
    }
}
// DO NOT MOVE ON WITHOUT WAITING FOR BROADCAST
MPI_Wait(&request, MPI_STATUS_IGNORE);
if (initiate)
  function();

I assume you want to make use of the wait time. Elaborating on Gilles Gouaillardet's comment, you can build an "interrupt" kind of structure.

bool initiate = false;

if (rank == 0)
  for(int k = 0; k < I * J; k++)
    if(!bool_arr[k]) {
      initiate = true;
      break;
    }

MPI_Request request;
MPI_Ibcast(&initiate, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD, &request);

for (int iter = 0; iter < numiter; iter++) {

    ; // DO WHATEVER YOU WANT!

    // TEST IF THE BROADCAST COMPLETE ONCE IN A WHILE
    bool complete;
    MPI_Test(&request, &complete, MPI_STATUS_IGNORE);
    if (complete && initiate) {
      function();
      initiate = false; // Avoid calling function() twice
    }
}
// DO NOT MOVE ON WITHOUT WAITING FOR BROADCAST
MPI_Wait(&request, MPI_STATUS_IGNORE);
if (initiate)
  function();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文