gpt4 book ai didi

linux - ifort mpi-openmp 段错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:34:51 25 4
gpt4 key购买 nike

我有一个混合 mpi-openmp 代码,它因段错误、错误终止错误而崩溃。我使用 mpif90/ifort 编译,并使用 mpich2。这是我使用并收到错误的编译行:

mpif90.mpich2 -f90=ifort -DAMD64_LNX -openmp -o jack_openmp.exe laplace.f

当使用这个命令时,如果我从一个节点运行,指向一个包含不同节点的机器文件,我会得到段错误:

=====================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= EXIT CODE: 11
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
=====================================================================================
APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)

但是,如果我从特定节点(比如 node1)运行它并且机器文件中只有“node1”,那么它会按预期运行,每个节点使用正确数量的线程(比如“node1”被列出两次在机器文件中,mpiexec 命令类似于“mpiexec -np 2 ...”)。

我尝试的第二件事不是链接“-openmp”,而是链接“-liomp5”。当我这样做时,代码编译并运行,甚至跨节点。但是,它不以任何线程方式运行。 “omp_get_num_threads”将返回每个节点 8 个线程(这是正确的),但它只会在机器文件中列出的每个节点运行一个线程,因此不会执行任何实际线程。

如前所述,我正在使用最新的 ifort 编译器 (12.1.2) 和 mpich2。堆栈大小是无限的,通过“ulimit -a”验证并看到它是无限的。

laplace.f 文件的源代码如下:

      program lpmlp
include 'mpif.h'
include "omp_lib.h"

integer imax,jmax,im1,im2,jm1,jm2,it,itmax
parameter (imax=10001,jmax=10001)
parameter (im1=imax-1,im2=imax-2,jm1=jmax-1,jm2=jmax-2)
parameter (itmax=100)
real*8 u(imax,jmax),du(imax,jmax),umax,dumax,tol,pi
parameter (umax=10.0,tol=1.0e-6,pi=3.14159)
! Additional MPI parameters
integer istart,iend,jstart,jend
integer size,rank,ierr,istat(MPI_STATUS_SIZE),mpigrid,length
integer grdrnk,dims(1),gloc(1),up,down,isize,jsize
integer ureq,dreq
integer ustat(MPI_STATUS_SIZE),dstat(MPI_STATUS_SIZE)
real*8 tstart,tend,gdumax
logical cyclic(1)
real*8 uibuf(imax),uobuf(imax),dibuf(imax),dobuf(imax)
! OpenMP parameters
integer nthrds,nthreads

! Initialize
call MPI_INIT_THREAD(MPI_THREAD_FUNNELED,IMPI_prov,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
! 1D linear topology
dims(1)=size
cyclic(1)=.FALSE.
call MPI_CART_CREATE(MPI_COMM_WORLD,1,dims,cyclic,.true.,mpigrid
+ ,ierr)
call MPI_COMM_RANK(mpigrid,grdrnk,ierr)
call MPI_CART_COORDS(mpigrid,grdrnk,1,gloc,ierr)
call MPI_CART_SHIFT(mpigrid,0,1,down,up,ierr)
istart=2
iend=imax-1
jsize=jmax/size
jstart=gloc(1)*jsize+1
if (jstart.LE.1) jstart=2
jend=(gloc(1)+1)*jsize
if (jend.GE.jmax) jend=jmax-1
nthrds=OMP_GET_NUM_PROCS()
print*,"Rank=",rank,"Threads=",nthrds
call omp_set_num_threads(nthrds)

!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j)
! Initialize -- done in parallel to force "first-touch" distribution
! on ccNUMA machines (i.e. O2k)
!$OMP DO
do j=jstart-1,jend+1
do i=istart-1,iend+1
u(i,j)=0.0
du(i,j)=0.0
enddo
u(imax,j)=umax*sin(pi*float(j-1)/float(jmax-1))
enddo
!$OMP END DO
!$OMP END PARALLEL

! Main computation loop
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
tstart=MPI_WTIME()
do it=1,itmax
! We have to keep the OpenMP and MPI calls segregated...
call omp_set_num_threads(nthrds)

!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j)
!$OMP MASTER
dumax=0.0
!$OMP END MASTER
!$OMP DO REDUCTION(max:dumax)
do j=jstart,jend
do i=istart,iend
!nthreads = OMP_GET_NUM_THREADS()
!print*,"Jack",rank,nthreads,nthrds
du(i,j)=0.25*(u(i-1,j)+u(i+1,j)+u(i,j-1)+u(i,j+1))-u(i,j)
dumax=max(dumax,abs(du(i,j)))
enddo
enddo
!$OMP END DO
!$OMP DO
do j=jstart,jend
do i=istart,iend
u(i,j)=u(i,j)+du(i,j)
enddo
enddo
!$OMP END DO
!$OMP END PARALLEL
! Compute the overall residual
call MPI_REDUCE(dumax,gdumax,1,MPI_REAL8,MPI_MAX,0
+ ,MPI_COMM_WORLD,ierr)

! Send phase
if (down.NE.MPI_PROC_NULL) then
j=1
do i=istart,iend
dobuf(j)=u(i,jstart)
j=j+1
enddo
length=j-1
call MPI_ISEND(dobuf,length,MPI_REAL8,down,it,mpigrid,
+ dreq,ierr)
endif
if (up.NE.MPI_PROC_NULL) then
j=1
do i=istart,iend
uobuf(j)=u(i,jend)
j=j+1
enddo
length=j-1
call MPI_ISEND(uobuf,length,MPI_REAL8,up,it,mpigrid,
+ ureq,ierr)
endif
! Receive phase
if (down.NE.MPI_PROC_NULL) then
length=iend-istart+1
call MPI_RECV(dibuf,length,MPI_REAL8,down,it,
+ mpigrid,istat,ierr)
call MPI_WAIT(dreq,dstat,ierr)
j=1
do i=istart,iend
u(i,jstart-1)=dibuf(j)
j=j+1
enddo
endif
if (up.NE.MPI_PROC_NULL) then
length=iend-istart+1
call MPI_RECV(uibuf,length,MPI_REAL8,up,it,
+ mpigrid,istat,ierr)
call MPI_WAIT(ureq,ustat,ierr)
j=1
do i=istart,iend
u(i,jend+1)=uibuf(j)
j=j+1
enddo
endif
write (rank+10,*) rank,it,dumax,gdumax
if (rank.eq.0) write (1,*) it,gdumax
enddo
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
tend=MPI_WTIME()
if (rank.EQ.0) then
write(*,*) 'Calculation took ',tend-tstart,'s. on ',size,
+ ' MPI processes'
+ ,' with ',nthrds,' OpenMP threads per process'
endif
call MPI_FINALIZE(ierr)
stop
end

当运行编译中链接的 -liomp5 时,可以看到:

call omp_set_num_threads(nthrds)

以 nthrds = 8 执行,通过 print 语句验证,但是当立即通过以下方式检查时:

nthreads = OMP_GET_NUM_THREADS()

结果 nthreads = 1。但是,在编译时在 -openmp 中链接时完成的情况(机器文件中的所有相同节点,运行从同一节点开始),nthreads = 8。

如果我在机器文件中首先指定头节点名称更长,说:

=====================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= EXIT CODE: 11
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
=====================================================================================
[proxy:0:1@c403] HYD_pmcd_pmip_control_cmd_cb (./pm/pmiserv/pmip_cb.c:906): assert (!closed) failed
[proxy:0:1@c403] HYDT_dmxu_poll_wait_for_event (./tools/demux/demux_poll.c:77): callback returned error status
[proxy:0:1@c403] main (./pm/pmiserv/pmip.c:226): demux engine error waiting for event
[mpiexec@c403] HYDT_bscu_wait_for_completion (./tools/bootstrap/utils/bscu_wait.c:70): one of the processes terminated badly; aborting
[mpiexec@c403] HYDT_bsci_wait_for_completion (./tools/bootstrap/src/bsci_wait.c:23): launcher returned error waiting for completion
[mpiexec@c403] HYD_pmci_wait_for_completion (./pm/pmiserv/pmiserv_pmci.c:189): launcher returned error waiting for completion
[mpiexec@c403] main (./ui/mpich/mpiexec.c:397): process manager error waiting for completion

很多信息,但希望不要太多。感谢您的帮助。

最佳答案

可能是 OpenMP 线程堆栈太小。您是否尝试过将 OMP_STACKSIZE 设置为较大的尺寸?

% export OMP_STACKSIZE=512m # may be another value: 32m, 64m, 128m, 256m ...

每个 OpenMP 线程使用私有(private)堆栈内存,默认堆栈大小在 IA-32 中为 2MB,在 Intel64 架构中为 4MB。

关于linux - ifort mpi-openmp 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com