Intel Fortran to GNU Fortran Conversion [closed]

╄→гoц情女王★ 提交于 2021-02-08 10:33:26

问题


I am working on a custom CFD Solver written in Fortran 90 and MPI. The code contain 15+ Modules and was initially designed to work with the Intel Fortran compiler. Now since i do not have access to the Intel compiler I need to make it work using the GNU Fortran Compiler.

I made changes in the Makefile that initially had flags suitable for the ifort. I am using it on Ubuntu with GNU Fortran and Openmpi

I am sorry I am unable to put in anything from the code structure or terminal output due to IP restrictions of my university. Nevertheless,I will try to best describe the issues

So now when I compile the code I am having some strange issues.

  1. The GNU Fortran is not able to read lines that are too long and I get errors during compilation. As a result I have to break it into multiple lines using the '&' symbol

  2. A module D.f90 contains all the Global variables declared. However, now I during compilation i get error is in module B.F90. The error I get is 'Unclassified Statement Error', I was able to fix it in some subroutines and functions by locally declaring the variables again.

I am not the most experienced person in Fortran, but I thought that the change in compiler should not be a reason for new found syntax errors.

The errors described above so far could be remedied but considering the expanse of the code it is impractical.

I was hoping if anyone could share views on this matter and provide guidance on how to tackle it.


回答1:


You should start reading three pieces of documentation:

  • The Fortran 90 standard (alternatively, other versions), which tells you what is legal, standard Fortran and what is not. Whenever you find some error, look at your code and check if what you are doing is legal, standard Fortran. Likely, the code in question will either be completely nonstandard (e.g. REAL*8, although that extension is fairly well understood) or rely on unspecified behaviour that Intel Fortran and GFortran are interpreting in different ways.
  • The GFortran manual for your version, which tells you how GFortran decides such unspecified cases, what intrinsic functions are available, how to change some options/flags, etc. This would tell you that your problem with the line lengths would be solved by adding -ffree-line-length-none.
  • The Intel Fortran manual for your version, which in cases of non-standard or unspecified behaviour, will allow you to know what the code you are reading was written to do, e.g. the behaviour that you would expect. In particular, it will allow you to decipher what the compiler flags that are currently being used mean. They may or may not need translation to GFortran, e.g. /Qsave will need to become -f-no-automatic.

A concrete example of interpretative differences within the range allowed be the standard: until Fortran 2003, the units for the "record length" in random access record files were left unspecified. Intel Fortran used "one machine word" (4 bytes in x86) while GFortran used 1 byte. Both were compliant with the standard letter, but incompatible.

Furthermore, even when coding "to standard", you may hit a wall if the compiler does not implement part of the Fnn standard, or it is buggy. Case in point: Intel Fortran 12.0 (old, but it's what I work with) does not the implement the ALLOCATE(y, SOURCE=x) construct for polymorphic x (the "clone allocation"). On the other hand, GFortran has not completely implemented FINAL type-bound procedures (destructors).

In both cases, you will need to find workarounds. For example, for the first issue you can use a special form of the INQUIRE statement (kudos to @haraldkl). In other cases, the workaround might even involve using some kind of feature detection (see autoconf, CMake, etc.) and storing the results as PARAMETER variables in a config.f90 file that is included by your code. Your code would then take decisions based on it, as in:

! config.f90.in (things in @x@ would get subtituted by automake, for example)
INTEGER, PARAMETER :: RECORD_LEN_BYTES = @RECORD_LEN_BYTES@

! Some other file which opens a file
INCLUDE "config.f90"
!...
OPEN(u, FILE='DE430.BIN', ACCESS='direct', FORM='unformatted', RECL=56 / RECORD_LEN_BYTES)



回答2:


People have been having complaints about following the standard since at least the 60s. But those cDEC$ features were put in a for good reasons...

It is valuable to cross compile though and you usually have things caught in one compiler or the other.

For you question #1 "The GNU Fortran is not able to read lines that are too long and I get errors during compilation. As a result I have to break it into multiple lines using the '&' symbol"

In the days of old there was:

options/extended_source
SUBROUTINE...

In fort it is -132, but I have not found a gfortran equivalent to -132 . It may be -ffixed-line-length-n -ffixed-line-length-none -ffree-line-length-n -ffree-line-length-none per the link: http://www.math.uni-leipzig.de/~hellmund/Vorlesung/gfortran.html#SEC8

Also the ifort standard for .f90 and .f95 is the the compiler switch '-free' '-fixed' is the standard <.f90... However one can use -fixed with .f90 and use column 6 and 'D' in column #1... Which is handy with '-D_lines' or '-DD'. Per the link: https://software.intel.com/sites/default/files/m/f/8/5/8/0/6366-ifort.txt

For you question #2: "A module D.f90 contains all the Global variables declared. However, now I during compilation i get error is in module B.F90. The error I get is 'Unclassified Statement Error', I was able to fix it in some subroutines and functions by locally declaring the variables again." You probably need to put in the offending line, if you can get an IP waiver.

Making variables local if they are expected to be shared in a /common/ or shared in a module will not work. If there were in /common/ or PUBLIC then they are shared. If they are local then they are PRIVATE.

it would be easy to get that error if a PRIVATE statement was in the wrong place, or a USE statement was omitted.



来源:https://stackoverflow.com/questions/38597527/intel-fortran-to-gnu-fortran-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!