我试图将8个处理器分成两个子组。其中一个子组包含2个处理器,例如,它们的级别分别为0和1。对于当前的示例,我不需要另一个组。下面的上下文中的代码片段是我用来达到这个目标的。但是,我一直在获取错误消息。
我收到的一条错误消息如下:
Fatal error in PMPI_Comm_rank: Invalid communicator, error stack:
PMPI_Comm_rank(121): MPI_Comm_rank(MPI_COMM_NULL, rank=0x7fff5a451e10) failed
PMPI_Comm_rank(73).: Null communicator.如果我将第15行中的语句更改为call MPI_GROUP_RANK(...),则不会显示错误消息。但是,我不知道是否可以使用group_rank作为MPI_SEND或MPI_RECV等子程序的输入参数。有人能告诉我我的密码出了什么问题吗?谢谢。
李
01 program main
02 include 'mpif.h'
03 integer :: ierr, irank, num_procs, base_group
04 integer :: incl_list(2), new_group, new_comm, new_rank
05 call MPI_Init ( ierr )
06 call MPI_COMM_RANK( MPI_comm_world, irank, ierr )
07 call MPI_COMM_SIZE( MPI_comm_world, num_procs, ierr)
08 call MPI_COMM_GROUP( MPI_comm_world, base_group, ierr)
09
10 incl_list(1) = 0
11 incl_list(2) = 1
12
13 call MPI_GROUP_INCL( base_group, 2, incl_list, new_group, ierr )
14 call MPI_COMM_CREATE( MPI_COMM_WORLD, new_group, new_comm, ierr )
15 call MPI_COMM_RANK( new_comm, new_rank, ierr )
16 call MPI_Finalize ( ierr )
17 end program发布于 2014-05-27 10:55:38
MPI_COMM_CREATE在不包括在new_group中的级别中返回MPI_COMM_NULL。使用MPI_COMM_RANK调用MPI_COMM_NULL将导致所获得的错误。您应该使用一个IF语句来防止它:
call MPI_COMM_CREATE(MPI_COMM_WORLD, new_group, new_comm, ierr)
if (new_comm /= MPI_COMM_NULL) then
!
! The process is part of new_group - do something useful
!
call MPI_COMM_RANK(new_comm, new_rank, ierr)
! ...
else
!
! The process is not part of new_group - do nothing
!
end ifhttps://stackoverflow.com/questions/23878940
复制相似问题