当变量用作源时,MPI_RECV 接收 0 值,但当源编号被硬编码时,MPI_RECV 接收正确的值

发布于 2024-09-17 06:29:42 字数 757 浏览 4 评论 0原文

我正在尝试从作为 DO 循环的一部分处理的多个变量接收变量。然而,如果我用变量来表示处理器编号,则运算后变量的值为0。如果我直接输入处理器编号就可以了。奇怪的是,完全相同的代码在程序的早期运行良好。对我的问题有什么想法吗?

  DO s = 1,numproc-1,1
        CALL MPI_RECV( numZERO, 1, MPI_INTEGER, s, 1, MPI_COMM_WORLD, status, ierr )
        WRITE(*,*)'s',s,'numZERO',numZERO
  END DO

给出:

  s   1   numZERO   0
  s   2   numZERO   0 ...

当它被编码时:

  CALL MPI_RECV( numZERO, 1, MPI_INTEGER, 1, 1, MPI_COMM_WORLD, status, ierr )
  WRITE(*,*)'1 numZERO',numZERO
  CALL MPI_RECV( numZERO, 1, MPI_INTEGER, 2, 1, MPI_COMM_WORLD, status, ierr )
  WRITE(*,*)'2 numZERO',numZERO

我得到

  1 numZERO   1
  2 numZERO   2 ...

s 是一个整数。

I am trying to receive a variable from multiple processed as part of a DO loop. However, the value of the variable is 0 after the operation if I use a variable to represent the processor number. It works fine if I put the processor number in directly. Oddly enough, the exact same code works fine earlier in the program. Any thoughts on my problem?

  DO s = 1,numproc-1,1
        CALL MPI_RECV( numZERO, 1, MPI_INTEGER, s, 1, MPI_COMM_WORLD, status, ierr )
        WRITE(*,*)'s',s,'numZERO',numZERO
  END DO

gives:

  s   1   numZERO   0
  s   2   numZERO   0 ...

when it is coded:

  CALL MPI_RECV( numZERO, 1, MPI_INTEGER, 1, 1, MPI_COMM_WORLD, status, ierr )
  WRITE(*,*)'1 numZERO',numZERO
  CALL MPI_RECV( numZERO, 1, MPI_INTEGER, 2, 1, MPI_COMM_WORLD, status, ierr )
  WRITE(*,*)'2 numZERO',numZERO

I get

  1 numZERO   1
  2 numZERO   2 ...

s is an integer.

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

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

发布评论

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

评论(1

溺孤伤于心 2024-09-24 06:29:43

“ierr”将毫无用处。默认情况下,Fortran MPI 实现不会返回任何内容。他们知道你不会检查它,所以作者用错误轰炸而不是传递一些有用的东西。您可以请求 MPI 返回错误。

您可以检查“状态”,因为这在极少数情况下很有用。

“S”应该是一个合适大小的整数(通常是整数*4)。这就是我所认为的全部错误。

"ierr" is going to be useless. Fortran MPI implementations don't return anything there by default. They understand that you are not going to check it, so the writers bomb with an error rather than passing something useful. You can request that MPI return errors.

You might check the "status" because that on very rare occasions is useful.

"S" should be an integer of the right size (integer*4 usually). That is all that I could think is wrong.

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