Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当相同的处理器在相同的存储箱中求和时,Fortran混合中的MPI_Allreduce_Mpi - Fatal编程技术网

当相同的处理器在相同的存储箱中求和时,Fortran混合中的MPI_Allreduce

当相同的处理器在相同的存储箱中求和时,Fortran混合中的MPI_Allreduce,mpi,Mpi,MPI_所有减少总和中的混合元素 我正在并行化一个fortran代码,它在无MPI版本中工作没有问题。下面是代码的摘录。每个处理器都会执行以下操作:对于一定数量的粒子,它会在循环do 203中演化出一定数量的粒子;在一个被划分为nin子区间j=1,nin的给定区间内,每个处理器产生一个向量Nx1j,Nx2j的元素。然后,向量Nx1j,Nx2j被发送到根mype=0,该根mype=0在每个子区间j=1,nin将每个处理器的所有贡献相加:来自处理器1的Nx1j+来自处理器2的Nx1j。。。。每个子区

MPI_所有减少总和中的混合元素

我正在并行化一个fortran代码,它在无MPI版本中工作没有问题。下面是代码的摘录。每个处理器都会执行以下操作:对于一定数量的粒子,它会在循环do 203中演化出一定数量的粒子;在一个被划分为nin子区间j=1,nin的给定区间内,每个处理器产生一个向量Nx1j,Nx2j的元素。然后,向量Nx1j,Nx2j被发送到根mype=0,该根mype=0在每个子区间j=1,nin将每个处理器的所有贡献相加:来自处理器1的Nx1j+来自处理器2的Nx1j。。。。每个子区间中j的每个值的根求和,并产生Nx5j,Nx6j。另一个问题是,如果我取消分配变量,代码在计算结束后仍处于备用状态,而没有完成执行;但我不知道这是否与MPI_Allreduce问题有关

include "mpif.h"
...

integer*4 ....

...

real*8 

...

call MPI_INIT(mpierr)

call MPI_COMM_SIZE(MPI_COMM_WORLD, npe, mpierr)

call MPI_COMM_RANK(MPI_COMM_WORLD, mype, mpierr)


! Allocate variables allocate(Nx1(Nint),Nx5(Nint)) ...


! Parameters ...


call MPI_Barrier (MPI_COMM_WORLD, mpierr)


! Loop on particles


do 100 npartj=1,npart_local


 call init_random_seed() 

 call random_number (rand)


...

Initial condition

... 

do 203 i=1,1000000  ! loop for time evolution of single particle


    if(ufinp.gt.p1.and.ufinp.le.p2)then 

     do j=1,Nint  ! spatial position at any momentum

      ls(j) = lb+(j-1)*Delta/Nint !Left side of sub-interval across shock

      rs(j) = ls(j)+Delta/Nint

      if(y(1).gt.ls(j).and.y(1).lt.rs(j))then !position-ordered

        Nx1(j)=Nx1(j)+1 

      endif 

     enddo

    endif

   if(ufinp.gt.p2.and.ufinp.le.p3)then 

    do j=1,Nint  ! spatial position at any momentum

      ls(j) = lb+(j-1)*Delta/Nint !Left side of sub-interval across shock

      rs(j) = ls(j)+Delta/Nint

      if(y(1).gt.ls(j).and.y(1).lt.rs(j))then !position-ordered

        Nx2(j)=Nx2(j)+1 

      endif 

    enddo

   endif


203 continue 

100 continue

call MPI_Barrier (MPI_COMM_WORLD, mpierr)


print*,"To be summed"

do j=1,Nint

   call MPI_ALLREDUCE (Nx1(j),Nx5(j),npe,mpi_integer,mpi_sum, &
     &      MPI_COMM_WORLD, mpierr)
   call MPI_ALLREDUCE (Nx2(j),Nx6(j),npe,mpi_integer,mpi_sum, &
     &          MPI_COMM_WORLD, mpierr)

enddo 


if(mype.eq.0)then

do j=1,Nint

   write(1,107)ls(j),Nx5(j),Nx6(j)

 enddo 


107 format(3(F13.2,2X,i6,2X,i6))

endif 

call MPI_Barrier (MPI_COMM_WORLD, mpierr) 
print*,"Now deallocate" 

! deallocate(Nx1) 

!inserting the de-allocate 

! deallocate(Nx2)


close(1)


call MPI_Finalize(mpierr)


end


! Subroutines ...

很抱歉,我不明白你的问题,你能解释一下你希望你的allreduces做什么,以及它们做什么不同于此吗?可能是我在你的另一个问题中添加了MPI标记的重复,不需要多次问同样的问题。@Haraldkl:我有N个粒子,每个处理器在npart_局部粒子上运行。空间间隔Delta分为九个子间隔。在单个粒子上,处理器记录粒子在Delta内不同时间的位置。如果在时间t,粒子的速度在p1和p2之间,并且位于lsj和rsj之间,则计数器Nx1j增加1。如果粒子的速度在p2和p3之间,在lsj和rsj之间,计数器Nx2j增加1。所以每个处理器都计算Nx1j,Nx2j。。。allreduce对每个j和各种速度的所有粒子求和。谢谢