我正在研究ScaLAPACK,并试图习惯使用ScaLAPACK所必需的BLACS例程。
我已经上过一些关于MPI的基础课程,所以对MPI_COMM_WORLD的东西有一些粗略的了解,但是对它的内部工作原理没有深入的了解,等等。
无论如何,我正在尝试使用BLACS例程来向您问好。
program hello_from_BLACS
use MPI
implicit none
integer :: info, nproc, nprow, npcol, &
myid, myrow, mycol, &
ctxt, ctxt_sys, ctxt_all
call BLACS_PINFO(myid, nproc)
! get the internal default context
call BLACS_GET(0, 0, ctxt_sys)
! set up a process grid for the process set
ctxt_all = ctxt_sys
call BLACS_GRIDINIT(ctxt_all, 'c', nproc, 1)
call BLACS_BARRIER(ctxt_all, 'A')
! set up a process grid of size 3*2
ctxt = ctxt_sys
call BLACS_GRIDINIT(ctxt, 'c', 3, 2)
if (myid .eq. 0) then
write(6,*) ' myid myrow mycol nprow npcol'
endif
(**) call BLACS_BARRIER(ctxt_sys, 'A')
! all processes not belonging to 'ctxt' jump to the end of the program
if (ctxt .lt. 0) goto 1000
! get the process coordinates in the grid
call BLACS_GRIDINFO(ctxt, nprow, npcol, myrow, mycol)
write(6,*) 'hello from process', myid, myrow, mycol, nprow, npcol
1000 continue
! return all BLACS contexts
call BLACS_EXIT(0)
stop
end program与'mpirun -np 10 ./exe‘的输出类似,
hello from process 0 0 0 3 2
hello from process 4 1 1 3 2
hello from process 1 1 0 3 2
myid myrow mycol nprow npcol
hello from process 5 2 1 3 2
hello from process 2 2 0 3 2
hello from process 3 0 1 3 2除了代码的左边标记(**)的'BLACS_BARRIER‘行之外,一切看起来都很好。
我把这一行放在输出下面,它的标题线总是打印在它的顶部。
myid myrow mycol nprow npcol
hello from process 0 0 0 3 2
hello from process 4 1 1 3 2
hello from process 1 1 0 3 2
hello from process 5 2 1 3 2
hello from process 2 2 0 3 2
hello from process 3 0 1 3 2所以问题是,
谢谢你阅读这个问题。
发布于 2020-05-09 07:49:58
回答你的两个问题(在未来最好是给出然后分开的帖子)
1) MPI_Barrier、BLACS_Barrier和我遇到的任何并行编程方法中的任何障碍都只同步调用它的实际进程集。然而,I/O并不仅仅是由调用进程处理的,而是至少在操作系统中处理一个,甚至更多,而操作系统实际上是I/O请求。这些不是由你们的屏障同步的。因此,I/O的排序不能通过简单的障碍来保证。我能想到的确保I/O排序的唯一标准一致性方法是
使用MPI /O。
2)你第二个打给BLACS_GRIDINIT的电话
call BLACS_GRIDINIT(ctxt, 'c', 3, 2)为3×2进程网格创建上下文,因此保持6个进程。如果您使用多个进程调用它,则只有6个进程将返回一个有效的上下文,因为其他的ctxt应该被视为一个未初始化的值。因此,例如,如果您用8个进程调用它,6将返回一个有效的ctxt,2将返回没有有效值的ctxt。如果这2现在尝试使用ctxt,那么任何事情都是可能的,而且在您的示例中,您将得到一个seg错误。你似乎看到了这是一个问题,因为你以后
! all processes not belonging to 'ctxt' jump to the end of the program
if (ctxt .lt. 0) goto 1000但是,我在BLACS_GRIDINIT的描述中没有看到任何能确保ctxt对于不参与进程的ctxt小于零的东西--在https://www.netlib.org/blacs/BLACS/QRef.html#BLACS_GRIDINIT,它说。
这个例程创建一个简单的NPROW过程网格。这个过程网格将使用第一个NPROW进程,并将它们以行或列的主要自然顺序分配给网格。如果这些从进程到网格的映射是不可接受的,则必须调用BLACS_GRIDINIT更复杂的姐妹例程BLACS_GRIDMAP。
没有提到如果流程不是结果网格的一部分,那么ctxt将是什么--这是我经常在BLACS文档中发现的问题。此外,也请不要使用goto,为了你自己。你以后会后悔的。使用If ... End If。我不记得我上次在Fortran使用goto是什么时候了,它很可能是10年前的事了。
最后,祝您在使用BLACS方面好运!在我的经验中,文档通常是不完整的,我建议只使用那些绝对必要的调用来使用ScaLAPACK和MPI,这对于其他的文档来说定义要好得多。如果ScaLAPACK现在能和MPI一起工作,那就好多了。
https://stackoverflow.com/questions/61678599
复制相似问题