当前位置: 首页 > news >正文

MATLAB R2023b配置Fortran编译器

MATLAB R2023b配置Fortran编译器

  • 引言
  • 1. 安装Visual Studio 2019
  • 2. 安装Intel API2024
  • 3. 配置xml文件文件
  • 4. 设置环境变量
  • 5. MATLAB编译Fortran

引言

当我们需要用到MATLAB编译Fortran代码后进行调用计算时,整个配置流程较繁琐。下面以MATLAB R2023b为例,介绍配置Fortran编译器的流程以及中间可能遇到的问题。
我的版本:
MATLAB R2023b:”https://mp.weixin.qq.com/s/KclU24GCUQj70j1s_cqE2g“
Visual Studio 2019:”https://mp.weixin.qq.com/s/Pc5U7lBrhUq06MYj6hSJWw“,(或:”https://learn.microsoft.com/zh-cn/visualstudio/releases/2019/release-notes”)
w_BaseKit_p_2024.2.1.101_offline.exe:”https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html“
w_BaseKit_p_2024.2.1.101_offline.exe:”https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html“

1. 安装Visual Studio 2019

我尝试了使用Visual Studio 2022进行配置,但是出现了在MATLAB中使用MEX -setup命令,能够正常显示编译器,但是在使用MEX编译Fortran代码时出现了“错误使用 mex ‘ifx’ 不是内部或外部命令,也不是可运行的程序 或批处理文件”的提示,具体原因可能是”G:\Program Files (x86)\Intel\oneAPI\compiler\2024.2\bin“文件夹中的ifx.exe不能识别,未找到解决办法。因此就选择卸载VS2022,重新安装VS2019。

VS2019安装包在如下链接可以下载:https://mp.weixin.qq.com/s/Pc5U7lBrhUq06MYj6hSJWw

但是在下载的过程中又出现了下载速度贼慢的问题。后来按照网上检索的一个修改hosts的办法,亲测有效,如果没有遇到这个问题可直接跳过,进行第2步
1.使用DNS查找工具网站”https://tool.chinaz.com/dns/?type=1&host=download.visualstudio.microsoft.com&ip=“,查询微软的下载网站的域名 download.visualstudio.microsoft.com 找到TTL最低的那个节点。
在这里插入图片描述
2.找到TTL值最小的那个节点,复制IP地址,在我这里对应的最小IP就是 103.208.44.30。如下所示:
在这里插入图片描述
3.以记事本形式,打开”C:\Windows\System32\drivers\etc“文件夹下的hosts文件,在hosts里加入 IP地址+微软的下载网站的域名
在这里插入图片描述
这里可能需要另存后,再复制粘贴进这个文件夹里。
在这里插入图片描述
3.打开cmd,刷新dns,然后在ping一下微软的下载地址,查看hosts文件有没有生效。具体步骤如下:
(1)在cmd中输入ipconfig /flushdns 刷新dns
(2)ping微软的下载地址,在cmd中输入:
ping download.visualstudio.microsoft.com
(3)若没有丢包,且往返时间很小,则说明我们的hosts文件生效。
在这里插入图片描述
经过上述操作,VS2019的下载速度会非常快。
安装流程完全按照”https://mp.weixin.qq.com/s/Pc5U7lBrhUq06MYj6hSJWw“所提供的步骤来就行了。

2. 安装Intel API2024

  1. 先安装the Intel® oneAPI Base Toolkit:”https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html“
  2. 再安装the Intel® HPC Toolkit:”https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html“
  3. 安装步骤很简单,修改安装路径,其他默认即可。
  4. 最后打开Visual Studio 2019,看到Fortran一项即说明安装配置成果。
    在这里插入图片描述

3. 配置xml文件文件

然后,需要添加intel_fortran_24_vs2019.xml文件。由于我用的是Intel API2024+visual studio 2019,所以在我的MATLAB安装路径”G:\MATLAB R2023b\bin\win64\mexopts“下需要有intel_fortran_24_vs2019.xml文件,这个文件matlab2023b是没有的。可将下面代码复制粘贴到记事本,再重命名为”intel_fortran_24_vs2019.xml“即可:

<?xml version="1.0" encoding="UTF-8" ?>
<configName="Intel oneAPI 2024 for Fortran with Microsoft Visual Studio 2019"ShortName="INTELF24MSVS2019"Manufacturer="Intel"Version="24.0"Language="FORTRAN"Priority="X"Location="$FORTRANROOT" ><DetailsCompilerExecutable="$COMPILER"CompilerDefines="$COMPDEFINES"CompilerFlags="$COMPFLAGS"OptimizationFlags="$OPTIMFLAGS"DebugFlags="$DEBUGFLAGS"IncludeFlags="$INCLUDE"LinkerExecutable="$LINKER"LinkerFlags="$LINKFLAGS"LinkerLibraries="$LINKLIBS"LinkerDebugFlags="$LINKDEBUGFLAGS"LinkerOptimizationFlags="$LINKOPTIMFLAGS"CommandLineShell="$FORTRANROOT\env\vars.bat "CommandLineShellArg="intel64"CompilerDefineFormatter="/D%s"LinkerLibrarySwitchFormatter="lib%s.lib;%s.lib"LinkerPathFormatter="/LIBPATH:%s"LibrarySearchPath="$$LIB;$$LIBPATH;$$PATH;$$INCLUDE;$MATLABROOT\extern\lib\$ARCH\microsoft"/><!-- Switch guide: http://msdn.microsoft.com/en-us/library/fwkeyyhe(v=vs.71).aspx --><varsCMDLINE100="$COMPILER /c $COMPFLAGS $OPTIM $SRC /Fo$OBJ"CMDLINE200="$LINKER $LINKFLAGS $LINKTYPE $LINKOPTIM $LINKEXPORTVER $OBJS $LINKLIBS /out:$EXE"CMDLINE300="del $EXP $LIB $ILK"
FORTRANROOT="$ONE_API_ROOT/compiler/$ONE_API_VERSION"
COMPILER="ifx.exe"
COMPFLAGS="/nologo /fpp /fixed /MD /fp:source /assume:bscc $INCLUDE  $COMPDEFINES"
COMPDEFINES="/DMATLAB_MEX_FILE"
MATLABMEX=" /DMATLAB_MEX_FILE"
OPTIMFLAGS="/O2 /DNDEBUG"
INCLUDE="-I&quot;$MATLABROOT\extern\include&quot;"
DEBUGFLAGS="/Z7"LINKER="link"
LINKFLAGS=" /nologo  /INCREMENTAL:NO"
LINKTYPE="/DLL"
LINKEXPORT="/EXPORT:MEXFUNCTION"
LINKEXPORTVER="/EXPORT:MEXFUNCTION /EXPORT:MEXFILEREQUIREDAPIVERSION"
LINKLIBS="/LIBPATH:&quot;$MATLABROOT\extern\lib\$ARCH\microsoft&quot; libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
LINKDEBUGFLAGS="/debug /PDB:&quot;$TEMPNAME$LDEXT.pdb&quot;"
LINKOPTIMFLAGS=""OBJEXT=".obj"
LDEXT=".mexw64"
SETENV="set COMPILER=$COMPILERset COMPFLAGS=/c $COMPFLAGS $COMPDEFINES $MATLABMEXset OPTIMFLAGS=$OPTIMFLAGSset DEBUGFLAGS=$DEBUGFLAGSset LINKER=$LINKERset LINKFLAGS=$LINKFLAGS /export:%ENTRYPOINT% $LINKTYPE $LINKLIBS $LINKEXPORTset LINKDEBUGFLAGS=/debug /PDB:&quot;%OUTDIR%%MEX_NAME%$LDEXT.pdb&quot;set NAME_OUTPUT=/out:&quot;%OUTDIR%%MEX_NAME%%MEX_EXT%&quot;"
/><client><engineCMDLINE300="if exist $ILK del $ILK"LINKLIBS="$LINKLIBS libeng.lib"LINKEXPORT="/subsystem:console"LINKEXPORTVER="/subsystem:console"LDEXT=".exe"LINKTYPE=""MATLABMEX=""/></client><locationFinder><ONE_API_ROOT><envVarExists name="ONEAPI_ROOT" /></ONE_API_ROOT><ONE_API_VERSION><and><envVarExists name="ONEAPI_ROOT" /><cmdReturns name ="echo off &amp; (for /f %a IN ('dir &quot;$$\compiler\2024*&quot; /b /ad /on') do (@if exist &quot;$$\compiler\%a\bin\ifx.exe&quot; set &quot;oneapiVer=%a&quot;)) &amp; (@if defined oneapiVer call echo %oneapiVer%)"/></and></ONE_API_VERSION><VCROOT><or><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" /></and></or></VCROOT><SDKROOT><or><hklmExists path="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" /><hkcuExists path="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" /><hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" /><hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" /></or></SDKROOT><VSINSTALLDIR><or><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" /></and></or></VSINSTALLDIR><VCINSTALLDIR><or><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" /></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" /><cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" /></and></or></VCINSTALLDIR><VCVARSALLDIR><or><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" /><fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" /><dirExists name="$$"/></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" /><fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" /><dirExists name="$$"/></and><and><envVarExists name="ProgramFiles(x86)" /><fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" /><cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,17.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" /><fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" /><dirExists name="$$"/></and></or></VCVARSALLDIR><KITSROOT><or><hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hklmExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hkcuExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /></or></KITSROOT><SDKVERSION><and><or><hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hklmExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /><hkcuExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" /></or><!-- For each folder inside '<KITSROOT>\include' check for 'ucrt' and if exists return that folder name --><cmdReturns name="echo off&amp;set &quot;sdkversion=&quot;&amp;(for /f %a IN ('dir &quot;$$\include\&quot; /b /ad-h /on') do ( @if exist &quot;$$\include\%a\ucrt\&quot; set &quot;sdkversion=%a&quot; ))&amp;call echo %sdkversion%" /></and></SDKVERSION></locationFinder><envPATH="$FORTRANROOT\bin;$VCINSTALLDIR\bin\HostX64\x64\;$VCROOT\Common7\IDE\VC\vcpackages;$VCROOT\Common7\IDE;$VCROOT\Common7\Tools;$SDKROOT\Bin\$SDKVERSION\x64;$SDKROOT\Bin\$SDKVERSION\x86;$SDKROOT\Bin\x64;$SDKROOT\Bin\x86;"INCLUDE="$FORTRANROOT\include;$VCINSTALLDIR\include;$VCINSTALLDIR\atlmfc\include;$KITSROOT\include\$SDKVERSION\ucrt;$KITSROOT\include\$SDKVERSION\shared;$KITSROOT\include\$SDKVERSION\um;$KITSROOT\include\$SDKVERSION\winrt;$MATLABROOT\extern\include"LIB="$FORTRANROOT\lib;$VCINSTALLDIR\lib\x64;$VCINSTALLDIR\atlmfc\lib\x64;$KITSROOT\Lib\$SDKVERSION\ucrt\x64;$KITSROOT\lib\$SDKVERSION\um\x64;$MATLABROOT\lib\$ARCH"LIBPATH="$FORTRANROOT\lib;$VCINSTALLDIR\lib\x64;$VCINSTALLDIR\atlmfc\lib\x64"/>
</config>

4. 设置环境变量

变量值是安装oneAPI地址
在这里插入图片描述

5. MATLAB编译Fortran

输入命令:mex -setup FORTRAN
输入编译的Fortran代码:mex ‘DC3D0wrapper.F’
在这里插入图片描述
在文件夹中生成了一个后缀”.mexw64“的文件,即表示编译成功!

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • java基础进阶——log日志、类加载器、XML、单元测试、注解、枚举类
  • 使用openlayers给地图添加内发光、外发光、内外阴影、三维立体效果
  • 可乐机的设计验证
  • 125. 验证回文串【 力扣(LeetCode) 】
  • 设计模式 - 状态模式
  • 详解使用Goalng+Redis实现分布式锁
  • haralyzer 半自动,一次性少量数据采集快捷方法
  • C++系列-继承中的对象模型
  • Spring Boot 使用 MongoDB 教程
  • SpringBoot日志整合
  • 大数据-70 Kafka 高级特性 物理存储 日志存储 日志清理: 日志删除与日志压缩
  • 第五天:java网络编程、JDBC与高级特性概览
  • 推荐一个根据后台提供的接口json文件自动生成前端调用接口的插件typescript
  • Mysql基础篇
  • Java高级Day28-让坦克动起来
  • Django 博客开发教程 8 - 博客文章详情页
  • ES6之路之模块详解
  • FineReport中如何实现自动滚屏效果
  • iOS筛选菜单、分段选择器、导航栏、悬浮窗、转场动画、启动视频等源码
  • Object.assign方法不能实现深复制
  • php的插入排序,通过双层for循环
  • php面试题 汇集2
  • python 学习笔记 - Queue Pipes,进程间通讯
  • SpiderData 2019年2月13日 DApp数据排行榜
  • Web Storage相关
  • 缓存与缓冲
  • 通过npm或yarn自动生成vue组件
  • 温故知新之javascript面向对象
  • 学习HTTP相关知识笔记
  • 学习笔记TF060:图像语音结合,看图说话
  • 用mpvue开发微信小程序
  • [Shell 脚本] 备份网站文件至OSS服务(纯shell脚本无sdk) ...
  • 阿里云移动端播放器高级功能介绍
  • ​Java基础复习笔记 第16章:网络编程
  • ‌分布式计算技术与复杂算法优化:‌现代数据处理的基石
  • #!/usr/bin/python与#!/usr/bin/env python的区别
  • #1014 : Trie树
  • #java学习笔记(面向对象)----(未完结)
  • #微信小程序:微信小程序常见的配置传旨
  • $jQuery 重写Alert样式方法
  • (1)安装hadoop之虚拟机准备(配置IP与主机名)
  • (2.2w字)前端单元测试之Jest详解篇
  • (c语言版)滑动窗口 给定一个字符串,只包含字母和数字,按要求找出字符串中的最长(连续)子串的长度
  • (Git) gitignore基础使用
  • (备忘)Java Map 遍历
  • (附源码)c#+winform实现远程开机(广域网可用)
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (十六)串口UART
  • ./和../以及/和~之间的区别
  • .NET C# 使用 iText 生成PDF
  • .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
  • .NET/C# 中设置当发生某个特定异常时进入断点(不借助 Visual Studio 的纯代码实现)
  • .NET开发者必备的11款免费工具
  • .net利用SQLBulkCopy进行数据库之间的大批量数据传递
  • .NET企业级应用架构设计系列之开场白