Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

How to Fix: Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)

William.Hatheway

Active member
The recent releases of Ubuntu 22, Ubuntu 23, Ubuntu 24, and newer by Canonical have introduced several significant changes to their base operating system, including notable updates to the GNU Compiler Collection (GCC). Specifically, these versions have been upgraded to GCC 11 and GCC 12, respectively. These updates bring a range of improvements and new features to the compilers, enhancing performance, security, and compatibility with modern software practices.

However, these advancements come with certain challenges, particularly concerning the compatibility of legacy Fortran code. GCC versions greater than 9 have deprecated certain antiquated Fortran commands, which has led to compatibility issues during the installation and compilation of software such as the Weather Research and Forecasting (WRF) model. This is due to the default disabling of older code syntaxes in these newer GCC versions, resulting in compilation errors.

Compatibility Issues with Legacy Fortran Code​

Legacy Fortran code often contains syntax and coding practices that have been superseded or deprecated in more recent versions of the Fortran standard. When compiling such code with modern compilers like GCC 11 or GCC 12, developers may encounter errors related to argument mismatches and invalid Binary, Octal, and Hexadecimal (BOZ) literal constants. These errors can prevent the successful compilation of the WRF model and other related applications.

Addressing Compatibility with Environment Variables​

To ensure compatibility with legacy Fortran code while compiling libraries for WRF, WPS (WRF Preprocessing System), and other related software, it is necessary to set specific environment variables before the compilation process. These variables instruct the compiler to allow certain older code syntaxes, thus preventing the common errors associated with deprecated features.

The required environment variables and their values are as follows:


Bash:
export fallow_argument=-fallow-argument-mismatch
export boz_argument=-fallow-invalid-boz

export FFLAGS="$fallow_argument $boz_argument -m64"
export FCFLAGS="$fallow_argument $boz_argument -m64"

These commands configure the compiler to:

  1. Allow Argument Mismatches: The -fallow-argument-mismatch flag enables the compiler to accept argument mismatches, which are a frequent occurrence in older Fortran codes.
  2. Allow Invalid BOZ Literals: The -fallow-invalid-boz flag permits the use of invalid BOZ literal constants, another common feature in legacy Fortran code.

Consideration of the -std=legacy Flag​

Another potential solution for enabling legacy Fortran code compatibility is the use of the -std=legacy flag in GCC. This flag instructs the compiler to accept all legacy Fortran code, effectively bypassing many of the issues caused by deprecated syntax and features. However, its usage might lead to additional complications. The -std=legacy flag can allow outdated coding practices that may not be compatible with modern Fortran standards, potentially leading to unforeseen issues in the software's execution and performance.

Recommendations for Developers and Researchers​

  1. Set the Environment Variables: Use the specific environment variables (-fallow-argument-mismatch and -fallow-invalid-boz) to enable the older Fortran code syntaxes without broadly enabling all legacy features.
  2. Test Extensively: Ensure thorough testing of the compiled software to identify and address any issues that might arise from the combination of legacy code and modern compiler practices.
  3. Refer to GCC Documentation: Consult the detailed documentation and explanations of these compiler options in the GCC online documentation, particularly in the section dedicated to Fortran Dialect Options: Fortran Dialect Options (The GNU Fortran Compiler).
 
There may still be projects / dependencies that require these workarounds, however for WRF specifically versions 4.2.2 and later do not need these modifications as they are already incorporated as stopgaps. This doesn't guarantee other issues with newer compilers.

For info on this workaround in WRF's repository history please see :

 
There may still be projects / dependencies that require these workarounds, however for WRF specifically versions 4.2.2 and later do not need these modifications as they are already incorporated as stopgaps. This doesn't guarantee other issues with newer compilers.

For info on this workaround in WRF's repository history please see :


@islas

Thanks for clarifying
 
There may still be projects / dependencies that require these workarounds, however for WRF specifically versions 4.2.2 and later do not need these modifications as they are already incorporated as stopgaps. This doesn't guarantee other issues with newer compilers.

For info on this workaround in WRF's repository history please see :

Would users using the older tutorial guide and older libraries still need these extra flags?
 
Older libraries might. Older versions of WRF / tutorial guide may require these flags but as noted in one of the other threads, the make files sometimes override those variables to an internal value.

If the flags are needed for compilation of older WRF versions, modifying the configure.wrf or respective stanza in arch/configure.defaults would be the least intrusive way of guaranteeing those flags propagate down accordingly.
 
@islas I think it does, but ill double check. I thought I saw it in 4.5.2 but it may have moved in 4.6
@islas

So looking at FCCOMPAT in the configure.defaults it is empty in the /arch folder. But in my configure.wrf file it is grabbing somehow from FCFLAGS?
 

Attachments

  • Screenshot from 2024-08-16 10-30-37.png
    Screenshot from 2024-08-16 10-30-37.png
    247.9 KB · Views: 3
  • Screenshot from 2024-08-16 10-30-53.png
    Screenshot from 2024-08-16 10-30-53.png
    215.2 KB · Views: 3
Top