Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Introduction

 Click here to expand...

Radioss is mostly written using Fortran language, Fortran77 and Fortran90 https://fortran-lang.org

A few low level routines are written in C

Thanks to architecture convergence, x86-64 under Linux and Windows, Radioss compilation relies on Intel compilers ifort and icc

The aim of this document is not to paraphrase the Fortran documentation but to give clear recommendations and advices about developing Radioss code

OpenRadioss contributors should read and understand this documentation and apply the rules defined hereafter

Radioss development should be focused towards performance and efficiency of the code written. Recommendations to help write efficient code are widely explained throughout these pages

Programming Languages

 Click here to expand...

Fortran Language

Fortran90 is the programming language used for Radioss development, including memory management (since the Altair commercial Radioss release v51)

The documentation of this compiler is given here:

https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top.html?wapkw=fortran%20compiler%20developer%20guide

https://software.intel.com/en-us/intel-fortran-compiler-17.0-user-and-reference-guide

Fortran95, Fortran2003, Fortran2008 and future extension should be avoided. More clearly, any extension of Fortran90 is forbidden unless it is approved by OpenRadioss development management and motivation is clearly explained. In such case, these programming guidelines will be amended accordingly

C Language

C routines deal with low level I/O, system calls, library interface (CUDA) only Reference manual:

 https://software.intel.com/en-us/intel-cplusplus-compiler-17.0-user-and-reference-guide

Precompiler Directives

 Click here to expand...

Fortran files are of type foo.F. Fortran precompiler is automatically called

Therefore, it is forbidden to name a file .f or .f90

 In particular the below directives are in use: 

Examples:

#include to include specific files or commons

#include "implicit_f.inc"

 #define

 #define my_real DOUBLE PRECISION

#ifdef mainly used to define platform specific code

IMPLICIT NONE

 Click here to expand...

For historical reasons, (in the past it was not supported everywhere) IMPLICIT NONE is automatically added to the source via a specific include implicit_f.inc. Its usage forces the programmer to declare every variable

 Every Radioss Fortran routine needs to include implicit_f.inc

Fixed Format

 Click here to expand...

To keep coherency between original code and new code, only fixed format is allowed, extended to 132 columns

Comments need to begin with "!"

They can be placed anywhere

("C" and "*" are still supported in first position)

Several instructions per line are allowed using ";"

Fortran95, Fortran2003, Fortran2008 Extensions

 Click here to expand...

Intrinsic functions are allowed, especially NULL() and CPU_TIME() are allowed

Other Fortran95 extensions are refused

Fortran2003 and Fortran2008 extensions are refused

Fortran 90 Restrictions

 Click here to expand...

Object oriented features like operator overloading are forbidden as they can highly penalize performance

Array manipulation, and especially non-contiguous section as subroutine argument is forbidden (assumed-shape-array)

Array reduction and special functions like MAXLOC/MINLOC/MAXVAL/MINVAL/SHAPE, ... need to be used with care as their performance is compiler dependent

Fortran 77 Extensions

 Click here to expand...

Fortran77 extensions which are not Fortran90 standard are refused

Obsolete Fortran 77 coding

 Click here to expand...

EQUIVALENCE

EQUIVALENCE is source of error. The use of EQUIVALENCE is forbidden

Use MODULE variables instead.

There is an ongoing effort to clean out the remaining instances in the code

COMMON

COMMON is a source of error, use MODULE variables instead

For new development, MODULE should be used instead of COMMON

Current/existing COMMON are maintained but one should avoid adding any new variables to existing COMMON

SAVE

SAVE statement is forbidden. It needs to be replaced by variables in MODULE

Multiple RETURN

Multiple RETURN statements inside a SUBROUTINE are forbidden

GOTO

The use of GOTO is forbidden. Existing GOTO statements are progressively being removed from the code

DO loop with label

DO loop with label is prohibited

Data Types

 Click here to expand...

Integer

All integers are by default 32-bit integers (INTEGER)

Where it is required 64-bit integer (INTEGER8) can be used explicitly

Use of INTEGER8 in the code is limited to such specific usage

Real

Reals can be either 32-bit simple precision or 64-bit double precision reals

Real variables need to be declared as MY_REAL or my_real

my_real.inc is automatically included together with implicit_f.inc to define MY_REAL macro

The pre-compiler automatically replaces MY_REAL by DOUBLE PRECISION or REAL depending on the R4R8 flag defined in the makefile:

R4R8=r8 : my_real is transcribed to Fortran DOUBLE PRECISION for double precision version of Radioss

R4R8=r4 : my_real is transcribed to Fortran REAL for extended single precision version of Radioss

Example:

my_real, INTENT(OUT) :: RES

For some exceptions, it is sometimes needed to explicitly use REAL or DOUBLE PRECISION for variables that need to stay in single or double precision independently of the Radioss precision version

Such exceptions are limited in the source code

Logical

LOGICAL operators are restricted to .NOT., .AND., .OR., .EQV., .NEQV.

In particular, it is forbidden to use “==" with LOGICAL, .EQV. needs to be used instead

Derived data type

Derived data type is one of the main improvements of Fortran90 standard

The use of derived data types is strongly encouraged (see OpenRadioss Coding Recommendations ).

Derived data type allows to define new structured types

The name of a new type should use suffix _STRUCT_

Example:

! Example of data structure definition
        TYPE DUMMY_STRUCT_
          INTEGER :: L_ITAB ! size of ITAB
          INTEGER :: L_RTAB ! size of RTAB
          INTEGER, DIMENSION(:) , POINTER ::  ITAB ! integer pointer
          my_real, DIMENSION(:) , POINTER ::  RTAB ! real pointer
        END TYPE DUMMY_STRUCT_

! Definition of a variable of type DUMMY_STRUCT_
     TYPE(DUMMY_STRUCT_), INTENT(INOUT) :: MY_DUM 

! Use of the variable MY_DUM
      MY_DUM%L_ITAB = NITEMS1
      MY_DUM%L_RTAB = NITEMS2
      ALLOCATE(MY_DUM%ITAB(MY_DUM%L_ITAB),MY_DUM%RTAB(MY_DUM%L_RTAB),
     &         STAT=ierror)

Intrinsic functions

Programmers are only allowed to use generic functions compatible with both single and double precision: SQRT, SIN, COS, MAX, MIN, LOG, EXP, ...

Explicitly typed functions are prohibited: DSQRT, DSIN, DCOS, AMAX1, AMAX0, AMIN1, DMAX1, DLOG, DEXP, ...

Numerical constants

All real constant variables are declared inside constant.inc common and initialized using INICONSTANT routine (iniconstant.F)

Examples:

Forbidden:

A = MAX(B,1.E-20)
CALL SUB(0.,2.*A)

Allowed:

A = MAX(B,EM20)
CALL SUB(ZERO,DEUX*A)

EM20, ZERO and DEUX declared in constant.inc and initialized by INICONSTANT

Zero & infinite values

To avoid division by zero, it is advised to test against EM20

To avoid infinite value test against EP20

These values are generally a good compromise for both double and single precision

It is always possible to check version precision using flag IRESP

IRESP=1: Double Precision version

IRESP=0: Extended Single Precision version

Bitwise logical operations

Semantic of bitwise logical operators like AND, XOR, may vary from one compiler to another. It is advised to use C emulation functions

Note: my_and, my_or, my_shift already exist

Interfacing Fortran and C

 Click here to expand...

Calling convention

There is no standard calling convention between Fortran and C

Here is described the way it is handled in Radioss by defining every potential calling convention

Notice that the importance of this specific point is decreasing with the number of architectures and compilers supported

Fortran 90 calling routine:

...
INTEGER :: L
my_real :: A(*)
...
CALL DUMMY(A,L)
...

C callee routine:

void dummy(a,l)
double *a;
int *l;
{
/* dummy function definition */
...
}
void dummy_(a,l)
double *a;
int *l;
{
dummy(a,l);
}
void _FCALL DUMMY(a,l)
double *a;
int *l;
{
dummy(a,l);
}

Note:

dummy, dummy_ and DUMMY share the 3 possible formats encountered 

Argument variable correspondence

Fortran

C

INTEGER

*int

REAL

*float

DOUBLE PRECISION

*double

Notes:

A variable of type my_real is never transferred from Fortran to C directly, It is copied into a REAL or DOUBLE PRECISION variable first

Variable of type CHARACTER should not be transferred from Fortran to C directly, It is mandatory to use INTEGER conversion through conversion function ICHAR at Fortran level and type (char) at the C level

Every variable is passed by address at Fortran level, therefore a pointer variable must match at the C level

Examples of type definition under Linux and Windows

Type

Linux, Windows

Size in Bytes

INTEGER

4

INTEGER8

8

REAL

4

DOUBLE PRECISION

8

REAL*4

4

REAL*8

8

Char

1

short

2

int

4

long

4

long long

8

float

4

double

8

Specific code management

 Click here to expand...

For some reason, some code may depend on a specific architecture or compiler. In this case, such code is gathered into a unique directory (one for Starter and one for Engine) called spe and spe_inc for include files

The rest of the code needs to be machine independent. This facilitates porting to new machine or compiler

The specific part of the code is managed by the precompiler using #ifdef directives depending on the compiling architecture

The different supported architectures are defined under hardware.inc

A clean up of the supported architecture must be scheduled

  • No labels