Skip to content

Commit

Permalink
fix: update macros and build options for mixed precision (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
rem1776 authored Oct 6, 2023
1 parent 11be274 commit 03ee7de
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 1,527 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github_autotools_gnu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
conf-flag: [ --disable-openmp, --enable-mixed-mode, --disable-setting-flags, --with-mpi=no]
conf-flag: [ --disable-openmp, --disable-setting-flags, --with-mpi=no, --disable-r8-defaults]
input-flag: [--with-yaml, --enable-test-input=/home/unit_tests_input]
exclude:
- conf-flag: --with-mpi=no
Expand Down
43 changes: 16 additions & 27 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ AS_IF([test x${CRAYPE_VERSION:+yes} = "xyes"],[


# Process user optons.
AC_ARG_ENABLE([mixed-mode],
[AS_HELP_STRING([--enable-mixed-mode],
[Build using mixed mode. Enables both 64-bit and 32-bit reals in Fortran. This option will be ignored if --disable-fortran-flag-setting is also given.])])
AS_IF([test ${enable_mixed_mode:-no} = no],
[enable_mixed_mode=no],
[enable_mixed_mode=yes])
AC_ARG_WITH([mpi],
[AS_HELP_STRING([--with-mpi],
[Build with MPI support. This option will be ignored if --disable-fortran-flag-setting is also given. (Default yes)])])
Expand All @@ -85,12 +79,6 @@ AS_IF([test ${enable_code_coverage:-no} = no],
[enable_code_coverage=no],
[enable_code_coverage=yes])
# individual mixed precision overload macros
AC_ARG_ENABLE([overload-r4],
[AS_HELP_STRING([--enable-overload-r4],
[Enables the OVERLOAD_R4 macro to compile with 4 byte real routine overloads. (Default no)])])
AS_IF([test ${enable_overload_r4:-no} = yes],
[enable_overload_r4=yes],
[enable_overload_r4=no])
AC_ARG_ENABLE([overload-c4],
[AS_HELP_STRING([--enable-overload-c4],
[Enables the OVERLOAD_C4 macro to compile with 4 byte complex routine overloads. (Default no)])])
Expand All @@ -117,6 +105,13 @@ AS_IF([test ${enable_deprecated_io:-no} = yes],
[enable_deprecated_io=yes],
[enable_deprecated_io=no])

AC_ARG_ENABLE([r8-default],
[AS_HELP_STRING([--disable-r8-default],
[Disables the build from adding the 8 byte default real kind flag during compilation (default no)])])
AS_IF([test ${enable_r8_default:-yes} = yes],
[enable_r8_default=yes],
[enable_r8_default=no])

# user enabled testing with input files
AC_MSG_CHECKING([whether to enable tests with input files])
AC_ARG_ENABLE([test-input],
Expand Down Expand Up @@ -282,7 +277,6 @@ AC_OPENMP()
AC_LANG_POP(Fortran)

# We passed all the tests. Set the required defines.
AC_DEFINE([use_netCDF], [1], [This is required for the library to build])
if test $with_mpi = yes; then
AC_DEFINE([use_libMPI], [1], [This is required for the library to build])
fi
Expand All @@ -291,16 +285,18 @@ fi
if test $enable_deprecated_io = yes; then
#If the test pass, define use_deprecated_io macro and skip it's unit tests
AC_DEFINE([use_deprecated_io], [1], [This is required to use mpp_io and fms_io modules])
# this macro was only removed from non-deprecated code so still needs to be set
AC_DEFINE([use_netCDF], [1], [This has been removed elsewhere but is still required to build with deprecated io])
AM_CONDITIONAL([SKIP_DEPRECATED_IO_TESTS], true)
else
AM_CONDITIONAL([SKIP_DEPRECATED_IO_TESTS], false)
fi

# disable mosaic unit tests if FMS is compiled in r4
if test $enable_mixed_mode = yes ; then
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], true)
# Builds with r8 default unless disable flag is given
if test $enable_r8_default = yes; then
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], false)
else
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], false)
AM_CONDITIONAL([SKIP_MOSAIC_TESTS], true)
fi

# Set any required compile flags. This will not be done if the user wants to
Expand All @@ -314,20 +310,13 @@ if test $enable_setting_flags = yes; then
# necessary fortran flags.
AC_FC_LINE_LENGTH([unlimited])

# Will we build with default 64-bit reals in Fortran, or do mixed mode?
if test $enable_mixed_mode = yes; then
GX_FC_DEFAULT_REAL_KIND4_FLAG([dnl
FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
AC_DEFINE([OVERLOAD_R4], [1], [Set to overload the R4 Fortran routines])
AC_DEFINE([OVERLOAD_R8], [1], [Set to overload the R8 Fortran routines])
else
# Builds with r8 default unless disable flag is given
if test $enable_r8_default = yes; then
GX_FC_DEFAULT_REAL_KIND8_FLAG([dnl
FCFLAGS="$FCFLAGS $FC_DEFAULT_REAL_KIND8_FLAG"])
fi

# individual mixed precision overloads
if test $enable_overload_r4 = yes; then
AC_DEFINE([OVERLOAD_R4], [1], [Set to overload with the R4 Fortran routines])
fi
if test $enable_overload_c4 = yes; then
AC_DEFINE([OVERLOAD_C4], [1], [Set to overload with the C4 Fortran routines])
fi
Expand Down
2 changes: 0 additions & 2 deletions diag_manager/diag_axis.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ MODULE diag_axis_mod
USE diag_data_mod, ONLY: diag_axis_type, max_subaxes, max_axes,&
& max_num_axis_sets, max_axis_attributes, debug_diag_manager,&
& first_send_data_call, diag_atttype
#ifdef use_netCDF
USE netcdf, ONLY: NF90_INT, NF90_FLOAT, NF90_CHAR
#endif

IMPLICIT NONE

Expand Down
6 changes: 0 additions & 6 deletions diag_manager/diag_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ MODULE diag_data_mod
USE fms_mod, ONLY: WARNING, write_version_number
USE fms_diag_bbox_mod, ONLY: fmsDiagIbounds_type

#ifdef use_netCDF
! NF90_FILL_REAL has value of 9.9692099683868690e+36.
USE netcdf, ONLY: NF_FILL_REAL => NF90_FILL_REAL
#endif
use fms2_io_mod

IMPLICIT NONE
Expand Down Expand Up @@ -335,13 +333,9 @@ MODULE diag_data_mod

! <!-- netCDF variable -->

#ifdef use_netCDF
REAL :: FILL_VALUE = NF_FILL_REAL !< Fill value used. Value will be <TT>NF90_FILL_REAL</TT> if using the
!! netCDF module, otherwise will be 9.9692099683868690e+36.
! from file /usr/local/include/netcdf.inc
#else
REAL :: FILL_VALUE = 9.9692099683868690e+36
#endif

INTEGER :: pack_size = 1 !< 1 for double and 2 for float

Expand Down
2 changes: 0 additions & 2 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ MODULE diag_manager_mod
USE fms_diag_fieldbuff_update_mod, ONLY: fieldbuff_update, fieldbuff_copy_missvals, &
& fieldbuff_copy_fieldvals

#ifdef use_netCDF
USE netcdf, ONLY: NF90_INT, NF90_FLOAT, NF90_CHAR
#endif

!----------
!ug support
Expand Down
2 changes: 0 additions & 2 deletions diag_manager/diag_output.F90
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ MODULE diag_output_mod
USE time_manager_mod, ONLY: get_calendar_type, valid_calendar_types
USE fms_mod, ONLY: error_mesg, mpp_pe, write_version_number, fms_error_handler, FATAL, note

#ifdef use_netCDF
USE netcdf, ONLY: NF90_INT, NF90_FLOAT, NF90_CHAR
#endif

use mpp_domains_mod, only: mpp_get_UG_io_domain
use mpp_domains_mod, only: mpp_get_UG_domain_npes
Expand Down
2 changes: 0 additions & 2 deletions diag_manager/diag_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ MODULE diag_util_mod
USE constants_mod, ONLY: SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE
USE fms2_io_mod
USE fms_diag_bbox_mod, ONLY: fmsDiagIbounds_type
#ifdef use_netCDF
USE netcdf, ONLY: NF90_CHAR
#endif

IMPLICIT NONE
PRIVATE
Expand Down
59 changes: 4 additions & 55 deletions include/fms_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,8 @@ use,intrinsic :: iso_c_binding, only: c_double,c_float,c_int64_t, &
!DEC$ MESSAGE:'Using 8-byte addressing'
#endif


!Control "pure" functions.
#ifdef NO_F95
#define _PURE
!DEC$ MESSAGE:'Not using pure routines.'
#else
#define _PURE pure
!DEC$ MESSAGE:'Using pure routines.'
#endif


!Control array members of derived types.
#ifdef NO_F2000
#define _ALLOCATABLE pointer
#define _NULL =>null()
#define _ALLOCATED associated
!DEC$ MESSAGE:'Using pointer derived type array members.'
#else
#define _ALLOCATABLE allocatable
#define _NULL
#define _ALLOCATED allocated
!DEC$ MESSAGE:'Using allocatable derived type array members.'
#endif


!Control use of cray pointers.
!Control use of cray pointers within mpp_peset
!Other cray pointer usage in mpp routines is compiled regardless
#ifdef NO_CRAY_POINTERS
#undef use_CRI_pointers
!DEC$ MESSAGE:'Not using cray pointers.'
Expand All @@ -80,40 +56,13 @@ use,intrinsic :: iso_c_binding, only: c_double,c_float,c_int64_t, &
!DEC$ MESSAGE:'Using cray pointers.'
#endif


!Control size of integers that will hold address values.
!Appears for legacy reasons, but seems rather dangerous.
#ifdef _32bits
#define POINTER_KIND 4
!DEC$ MESSAGE:'Using 4-byte addressing'
#endif


!If you do not want to use 64-bit integers.
!If you do not want to use 64-bit integers.
#ifdef no_8byte_integers
#define LONG_KIND INT_KIND
#endif


!If you do not want to use 32-bit floats.
#ifdef no_4byte_reals
#define FLOAT_KIND DOUBLE_KIND
#define NF_GET_VAR_REAL nf_get_var_double
#define NF_GET_VARA_REAL nf_get_vara_double
#define NF_GET_ATT_REAL nf_get_att_double
#undef OVERLOAD_R4
#undef OVERLOAD_C4
#endif


!If you want to use quad-precision.
! The NO_QUAD_PRECISION macro will be deprecated and removed at some future time.
! Model code will rely solely upon the ENABLE_QUAD_PRECISION macro thereafer.
#if defined(ENABLE_QUAD_PRECISION)
#undef NO_QUAD_PRECISION
#else
#define NO_QUAD_PRECISION
#undef QUAD_KIND
#ifndef ENABLE_QUAD_PRECISION
#define QUAD_KIND DOUBLE_KIND
#endif

Expand Down
2 changes: 0 additions & 2 deletions mosaic/read_mosaic.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include "read_mosaic.h"
#include "constant.h"
#include "mosaic_util.h"
#ifdef use_netCDF
#include <netcdf.h>
#endif

/** \file
* \ingroup mosaic
Expand Down
8 changes: 4 additions & 4 deletions test_fms/mosaic2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ test_grid2_r8_CPPFLAGS =-DTEST_MOS_KIND_=8 $(AM_CPPFLAGS)
# These files are also included in the distribution.
EXTRA_DIST = test_mosaic2.sh

if SKIP_MOSAIC_TESTS
TESTS_ENVIRONMENT = SKIP_TESTS="test_mosaic2.1 test_mosaic2.2 test_mosaic2.3 test_mosaic2.4"
endif

# Run the test program.
TESTS = test_mosaic2.sh

if SKIP_MOSAIC_TESTS
TESTS_ENVIRONMENT = SKIP_TESTS="test_mosaic2.1 test_mosaic2.2 test_mosaic2.3 test_mosaic2.4"
endif

TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(abs_top_srcdir)/test_fms/tap-driver.sh
Expand Down
Loading

0 comments on commit 03ee7de

Please sign in to comment.