1.安装
在混和使用g77与gfortran编译mvapich时,官方文档中提到了要设置如下的相关的参数,这里我以make.mvapich.smp为例.
#vi make.mvapich.smp
18 PREFIX=${PREFIX:-/usr/local/mvapich}
19 export CC=${CC:-gcc}
20 export CXX=${CXX:-g++}
21 export F77=${F77:-g77}
22 export F90=${F90:-gfortran}
23 export F77_GETARGDECL=" "
24 export F90FLAGS="-ff2c"
修改完成后进行编译安装:
#./make.mvapich.smp
通过查看目录下config-mine.log可以查看相关信息.
完成安装后,可以看到存在/usr/local/mvapich/examples/pi3f90.f90,说明mpif90己经配置安装,可以使用了.
2.测试
开始测试mpif90是否能正常编译f90程序.
#cd /usr/local/mvapich/examples
#/usr/local/mvapich/bin/mpif90 pi3f90.f90
pi3f90.o: In function `MAIN__':
pi3f90.f90:(.text+0x2c): undefined reference to `mpi_init_'
pi3f90.f90:(.text+0x46): undefined reference to `mpi_comm_rank_'
pi3f90.f90:(.text+0x60): undefined reference to `mpi_comm_size_'
pi3f90.f90:(.text+0x254): undefined reference to `mpi_bcast_'
pi3f90.f90:(.text+0x338): undefined reference to `mpi_reduce_'
pi3f90.f90:(.text+0x3f5): undefined reference to `mpi_finalize_'
collect2: ld returned 1 exit status
3.如何解决上面的问题呢?
1)首先在mpif90中加入F90FLAGS的信息
#vi /usr/local/mvapich/bin/mpif90
30 F90BASE="gfortran"
31 F90LINKERBASE="gfortran"
32 F90FLAGS="-ff2c"
#/usr/local/mvapich/bin/mpif90 pi3f90.f90
/usr/local/mvapich/lib/libmpich.a(farg.o): In function `mpir_iargc__':
farg.f:(.text+0x7): undefined reference to `f__xargc'
/usr/local/mvapich/lib/libmpich.a(farg.o): In function `mpir_getarg__':
farg.f:(.text+0x27): undefined reference to `G77_getarg_0'
collect2: ld returned 1 exit status
make: *** [pi3f90] Error 1
2)接下来生成一个farg.f的文件,生成farg.o文件.
#vi farg.f
1 integer function mpir_iargc()
2
3 mpir_iargc = IARGC()
4 return
5 end
6 c
7 subroutine mpir_getarg( i, s )
8
9 integer i
10 character (LEN=*) s
11
12 call GETARG(i,s)
13 return
14 end
#gfortran -fsecond-underscore -c farg.f
3)使用下面的命令生成pi3f90文件.
#/usr/local/mvapich/bin/mpif90 -c pi3f90.f90
#/usr/local/mvapich/bin/mpif90 -o pi3f90 pi3f90.o farg.o
(补充:若又出现了
/usr/local/mvapich/bin/mpif90 -o pi3f90 pi3f90.o farg.o
farg.o(.text+0x34): In function `mpir_getarg__':
: undefined reference to `getarg_'
collect2: ld returned 1 exit status )
修改mpif90下面两行类似以下
USER_FFLAGS="-L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -L/usr/lib64" ( 我的g77是3.4.6版的)
BASE_LIB_LIST=" -L/usr/lib64 -Wl,-rpath=/usr/lib64 -libverbs -libumad -lpthread -lpthread -lrt -lg2c")
4)最终测试
#mpirun_rsh -np 2 n1 n2 GFORTRAN_UNBUFFERED_ALL=y ./pi3f90
Process 0 of 2 is alive
Enter the number of intervals: (0 quits)
Process 1 of 2 is alive
10000000
pi is approximately: 3.1415926535899814 Error is: 0.0000000000001883
Enter the number of intervals: (0 quits)
写这篇文档的原由是由于在解决这个问题的过程中,google后很失望,通过对 这篇文档的反复琢磨,有了上面的文档,希望对后来者有用.
阅读(6863) | 评论(0) | 转发(0) |