Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29237 Discussions

using ifort to improve code robustness

mkbane
Beginner
1,325 Views
I have legacy F77 code that I wish to improve the robustness and portability thereof, making the ifort compiler take as much of the strain as possible.

For example, I am removing 'IMPLICIT REAL*8(A-H,O-Z)' and require explicit typing of all variables. Is there an easy way that the ifort compiler (or another Intel tool) can help? At the moment I'm just compiling with IMPLICIT NONE then adding by add each variable that the compiler claims is used but not declared.

Secondly, there will be areas of code where variables are assigned but not used. It would be nice to remove these areas altogether from the source code. I know that ifort -O2 will perform dead code elimination and I can see from -opt-report than some stuff is being removed but is it possible to the the compiler to spit out which lines/variables/basic blocks are being removed?

Many thanks, Michael, Univ of Manchester
0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
1,325 Views

Using IMPLICIT NONE then on variable by variable basis is likely the best method since this will provide you with a case by case analysis as to if the 'IMPLICIT REAL*8(A-H,O-Z)' was potentially a cause for a problem in the first place (e.g. a temporary was created and used when it was not intended to be createdand used, or wrong type used). Any automatic tool would produce the same symptom in your program. Yes, this is work, if you learn how to use macro capabilities of your editor (assuming it has macro capabilities), then conversion work might be relatively fast (e.g. F8 toplace variable nameat cursor into paste buffer, insert find me later token into code, search backwards to IMPLICIT, advance line, insert 'REAL*8 :: ', paste paste buffer, insert new line, search for and delete find me later token. F4 for REAL*4, Alt-F8 forarray declaration, etc...

For unused variables, enable the FPP, and place #if 0 and #endif around your declarations.Compile, get errors (form IMPLICIT NONE) then move appropriate declarations outside of scope of #if 0.

This goes relatively fast.

Your goal is not only robustness but correctness of code. Take the time to do it right.

Also, I strongly suggest using INTERFACE declarations.

Jim Dempsey
0 Kudos
mkbane
Beginner
1,325 Views

Using IMPLICIT NONE then on variable by variable basis is likely the best method since

yeah was hoping there was a quicker/easier way...

another Q that springs to mind is how to tell ifort to EXCLUDE extensions (cf gfortran -pedantic) - I've an example that ifort -warn all compiles without any warning/error whereas gfortran -pedantic picks up the use of extensions

ta, Michael
0 Kudos
Kevin_D_Intel
Employee
1,325 Views

The -stand {keyword} option might help. You select a Standard to be applied via {keyword} = f90, f95, or f03
0 Kudos
roddur
Beginner
1,325 Views
if you learn how to use macro capabilities of your editor (assuming it has macro capabilities), then conversion work might be relatively fast (e.g. F8 toplace variable nameat cursor into paste buffer, insert find me later token into code, search backwards to IMPLICIT, advance line, insert 'REAL*8 :: ', paste paste buffer, insert new line, search for and delete find me later token. F4 for REAL*4, Alt-F8 forarray declaration, etc...

For unused variables, enable the FPP, and place #if 0 and #endif around your declarations.Compile, get errors (form IMPLICIT NONE) then move appropriate declarations outside of scope of #if 0.

Jim Dempsey
Dear Jim,
can you manage time to elaborate this? I think it will be of much help, and if possible, not start with a IDE
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,325 Views

By macros I mean editor or IDE keyboard macro capability. Most mature editors have a capability of executing macros. I.e. you press a Hot-Key or Fn key (with/without Shift, Ctrl, Alt, left and right varients) and it executes the specified macro. In this case you write the macro. After your initial edits your program will likely be

subroutine YourSubroutine()
implicit none
...
end subroutine YourSubroutine

Compiling the above you might receive an error

A = B + C
^ undefined symbol

and a whole bunch of additional errors.

In the IDE both the source window and error message windows are open. When clicking on the line in the error message window, the edit window positions to the line in error. Your development system may have a similar capability. Assuming it does. If you place the cursor within or at the beginning of the symbol in error (A in this case) and if you write a macro to functionally perform the following

goto(beginningOfWord)
mark
goto(endOfWord)
copy
insert('***here***')
searchBackwards('implicit none')
advance line
insert('real :: ')
paste
insert('n')
replace('***here***','')

This macro is assigned to the one you want to use for REAL(4), or REAL
You setup a similar one for REAL(8), INTEGER, LOGICAL, etc...

Most macro systems permit you to record keystrokes to generate the macro. Many macro systems use a scripting language (Linux/Mac may use Python). These macros can often be written to a file for use in every edit session.

The editing session (once macros built)

compile
repeat until done
click on error line to goto source line in error
decide what the variable type should be an if macro available to perform edit
execute macro or hand edit if macro not available
end repeat

compile
...

Jim Dempsey

0 Kudos
Reply