2012-10-19 43 views
2

最近我嘗試編譯和一臺機器上運行我的MPI代碼的MPI Fortran代碼錯誤(Ubuntu的12.04 - 64位酷睿i7 2670 QM)我用下面的配置安裝MPICH2 1.2版:一臺PC

./configure --prefix=/opt/mpich2 --enable-f77 --enable-fc --enable-cxx --with-device=ch3:sock --with-pm=mpd CC=icc CXX=icpc F77=ifort FC=ifort 2>&1 | tee configure.log 

安裝沒問題,我的mpd工作得很好,我用mpd測試了一些例子,都很完美。

我使用mpif77編譯我的代碼,因爲我不知道爲什麼當我編譯mpich2 mpif90時沒有創建。但即使使用mpif77,我也可以編譯出沒有錯誤的代碼。

我使用的編譯代碼的標誌是:

對於編譯器:

LN_FLAGS= -lm -larpack -lsparskit -lfftw3 -lrt -llapack -lblas 

對於MPI鏈接:

LN_FLAGS_MPI= $(LN_FLAGS) -I$(MPIHOME)/include -L$(MPIHOME) $(MPIHOME)/lib/libmpich.a -lfmpich -lopa -lmpe 

所以,問題是當我嘗試運行我的機器上的代碼:

首先我調用mpd爲:

mpd & 

,然後運行該代碼:

mpirun -np 4 ./code_mpi 

我嘗試了很多的變化爲:

mpiexec -np 4 ./code_mpi 
mpirun -n 2 ./code_mpi 
mpiexec -n 2 ./code_mpi 

而且所有結果在相同的錯誤:

Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
[cli_2]: aborting job: 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
[cli_1]: aborting job: 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
rank 2 in job 1 ubuntu_38132 caused collective abort of all ranks 
    exit status of rank 2: killed by signal 9 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
[cli_3]: aborting job: 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
[cli_0]: aborting job: 
Fatal error in MPI_Comm_rank: Invalid communicator, error stack: 
MPI_Comm_rank(106): MPI_Comm_rank(MPI_COMM_NULL, rank=0x14b46a0) failed 
MPI_Comm_rank(64).: Null communicator 
rank 1 in job 1 ubuntu_38132 caused collective abort of all ranks 
    exit status of rank 1: return code 1 

我花了將近2周的時間來解決這個問題,因爲我真的需要運行這個代碼我的個人電腦在家工作。我感謝所有可以幫助我的人!


這裏是我初始化MPI庫

subroutine init() 
integer      :: provided 
call mpi_init(mpi_err) 
call mpi_comm_rank(mpi_comm_world,rank,mpi_err) 
call mpi_comm_size(mpi_comm_world,an_proc,mpi_err) 
call MPI_BARRIER(MPI_COMM_WORLD,mpi_err) 
end subroutine init 
+1

您不應該首先啓動mpd;你能編譯/運行一個簡單的MPI「Hello world」,例如http://www.slac.stanford.edu/comp/unix/farm/mpi.html? –

+2

向我們展示這部分初始化MPI庫的代碼,例如包含調用'MPI_INIT'和'MPI_COMM_RANK'的部分。 –

回答

4

的問題是你的子程序不知道什麼mpi_comm_world是。此整數值在mpif.h標題(或f90的mpi模塊)中設置。編寫代碼時,mpi_comm_world由編譯器隨機分配,與mpi提供的實際mpi_comm_world通信器手柄無關。

通常,最好在您的代碼中使用implicit none,它會警告您這些類型的錯誤。請嘗試以下操作:

subroutine init() 
!use mpi !This one is for f90 
implicit none 
include 'mpif.h' !use this for f77 
integer :: provided,rank,an_proc,ierr 
call mpi_init(ierr) 
call mpi_comm_rank(mpi_comm_world,rank,ierr) 
call mpi_comm_size(mpi_comm_world,an_proc,ierr) 
call MPI_BARRIER(MPI_COMM_WORLD,ierr) 
end subroutine init 
+0

真的很奇怪,因爲當我在羣集上運行時,我不會收到這個錯誤。我做了更改,錯誤繼續... –

相關問題