我想use
我的 Fortran 代码中的不同库(我也在使用英特尔 Fortran 编译器)取决于编译时可用的 MKL 版本。 MKL 安装中包含一个文件接口(interface),它为版本号和构建日期定义预处理器宏 - /opt/intel/mkl/include/mkl.fi
我认为流程如下:
- 从上述文件接口(interface)获取MKL的版本号
- 使用版本号来决定将哪个库
use
通过预处理器指令 - 执行
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/