标签: fortran

您为GFORTRAN调试器/编译器设置了哪些标志来捕获错误的代码?

我想我不会在任何教科书中找到它,因为回答这需要经验.我目前正处于测试/验证我的代码/狩猎漏洞以使其进入生产状态的阶段,任何错误都会导致许多人遭受痛苦,例如黑暗面.

  • 在为Fortran编译程序以进行调试时,您设置了哪种标志?

  • 你为生产系统设置了什么样的标志?

  • 在部署之前你做了什么?

生产版本ifort用作编译器,但我用我的测试gfortran.我做错了吗?

deployment debugging fortran gfortran fortran90

38
推荐指数
2
解决办法
3万
查看次数

使用gcc链接fortran和c ++二进制文件

我可以使用gcc分别使用g ++或gfortran在c和c ++之间或c和fortran之间进行调用.但是如果我尝试在c ++和fortran之间进行过程调用,那么在使用g ++或gfortran编译时会出现错误,因为它们都不知道其他所需的库.如何链接使用c ++和fortran编写的源代码的项目?

$ cat print_hi.f90
subroutine print_hi() bind(C)
  implicit none
  write(*,*) "Hello from Fortran."
end subroutine print_hi

$ cat main.cpp
#include <iostream>

extern "C" void print_hi(void);

using namespace std;

int main() {
  print_hi();
  cout << "Hello from C++" << endl;
  return 0;
}
$ gfortran -c print_hi.f90 -o print_hi.o
$ g++ -c main.cpp -o main.o
Run Code Online (Sandbox Code Playgroud)

我尝试用g ++链接:

$ g++ main.o print_hi.o -o main
print_hi.o: In function `print_hi':
print_hi.f90:(.text+0x3f): undefined reference to `_gfortran_st_write'
Run Code Online (Sandbox Code Playgroud)

以及有关未定义引用的更多错误.

并与gfortran:

$ gfortran …
Run Code Online (Sandbox Code Playgroud)

c++ gcc fortran

37
推荐指数
1
解决办法
3万
查看次数

Fortran 90种参数

我无法理解Fortran 90的kind参数.据我所知,它不确定变量的精度(即浮点数或双精度数),也不确定变量的类型.

那么,它决定了什么,究竟是什么呢?

fortran

36
推荐指数
3
解决办法
5万
查看次数

你如何使用Fortran 90模块数据

假设您有一个包含大量变量,函数和子例程的Fortran 90模块.在您的USE陈述中,您遵循哪种惯例:

  1. 使用, only :语法显式声明您正在使用哪些变量/函数/子例程,例如 USE [module_name], only : variable1, variable2, ...
  2. 插入毯子USE [module_name]

一方面,该only子句使代码更加冗长.但是,它会强制您在代码中重复自己,如果您的模块包含许多变量/函数/子例程,那么事情就会开始变得难以驾驭.

这是一个例子:

module constants
  implicit none
  real, parameter :: PI=3.14
  real, parameter :: E=2.71828183
  integer, parameter :: answer=42
  real, parameter :: earthRadiusMeters=6.38e6
end module constants

program test
! Option #1:  blanket "use constants"
!  use constants
! Option #2:  Specify EACH variable you wish to use.
  use constants, only : PI,E,answer,earthRadiusMeters
  implicit none …
Run Code Online (Sandbox Code Playgroud)

fortran module conventions fortran90

36
推荐指数
3
解决办法
5万
查看次数

由于在Mac OS X上brew install gcc之后缺少fortran编译器,仍然无法安装scipy

我已阅读并按照此答案安装scipy/numpy/theano.但是,在brew install gcc之后,它仍然失败了同样的错误,即缺少Fortran编译器.虽然HomeBrew安装了gcc-4.8,但它没有安装任何gfortran或g95命令.我认为gfortran可能只是gcc 的同义词,然后我创建了一个符号链接

$ cd /usr/local/bin
$ ln -s gcc-4.8 gfortran
$ pip install scipy
Run Code Online (Sandbox Code Playgroud)

然后它检测到gfortran命令,但仍抱怨没有Fortran编译器

customize Gnu95FCompiler
Found executable /usr/local/bin/gfortran
customize NAGFCompiler
Could not locate executable f95
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize IBMFCompiler
Could not locate executable xlf90
Could not locate executable xlf
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not …
Run Code Online (Sandbox Code Playgroud)

python macos homebrew fortran numpy

36
推荐指数
2
解决办法
3万
查看次数

朱莉娅(Julia-lang)表现与Fortran和Python相比

我调整了一个简单的程序来计算和绘制Julia的运动漩涡以测试语言,我也用Python编写它没有特别的原因.

(免责声明:1.我读过的stackoverflow的每一次性能比较都因为没有全面/正确/写得好/相关等等而受到抨击 - 我不是假装这是一个真正的比较,我只想知道如何制作朱莉娅更快.2.我知道python可以优化,在Cython等中实现,这不是讨论的一部分,它只是在这里为Julia和Python中的等效函数的参考.)

代码和性能结果可以在一个要点中看到.

Julia的表现明显慢于Fortran.执行计算所花费的时间是(50000个时间步长):

Fortran: 0.051s
Julia: 2.256s
Python: 30.846s
Run Code Online (Sandbox Code Playgroud)

朱莉娅比Fortran慢得多(慢44倍),差距缩小但仍然显着,时间步长增加10倍(0.50s vs 15.24s).

这些结果与julia主页上显示的结果有很大不同.我究竟做错了什么?我可以修快朱莉娅吗?

我在Julia主页上浏览了Julia Performance Tips页面和比较背后的代码,没有什么能让我解决.

同样有趣的是,Julia加载PyPlot(5secsish !!)非常慢,而且比Python读取文本文件要慢得多.我可以做些什么来改善这些事情吗?

请注意,上面的时间不显示Julia和Python的加载时间,它只是计算AFAIK所需的原始时间 - 请参阅代码.对于fortran来说,这就是整个事情.在每种情况下,绘图都已大致关闭以允许速度比较.

计算机:Intel i7-3770,16GB RAM,SSD HD,操作系统:Ubuntu 13.10 64bit.,Fortran:gfortran,GNU Fortran(Ubuntu/Linaro 4.8.1-10ubuntu9)4.8.1,Julia:版本0.3.0-prerelease + 396 (2013-12-12 00:18 UTC),提交c5364db*(0天大师),x86_64-linux-gnu,Python:2.7.5+


更新:

根据ivarne的建议,我重新编写了Julia脚本(在上面的gist中更新):在函数中封装grunt工作,声明所有内容的类型,并在适用的情况下将矩阵的不同元素拆分为不同的数组.(我在很多地方都包含了Float64,因为我尝试了Float32,看看是否有帮助,但大部分时间都没有).

结果如下:

50,000 时间步骤:

Fortran: 0.051s (entire programme)
Julia: raw calc.: 0.201s, calc. and return (?): 0.758s, total exec.: 6.947s
Run Code Online (Sandbox Code Playgroud)

500,000 时间步骤:

Fortran: 0.495s (entire programme)
Julia: raw calc.: 1.547s, …
Run Code Online (Sandbox Code Playgroud)

performance fortran fortran77 julia

35
推荐指数
2
解决办法
1万
查看次数

Fortran意图(inout)与省略意图

良好实践规定Fortran中的子例程参数应该都具有指定的意图(即intent(in),intent(out)或者如此问题intent(inout)所描述的):

subroutine bar (a, b)
    real, intent(in) :: a
    real, intent(inout) :: b
    b = b + a
    ...
Run Code Online (Sandbox Code Playgroud)

但是,未指定intent是有效的Fortran:

subroutine bar (a, b)
    real, intent(in) :: a
    real :: b
    b = b + a
    ...
Run Code Online (Sandbox Code Playgroud)

在编译时检查指定intent(inout)的参数和没有指定意图的参数之间是否存在任何真正的差异?如果我正在改进对较旧的,无意图的代码的意图,我还有什么可担心的吗?

fortran fortran90

33
推荐指数
3
解决办法
3万
查看次数

SciPy构建/安装Mac Osx

我在我的mac os x上为python 2.7.3成功构建/安装了NumPy.现在我想建立/安装scipy.我从git hub下载了它.进入目录.Ran python setup.py build,它似乎一直在工作,直到遇到这个错误:

customize Gnu95FCompiler
Could not locate executable gfortran
Could not locate executable f95
customize NAGFCompiler
customize AbsoftFCompiler
Could not locate executable f90
Could not locate executable f77
customize IBMFCompiler
Could not locate executable xlf90
Could not locate executable xlf
customize IntelFCompiler
Could not locate executable ifort
Could not locate executable ifc
customize GnuFCompiler
Could not locate executable g77
customize G95FCompiler
Could not locate executable g95
customize PGroupFCompiler
Could not locate executable pgfortran
don't …
Run Code Online (Sandbox Code Playgroud)

python macos fortran scipy python-2.7

33
推荐指数
1
解决办法
3万
查看次数

C99中的暂定定义和链接

考虑由两个文件组成的C程序,

在f1.c:

int x;
Run Code Online (Sandbox Code Playgroud)

f2.c:

int x=2;
Run Code Online (Sandbox Code Playgroud)

对C99标准第6.9.2段的解读是该程序应该被拒绝.在我对6.9.2的解释中,变量x是暂定的f1.c,但是这个暂定的定义在翻译单元的末尾变成了一个实际的定义,并且(在我看来),应该表现得好像f1.c包含了定义int x=0;.

对于所有编译器(以及重要的是,链接器)我能够尝试,这不是发生的事情.我试过的所有编译平台都链接了上面两个文件,两个文件中的值x都是2.

我怀疑这是偶然发生的,或者只是作为标准要求提供的"简单"功能.如果你考虑一下,这意味着链接器中对那些没有初始化器的全局变量有特殊支持,而不是那些显式初始化为零的全局变量.有人告诉我,无论如何编译Fortran可能都需要链接器功能.那将是一个合理的解释.

有什么想法吗?对标准的其他解释?文件f1.cf2.c拒绝链接在一起的平台名称?

注意:这很重要,因为问题出现在静态分析的上下文中.如果这两个文件可能拒绝在某个平台上链接,分析器应该抱怨,但是如果每个编译平台都接受它,那么就没有理由对它进行警告.

c fortran static-analysis compilation c99

32
推荐指数
3
解决办法
5146
查看次数

为什么首先编译为目标文件?

在去年,我开始在Fortran开设编程,在一所研究型大学工作.我之前的大部分经验都是使用PHP或旧ASP等网络语言,所以我是编译语句新手.

我有两个不同的代码我正在修改.

其中 有一个明确的声明创建的.o从模块文件中创建可执行文件之前(如gfortran -c filea.f90).

另一个直接创建可执行文件(有时创建.mod文件,但没有.o文件,例如gfortran -o executable filea.f90 fileb.f90 mainfile.f90).

  • 是否有一种理由(除了,也许是Makefiles)一种方法比另一种方法更受欢迎?

c c++ fortran compilation object-files

31
推荐指数
3
解决办法
8818
查看次数