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

时间:2016-04-14 00:26:17

标签: c++ fortran openmpi

使用Open MPI 1.8.4和Intel Compiler 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,但却找不到它。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

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