【发布时间】:2015-07-30 05:15:20
【问题描述】:
我有以下 MPI/fortran 代码来创建两组,其中一组 包含处理器总数的前 2/3 和第二个 其中包括其余的 1/3。它编译没有问题但是当我 打印出新排名(在最近创建的组中),只有第二个 组显示正确的排名,第一组中的进程 显示负数。
您对此问题有何评论? 谢谢。
program test
implicit none
include "mpif.h"
integer, allocatable :: rs_use(:),ks_use(:)
integer numnodes,myid,mpi_err
integer ijk,new_group,old_group,num_used,used_id
integer proc_rs,proc_ks
integer RSPA_COMM_WORLD !Real Space communicator
integer KSPA_COMM_WORLD !Recip. Space communicator
! initialize mpi
call MPI_INIT( mpi_err )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numnodes, mpi_err )
call MPI_Comm_rank(MPI_COMM_WORLD, myid, mpi_err)
proc_rs = 2*numnodes/3 !Nr. of processors for Real Space
proc_ks = numnodes - proc_rs !Nr. of processors for Recip. Space
write(6,*) 'processors rs',proc_rs,'ks',proc_ks
! get our old group from MPI_COMM _WORLD
call MPI_COMM_GROUP(MPI_COMM_WORLD,old_group,mpi_err)
! Real Space group that will contain 2*N/3 processors
allocate(rs_use(0:proc_rs-1))
do ijk=0,proc_rs-1
rs_use(ijk)=ijk
enddo
call MPI_GROUP_INCL(old_group,proc_rs,rs_use,new_group,mpi_err)
! create the new communicator
call MPI_COMM_CREATE(MPI_COMM_WORLD,new_group,RSPA_COMM_WORLD, mpi_err)
! test to see if I am part of new_group.
call MPI_GROUP_RANK(new_group,used_id, mpi_err)
! Recip. Space group that will contain N/3 processors
allocate(ks_use(proc_rs:numnodes-1))
do ijk=proc_rs,numnodes-1
ks_use(ijk)=ijk
enddo
call MPI_GROUP_INCL(old_group,proc_ks,ks_use,new_group,mpi_err)
! create the new communicator
call MPI_COMM_CREATE(MPI_COMM_WORLD,new_group,KSPA_COMM_WORLD, mpi_err)
! test to see if I am part of new_group.
call MPI_GROUP_RANK(new_group,used_id, mpi_err)
if(used_id==0) write(6,*) 'group ',used_id,myid
end program test
【问题讨论】:
-
您不会测试对 MPI 例程的任何调用是否成功。
allocate声明也没有成功。为什么我不应该断定其中一个调用会静默失败? -
您好,我测试了 allocate 和 MPI 例程,感谢您的建议。但是,我仍然有问题,第一组的 used_id 打印出负数。
-
@innoSPG 有正确答案,但我将提供两个更一般的建议:(1) 在现代 fortran 中,强烈建议您使用
use mpi而不是include "mpif.h",并让编译器在编译时为您找到潜在问题的整个类。 (2) 在这种情况下,您要将现有通信器划分为两个不重叠的子集,使用MPI_Comm_split更容易。