fortran - 我可以使用依赖于 Fortran 文件接口(interface)/头文件中的数据的预处理器指令来有条件地选择 USE 语句吗?

标签 fortran fortran90 intel-fortran

我想use我的 Fortran 代码中的不同库(我也在使用英特尔 Fortran 编译器)取决于编译时可用的 MKL 版本。 MKL 安装中包含一个文件接口(interface),它为版本号和构建日期定义预处理器宏 - /opt/intel/mkl/include/mkl.fi

我认为流程如下:

  1. 从上述文件接口(interface)获取MKL的版本号
  2. 使用版本号来决定将哪个库use通过预处理器指令
  3. 执行use用正确的库编译的语句

如果我放置任何use include 之后的语句语句,然而,编译在抛出 error #6278: This USE statement is not positioned correctly within the scoping unit. 后中止。

有没有办法实现条件选择use使用依赖于文件接口(interface)或头文件信息的预处理器指令的语句?

我看不出这怎么可能,因为任何 use语句必须在 include 之前提供决定哪个所需数据的声明 use要执行的语句。我在下面包含了一个示例,该示例演示了我正在尝试做什么,但行不通·

module MKLVersion

!Test for definition and value up here
#ifdef INTEL_MKL_VERSION  

#if INTEL_MKL_VERSION >=  110200
    use LAPACK95, only : ggevx, geevx, sygvd

#elif INTEL_MKL_VERSION < 110200
    use MKL95_LAPACK, only : ggevx, geevx, sygvd

#endif
#endif

! but dont actually get the definition till we get here

include '/opt/intel/mkl/include/mkl.fi'  

end module MKLVersion

最佳答案

这个问题的简短回答最终是否定的——正如 Steve Lionel 所指出的,包含的文件有 INTERFACE 语句,它不能出现在 USE 语句之前。

但是,我为我的特定用例找到了一个解决方案,它可以使用新旧 MKL 版本编译代码。根据这个intel article from 2009 , 有一种调用库的方法可以与旧版本的 MKL 一起使用:

Notes: * f95_precision.mod, mkl95_lapack.mod and mkl95_precision.mod files will be removed in one of the future releases. The current version supports two USE statements - so you can choose or "USE MKL95_LAPACK" or " USE LAPACK95 ". For the future compatibility we recommend using "USE LAPACK95" statement.

因此 USE MKL95_LAPACK 可以替换为 USE LAPACK95 而不会破坏所有内容,这很好。

关于fortran - 我可以使用依赖于 Fortran 文件接口(interface)/头文件中的数据的预处理器指令来有条件地选择 USE 语句吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39251927/

相关文章:

Fortran 打印语句格式,空格太多

parameters - 在 Fortran-90 中将参数作为参数传递?

windows - forrt1 : severe (170): Program Exception - stack overflow

oop - Fortran 中不同接口(interface)过程的重载

c++ - 试图在 C++ 中调用 fortran 子例程

fortran - 覆盖不同模块中的私有(private)函数

oop fortran : why my program does not choose the good subroutine?

fortran - 我们真的可以在所有情况下都避免 goto 吗?

python - 使用 f2py 从 python 将动态向量分配到 fortran

fortran - 如果 OpenMP :. ..else 则打开 MP