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

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

问题描述

我最近来维护大量的科学计算密集型 FORTRAN 代码.尽管有 google 和两本入门级书籍.该代码充斥着性能增强改进".有人对 de-将 FORTRAN 优化到 CS 101 级别有任何指南或实用建议吗?有谁知道 FORTRAN 代码优化是如何运作的?Java/C++/.NET 开发人员接管 FORTRAN 77/90 代码库时,是否有任何典型的 FORTRAN陷阱"?

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.

我处理的常见 FORTRAN 主义会损害可读性:

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

  • 常见块
  • 隐式变量
  • 两个或三个带有共享 CONTINUE 语句的 DO 循环
  • 用 GOTO 代替 DO 循环
  • 算术 IF 语句
  • 计算的 GOTO 的
  • 在一些公共块中等价 REAL/INTEGER/other

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

Strategies for solving these involve:

  1. 获取 Spag/plusFORT,物有所值,它自动解决了很多问题并且没有错误(tm)
  2. 尽可能迁移到 Fortran 90,如果不能迁移到自由格式的 Fortran 77
  3. 将 IMPLICIT NONE 添加到每个子例程,然后修复每个编译错误,虽然耗时但最终是必要的,有些程序可以自动为您完成此操作(或者您可以编写脚本)
  4. 将所有 COMMON 积木移至 MODULE,唾手可得,值得
  5. 将算术 IF 语句转换为 IF..ELSEIF..ELSE 块
  6. 将计算的 GOTO 转换为 SELECT CASE 块
  7. 将所有 DO 循环转换为较新的 F90 语法

  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

  • 将等效的公共块成员转换为在模块中分配的 ALLOCATABLE 内存,或者如果 Hollerith 存储在 REAL 中,则转换为它们的真实字符例程

  • 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

    如果您对如何完成一些可读性任务有更具体的问题,我可以提供建议.我有一个几十万行 Fortran 的代码库,它是在 40 年的时间里编写的,我在某种程度上负责,所以我可能遇到过你可能发现的任何问题".

    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天全站免登陆