gfortran - 确定用户是使用 gfortran 还是 ifort
问题描述
我正在用现代 Fortran 编写代码,我想做一些类似的事情:
IF (you are compiling the code with gfortran) Do something...
IF (you are compiling the code with ifort) Do other thing...
但我还没有找到一种方法来验证代码中 IF 语句中的那些逻辑条件。
解决方案
最简单的方法是查看特定于编译器的宏。
对于 gfortran,您可以按照此处__GNUC__
所述查看。
对于ifort,你可以看这里__INTEL_COMPILER
描述的。
如果你有文件test.F90
(注意.F90
而不是.f90
,这个文件被预处理很重要),那么你可以有类似的东西
program test
implicit none
#ifdef __GNUC__
logical, parameter :: gfortran = .true.
#else
logical, parameter :: gfortran = .false.
#endif
#ifdef __INTEL_COMPILER
logical, parameter :: ifort = .true.
#else
logical, parameter :: ifort = .false.
#endif
if (gfortran) then
write(*,*) 'gfortran'
elseif (ifort) then
write(*,*) 'ifort'
else
write(*,*) 'Unknown compiler'
endif
end program
推荐阅读
- c++ - 在子窗口中使用 winapi 在 C++ 中创建按钮不起作用
- r - 试图从 ggplot 中重现 ANOVA 测试箱线图
- amazon-web-services - AWS Cognito 用户池禁用登录按钮
- python - 网格中的 Tkinter 标签异常扩展
- python - 为什么我的 tksheet tkinter 窗口滚动条在调整大小后被隐藏?
- javascript - React Native:何时使用箭头函数
- pie-chart - 空对象引用上的 MPAndroidChart PieChart setData
- action - 是否有另一种方法可以在不使用 action 属性的情况下将表单中的提交按钮链接到另一个页面?
- eloquent - 在 Laravel 错误中使用 Group by 加入查询
- reactjs - 为什么数字没有按顺序上升?