我有以下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
use mpi
而不是include "mpif.h"
,让编译器在编译时为您找到整个类别的潜在问题。(2) 在这种情况下,您要将现有通信器分成两个不重叠的子集,使用MPI_Comm_split
更容易。 - Jonathan Dursi