Skip to main content

Himeno modernization

Goal

Learn how to use Codee to modernize Himeno, a fluid analysis simulation code.

info

This guide is part of the NERSC + Codee Training Series 2024. Code available for download at the previous link.

Getting started

First, navigate to the source code for Himeno:

cd codee-demos/Fortran/Himeno

Next, load the latest Codee version available on Perlmutter:

module load codee/2024.3.1

Walkthrough

1. Run the screening report

To explore the recommendations of the Open Catalog that are applicable to Himeno, let's run Codee's screening report:

Codee command
codee screening -- gfortran himeno.f90
Codee output
Date: 2024-09-05 Codee version: 2024.3.1 License type: Modern
Compiler invocation: gfortran himeno.f90

[1/1] himeno.f90 ... Done

SCREENING REPORT

---Number of files---
Total | C C++ Fortran
----- | - --- -------
1 | 0 0 1

Lines of code Analysis time # checks Profiling
------------- ------------- -------- ---------
214 303 ms 18 n/a

Lines of code : total lines of code found in the target (computed the same way as the sloccount tool)
Analysis time : time required to analyze the target
# checks : total actionable items (opportunities, recommendations, defects and remarks) detected
Profiling : estimation of overall execution time required by this target

RANKING OF CHECKERS

Checker Priority AutoFix # Title
------- -------- ------- - ------------------------------------------------------------------------------------------------
PWR068 P27 (L1) 6 Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
PWR063 P12 (L1) 1 Avoid using legacy Fortran constructs
PWR069 P3 (L3) 6 Use the keyword only to explicitly state what to import from a module
PWR001 P3 (L3) 5 Declare global variables as function parameters

SUGGESTIONS

Use 'roi' to get a return of investment estimation report:
codee roi -- gfortran himeno.f90

Use 'checks' to find out details about the detected checks:
codee checks -- gfortran himeno.f90

1 file, 7 functions, 5 loops successfully analyzed (18 checkers) and 0 non-analyzed files in 305 ms

2. Run the checks report

Follow the suggestions to generate Codee's checks report, which helps identify all places in the code where each check is applicable:

Codee command
codee checks -- gfortran himeno.f90
Codee output
Date: 2024-09-05 Codee version: 2024.3.1 License type: Modern
Compiler invocation: gfortran himeno.f90

[1/1] himeno.f90 ... Done

CHECKS REPORT

himeno.f90:136:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:164:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:223:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:255:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:275:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:325:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90 [PWR063] (level: L1): Avoid using legacy Fortran constructs
himeno.f90:136:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:164:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:223:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:255:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:275:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:67:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:136:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:164:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:223:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:255:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:275:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module

SUGGESTIONS

Use --verbose to get more details, e.g:
codee checks --verbose -- gfortran himeno.f90

Use --check-id to focus on specific subsets of checkers, e.g.:
codee checks --check-id PWR068 -- gfortran himeno.f90

1 file, 7 functions, 5 loops successfully analyzed (18 checkers) and 0 non-analyzed files in 249 ms

We can also run the detailed output of the checks report (option --verbose) to obtain more information about each suggestion. This detailed output includes links to the Open Catalog, along with the precise location in the source code.

As an example, let's focus on the checker PWR063, related to replacing legacy Fortran constructs:

Codee command
codee checks --check-id PWR063 --verbose -- gfortran himeno.f90
Codee output
Date: 2024-09-05 Codee version: 2024.3.1 License type: Modern
Compiler invocation: gfortran himeno.f90

[1/1] himeno.f90 ... Done

CHECKS REPORT

himeno.f90 [PWR063] (level: L1): Avoid using legacy Fortran constructs
PAUSE:
131: pause
Suggestion: Remove the legacy fortran constructs and refactor the code to comply with modern Fortran standards.
Documentation: https://github.com/codee-com/open-catalog/tree/main/Checks/PWR063

1 file, 7 functions, 5 loops successfully analyzed (1 checker) and 0 non-analyzed files in 259 ms

3. Apply the modernization suggestion

Follow Codee's suggestion to remove the legacy Fortran construct that has been identified on line 131 (PAUSE). In this particular case, we can comment or remove the affected line, since the execution stops right after.

Let's run the checks report once again to verify that PWR063 is no longer triggered for Himeno:

Codee command
codee checks -- gfortran himeno.f90
Codee output
Date: 2024-09-05 Codee version: 2024.3.1 License type: Modern
Compiler invocation: gfortran himeno.f90

[1/1] himeno.f90 ... Done

CHECKS REPORT

himeno.f90:136:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:164:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:223:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:255:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:275:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:325:1 [PWR068] (level: L1): Encapsulate external procedures within modules to avoid the risks of calling implicit interfaces
himeno.f90:136:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:164:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:223:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:255:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:275:1 [PWR001] (level: L3): Declare global variables as function parameters
himeno.f90:67:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:136:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:164:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:223:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:255:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module
himeno.f90:275:1 [PWR069] (level: L3): Use the keyword only to explicitly state what to import from a module

SUGGESTIONS

Use --verbose to get more details, e.g:
codee checks --verbose -- gfortran himeno.f90

Use --check-id to focus on specific subsets of checkers, e.g.:
codee checks --check-id PWR068 -- gfortran himeno.f90

1 file, 7 functions, 5 loops successfully analyzed (17 checkers) and 0 non-analyzed files in 247 ms

As can be seen above, PWR063 is no longer triggered.