【问题标题】:MPI_COMM_RANK vs MPI_GROUP_RANKMPI_COMM_RANK 与 MPI_GROUP_RANK
【发布时间】:2014-07-15 17:56:42
【问题描述】:

我尝试将 8 个处理器分成两个子组。其中一个子组包含 2 个处理器,例如,它们的等级是 0 和 1。对于当前示例,我不需要另一个组。下面上下文中的代码 sn-p 是我用来实现这个目标的。但是,我不断收到错误消息。

我收到的错误消息之一如下:

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_SENDMPI_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

【问题讨论】:

    标签: parallel-processing fortran mpi fortran90


    【解决方案1】:

    MPI_COMM_CREATE 在未包含在new_group 中的那些等级中返回MPI_COMM_NULL。用MPI_COMM_NULL 调用MPI_COMM_RANK 会导致您遇到错误。您应该使用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 if
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2015-12-10
      • 2010-09-07
      相关资源
      最近更新 更多