在现代时代学习FORTRAN [英] Learning FORTRAN In the Modern Era

查看:141
本文介绍了在现代时代学习FORTRAN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我来维护大量的科学计算密集型FORTRAN代码。尽管有谷歌和谷歌这样的语言,但我仍然无法处理所有这些四十年语言的细微差别。两本入门级书籍。该代码充斥着提升性能。有没有人为 de - 将FORTRAN优化为CS 101级别提供任何指南或实用建议?有没有人知道FORTRAN代码优化如何运作?是否有任何典型的FORTRAN '陷阱',可能不会发生到Java / C ++ /。NET提出开发商接管FORTRAN九十零分之七十七代码库?


解决方案

你必须得到一个感觉,让程序员必须在当天做些什么。我工作的绝大多数代码都比我年长,并且在我父母上高中的时候在新机器上运行。



常见的FORTRAN-isms我处理,伤害可读性:
$ b


  • 常见块

  • 隐式变量

  • 具有共享CONTINUE语句的两个或三个DO循环

  • GOTO代替DO循环
  • 算术IF语句
  • >
  • 计算GOTO的

  • 在一些公共块等价REAL / INTEGER /其他



解决这些问题的策略包括:


  1. 获取
  2. 将IMPLICIT NONE添加到每个子例程,然后修复每个编译错误,耗时但最终必要时,有些程序可以自动为你做这件事(或者你可以编写脚本)

  3. 将所有COMMON块移动到MODULE,值得一提的是
  4. 转换算术IF语句IF..ELSEIF..ELSE块

  5. 转换计算转移到选择CASE块

  6. 转换所有DO循环到更新的F90语法

      myloop:do ii = 1,nloops 
    !做一些
    ENDDO myloop


  7. 转换等效的公共块构件要么ALLOCATABLE存储器分配在一个模块中,或者如果它是真实的字符例程,如果它是Hollerith被存储在一个REAL中


如果你有更多关于如何完成一些可读性任务的具体问题,我可以给出建议。我有一个由几十万行Fortran代码组成的代码库,这个代码库在40年的时间里我写了一篇文章,这是我在某种程度上负责的,所以我可能遇到了你可能发现的任何问题。


I've recently come to maintain a large amount of scientific calculation-intensive FORTRAN code. I'm having difficulties getting a handle on all of the, say, nuances, of a forty year old language, despite google & two introductory level books. The code is rife with "performance enhancing improvements". Does anyone have any guides or practical advice for de-optimizing FORTRAN into CS 101 levels? Does anyone have knowledge of how FORTRAN code optimization operated? Are there any typical FORTRAN 'gotchas' that might not occur to a Java/C++/.NET raised developer taking over a FORTRAN 77/90 codebase?

解决方案

You kind of have to get a "feel" for what programmers had to do back in the day. The vast majority of the code I work with is older than I am and ran on machines that were "new" when my parents were in high school.

Common FORTRAN-isms I deal with, that hurt readability are:

  • Common blocks
  • Implicit variables
  • Two or three DO loops with shared CONTINUE statements
  • GOTO's in place of DO loops
  • Arithmetic IF statements
  • Computed GOTO's
  • Equivalence REAL/INTEGER/other in some common block

Strategies for solving these involve:

  1. Get Spag / plusFORT, worth the money, it solves a lot of them automatically and Bug Free(tm)
  2. Move to Fortran 90 if at all possible, if not move to free-format Fortran 77
  3. Add IMPLICIT NONE to each subroutine and then fix every compile error, time consuming but ultimately necessary, some programs can do this for you automatically (or you can script it)
  4. Moving all COMMON blocks to MODULEs, low hanging fruit, worth it
  5. Convert arithmetic IF statements to IF..ELSEIF..ELSE blocks
  6. Convert computed GOTOs to SELECT CASE blocks
  7. Convert all DO loops to the newer F90 syntax

    myloop: do ii = 1, nloops
        ! do something
    enddo myloop
    

  8. Convert equivalenced common block members to either ALLOCATABLE memory allocated in a module, or to their true character routines if it is Hollerith being stored in a REAL

If you had more specific questions as to how to accomplish some readability tasks, I can give advice. I have a code base of a few hundred thousand lines of Fortran which was written over the span of 40 years that I am in some way responsible for, so I've probably run across any "problems" you may have found.

这篇关于在现代时代学习FORTRAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆