Skip to content

logical(c_bool) support with PORTABLE_KINDS #1645

@mlee03

Description

@mlee03

Is your feature request related to a problem? Please describe.
When FMS is compiled with -DPORTABLE_KINDS, r4_kind and r8_kind are set so that r4_kind=c_float and r8_kind=c_double where c_float and c_double are defined in the iso_c_binding module. Such portability for logicals are however not implemented to take into account booleans of 1 byte size in C and logicals of the size of integers in Fortran, which defaults to 4 bytes unless flags along the lines of -fdefault-integer-8 is defined. Thus, when a logical argument is sent from C to Fortran, explicit conversion, fortran_logical = logical(c_logical), is required.

Describe the solution you'd like
This issue proposes to modify all logical variable declarations so that the size of logicals are explicitly defined. For example, current code such as

subroutine fsubroutine( logical_arg ) 
      logical , intent(in):: logical_arg

will be modifed such that

subroutine fsubroutine( logical_arg ) 
      logical(log_kind) , intent(in):: logical_arg

All logicals in derived types will similarly be modified. In include/platform.h, the following will be set: LOGICAL_KIND = c_bool for PORTABLE_KINDS or LOGICAL_KIND = INT_KIND of 4 bytes as default. Then in platform/platform.F90, log_kind = LOGICAL_KIND will be defined. By this implementation, logical kinds will always be of 4 bytes for non-portable-kinds usage.

Describe alternatives you've considered
Leave as is and explicitly convert logicals.

Additional context
This change would be a nice feature for cFMS development. This issue will not address adding additional mpp subroutines for c_bool logicals to the existing set of subroutines such as mpp_alltoall_logical4 and mpp_alltoall_logical8

Metadata

Metadata

Labels

enhancementIssue/PR for a modification that increases performance, improves syntax, or adds functionality.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions