在OpenMPI中混合使用“英特尔C++”和“Fortran”时未定义的引用



我在使用Open MPI 1.8.4和"英特尔编译器v15.2"时遇到编译问题。这是一个使用Fortran和C++的大型代码。该代码以前是使用Open MPI 1.6编译的,但问题并不存在。

以下是make文件的内容:

ifdef TAUDEBUG
    FC=tau_f90.sh
    COMP=tau_f90.sh
    CXX=tau_cxx.sh
    CXXFLAGS=
    CXXOPT=
    LINKER=tau_cxx.sh
else
    FC=mpif90
    COMP=mpif90
    CXX=mpic++
    CXXFLAGS=
    CXXOPT=
    LINKER=$(CXX)
endif

CXXLINKFLAGS += -I/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,-rpath -Wl,/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,--enable-new-dtags -L/cm/shared/apps/openmpi/intel/1.8.4/lib -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi
FORTFLAGS= -DFORTRAN_UNDERSCORE -DFORTRAN_LOWERCASE

我遇到的问题是C++代码正在使用一些Fortran例程,mpic++需要与Fortran库链接。

对于Open MPI 1.6,它是用完成的

CXXLINKFLAGS += -L/usr/mpi/intel/openmpi-1.6/lib64 -lmpi_f90 

它奏效了。

不赞成从OpenMPI v.1.7开始使用mpif90。并且libmpi_f90不再存在。所有与Fortran相关的例程都由libmpi_usempif08*和libmpi_mpifh*处理。

这就是我正在挣扎的地方。

我试过

CXXLINKFLAGS += -L/cm/shared/apps/openmpi/intel/1.8.4/lib -lmpi_usempif08 -lmpi_mpifh -lmpi -lmpi_usempi_ignore_tkr 

代码的Fortran部分编译得很好,但当它到达mpic++时,我开始得到很多"未定义的引用"错误:

mpic++  rflump.o main.o -o ../rflump -O .././build_lib/libflu.a      -L/cm/shared/apps/openmpi/intel/1.8.4/lib -lmpi_usempif08 -lmpi_mpifh -lmpi -lmpi_usempi_ignore_tkr 
rflump.f90:(.text+0x56): undefined reference to `for_cpystr'
.././build_lib/libflu.a(RFLU_EndFlowSolver.o): In function `rflu_endflowsolver_':
RFLU_EndFlowSolver.f90:(.text+0x2a): undefined reference to `for_cpystr'
.././build_lib/libflu.a(RFLU_FlowSolver.o): In function `rflu_flowsolver_':
RFLU_FlowSolver.f90:(.text+0x2d): undefined reference to `for_cpystr'
.././build_lib/libflu.a(RFLU_InitFlowSolver.o): In function `rflu_initflowsolver_':
RFLU_InitFlowSolver.f90:(.text+0x4e): undefined reference to `for_cpystr'
RFLU_InitFlowSolver.f90:(.text+0x1b3): undefined reference to `for_inquire'
RFLU_InitFlowSolver.f90:(.text+0x1c59): undefined reference to `for_cpstr'
RFLU_InitFlowSolver.f90:(.text+0x2cc4): undefined reference to `for_write_seq_lis'
.././build_lib/libflu.a(RFLU_OpenConverFile.o): In function `rflu_openconverfile_':
RFLU_OpenConverFile.f90:(.text+0x2d): undefined reference to `for_cpystr'
RFLU_OpenConverFile.f90:(.text+0x1ca): undefined reference to `for_trim'
RFLU_OpenConverFile.f90:(.text+0x20a): undefined reference to `for_concat'
.././build_lib/libflu.a(RFLU_OpenPMFile.o): In function `rflu_openpmfile_':
RFLU_OpenPMFile.f90:(.text+0x2d): undefined reference to `for_cpystr'
RFLU_OpenPMFile.f90:(.text+0x1ca): undefined reference to `for_trim'
RFLU_OpenPMFile.f90:(.text+0x20a): undefined reference to `for_concat'
.././build_lib/libflu.a(RFLU_OpenStatsFileOLES.o): In function `rflu_openstatsfileoles_':
RFLU_OpenStatsFileOLES.f90:(.text+0x2d): undefined reference to `for_cpystr'
RFLU_OpenStatsFileOLES.f90:(.text+0x1c0): undefined reference to `for_trim'
RFLU_OpenStatsFileOLES.f90:(.text+0x200): undefined reference to `for_concat'
.././build_lib/libflu.a(RFLU_OpenTotalMassFile.o): In function `rflu_opentotalmassfile_':
RFLU_OpenTotalMassFile.f90:(.text+0x2d): undefined reference to `for_cpystr'
RFLU_OpenTotalMassFile.f90:(.text+0x1ca): undefined reference to `for_trim'
RFLU_OpenTotalMassFile.f90:(.text+0x20a): undefined reference to `for_concat'
.././build_lib/libflu.a(RFLU_PrintHeader.o): In function `rflu_printheader_':
RFLU_PrintHeader.f90:(.text+0x26): undefined reference to `for_cpystr'
RFLU_PrintHeader.f90:(.text+0x6e): undefined reference to `for_cpystr'
RFLU_PrintHeader.f90:(.text+0x7d): undefined reference to `for_len_trim'
RFLU_PrintHeader.f90:(.text+0xc2): undefined reference to `for_cpystr'
RFLU_PrintHeader.f90:(.text+0x324): undefined reference to `for_trim'
RFLU_PrintHeader.f90:(.text+0x622): undefined reference to `for_trim'
RFLU_PrintHeader.f90:(.text+0x77a): undefined reference to `for_trim'

我知道OpenMPI正在使用正确的编译器:

$ mpifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.2.164 Build 20150121
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.
$ mpic++ -V
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.2.164 Build 20150121
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

同样根据OpenMPI文档链接到Fortran我需要使用:

$ mpifort --showme:link
-I/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,-rpath -Wl,/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,--enable-new-dtags -L/cm/shared/apps/openmpi/intel/1.8.4/lib -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi

我复制了整行并将其粘贴到Makefile:

CXXLINKFLAGS += -I/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,-rpath -Wl,/cm/shared/apps/openmpi/intel/1.8.4/lib -Wl,--enable-new-dtags -L/cm/shared/apps/openmpi/intel/1.8.4/lib -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi

结果与之前的输出完全相同。看起来C++编译器正在尝试使用Fortran,但没有找到它

我在这里错过了什么?

就像Hristo建议的那样,我在CXXLINKFLAGS中添加了-lifcore(这是我在英特尔编译器中找到的库),但我再也看不到undefined reference错误了。我没有意识到您可以通过这种方式将icpcifort选项添加到mpic++mpifort中。

最新更新