问题描述
我是 Fortran 新手(Windows 上的 gfortran),想使用随机数生成器 vsrnggaussian
。
vsrnggaussian
需要 mkl_vsl.f90 文件中提供的英特尔 MKL VSL 模块“mkl_vsl_type”和“mkl_vsl”。需要包含此文件以生成模块文件“mkl_vsl_type.mod”和“mkl_vsl.mod”,用于处理引用 VSL 接口的 Fortran 使用子句:
use mkl_vsl_type
use mkl_vsl
我尝试了多种方法来包含 mkl_vsl.f90 文件,但它们都不起作用:
Unexpected data declaration statement at (1)
[...] at (1) has no implicit type
expecting [...] statement at (1)
unexpected [...] statement at (1)
- 最后
Fatal error: Cannot open module file 'mkl_vsl_type.mod' for reading at (1): No such file or directory. compilation terminated. "gfortran -g -o incl_mkl.exe ../incl_mkl.f90" terminated with exit code 1. Build might be incomplete.
-
我在包含语句中使用了完整路径:
INCLUDE 'C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/mkl_vsl.f90'
-->Error: Can't open included file
-
我尝试了 -Idir 编译器命令:
gfortran -I/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/ -g -o incl_mkl.exe
-->gfortran: error: Files: no such file or directory
-
我把它放到 makefile 中:
INCLUDES=-I. -I/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/
-->Error: Can't open included file
如何包含 mkl_vsl.f90 文件??
编辑:我的简单代码包含 mkl_vsl.f90 文件
(在我用 vsrnggaussian
编译我的主代码之前,将首先编译此代码):
Program INCL
IMPLICIT NONE
INCLUDE 'mkl_vsl.f90'
!INCLUDE 'C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/mkl_vsl.f90'
END Program
解决方法
您需要使用vsl_type
和vsl
模块。原因是 vsl
中的派生类型是在 vsl_type
中定义的。 MWE
Program INCL
use mkl_vsl_type
use mkl
IMPLICIT NONE
write(6,*) 'hello world'
END Program
您需要将文件 mkl_vsl.f90
的地址传递给 ifort 和 mkl
标志。
ifort -mkl foo.f90 <address>/mkl_vsl.f90
要使用 MKL 的任何特定子程序,请咨询他们的网站。 MKL 还提供了大量示例。您可能会在 C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/examples
或类似的地方找到它。