MPI_Recv覆盖不应访问的部分内存 [英] MPI_Recv overwrites parts of memory it should not access
问题描述
在以下代码中,如果我没有将xysize
的值声明为参数(通常我不能这样做),则该值会更改.仅在优化-O2以及gfortran 4.7.2和OpenMPI 1.6中的其他情况下才会发生这种情况.这怎么可能?我找不到从mpi.mod
导入的确切接口,但是C原型清楚地指出count
是按值传递的,因此它不能更改.
In the following code the value of xysize
gets changed, if I do not declare it as a parameter (which I generally cannot do). It happens only with optimizations -O2 and more in gfortran 4.7.2 and OpenMPI 1.6. How is it possible? I cannot find the exact interface, that I import from mpi.mod
, but the C prototype clearly states that count
is passed by value, hence it cannot change.
write(*,*) im,"receiving from",image_index([iim,jim,kim+1]),"size",&
size(D%A(D%starti:D%endi,D%startj:D%endj,D%endk)),xysize
call MPI_RECV(D%A(D%starti:D%endi,D%startj:D%endj,D%endk+1),xysize , MPI_REAL, image_index([iim,jim,kim+1])-1,&
5000, comm, status, ierr)
write(*,*) im,"received size",&
size(D%A(D%starti:D%endi,D%startj:D%endj,D%endk)),xysize
输出:
1 receiving from 2 size 4096 4096
1 received size 4096 5000
推荐答案
为了将来的访问者,我想我会回答这个问题,即使上面的评论中都回答了这些问题.
For the sake of future visitors, I suppose I'll answer this even though it's all answered in the comments above.
据我所知,如果您的程序运行正常,则无法在对MPI_Recv
的调用中更改该参数的值(计数").
As far as I'm aware, if your program is behaving properly, you cannot change the value of that parameter ("count") in a call to MPI_Recv
.
您的参数status
太小,它应该是数组status(MPI_STATUS_SIZE)
,并且您会遇到缓冲区溢出-这通常会导致分段错误,但有时(取决于编译器如何打包)内存中的变量),它可能会导致类似这样的有趣行为.
Your argument status
is too small, it should be an array status(MPI_STATUS_SIZE)
, and you're getting a buffer overflow -- This often results in a segmentation fault, but at times (depending on how the compiler packed the variables in memory), it can result in funny behavior like this.
这篇关于MPI_Recv覆盖不应访问的部分内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!