From 96dea914279283e081ae6dc2be6fdb78a6ee9556 Mon Sep 17 00:00:00 2001 From: noel Date: Mon, 24 Apr 2017 11:36:23 -0700 Subject: [PATCH] Disable FP checks for a certain LAPACK routine, by using ieee_exceptions module to turn off FP trapping that is enabled by -fpe0. Only for DEBUG builds, only for cori-knl, and only for Intel compiler. Fixes #1183 [BFB] --- .../config/acme/machines/config_compilers.xml | 3 +-- .../cam/src/physics/clubb/lapack_wrap.F90 | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cime/config/acme/machines/config_compilers.xml b/cime/config/acme/machines/config_compilers.xml index b9da2ab61ef7..9c9c205be12b 100644 --- a/cime/config/acme/machines/config_compilers.xml +++ b/cime/config/acme/machines/config_compilers.xml @@ -596,8 +596,7 @@ for mct, etc. -L$(NETCDF_DIR) -lnetcdff -Wl,--as-needed,-L$(NETCDF_DIR)/lib -lnetcdff -lnetcdf -mkl -lpthread -lm -DHAVE_PAPI - -DHAVE_SLASHPROC - + -DARCH_MIC_KNL -DHAVE_SLASHPROC ftn cc CC diff --git a/components/cam/src/physics/clubb/lapack_wrap.F90 b/components/cam/src/physics/clubb/lapack_wrap.F90 index f1282703b91b..ac7246d48d15 100644 --- a/components/cam/src/physics/clubb/lapack_wrap.F90 +++ b/components/cam/src/physics/clubb/lapack_wrap.F90 @@ -218,7 +218,11 @@ subroutine tridag_solve & use clubb_precision, only: & core_rknd ! Variable(s) - +#ifndef NDEBUG +#if defined(ARCH_MIC_KNL) && defined(CPRINTEL) + use, intrinsic :: ieee_exceptions +#endif +#endif implicit none ! External @@ -268,8 +272,20 @@ subroutine tridag_solve & !----------------------------------------------------------------------- if ( kind( diag(1) ) == dp ) then - call dgtsv( ndim, nrhs, subd(2:ndim), diag, supd(1:ndim-1), & +#ifndef NDEBUG +#if defined(ARCH_MIC_KNL) && defined(CPRINTEL) + ! when floating-point exceptions are turned on, this call was failing with a div-by-zero on KNL with Intel/MKL. Solution + ! was to turn off exceptions only here at this call (and only for machine with ARCH_MIC_KNL defined) (github 1183) + call ieee_set_halting_mode(IEEE_DIVIDE_BY_ZERO, .false.) ! Turn off stopping on div-by-zero only +#endif +#endif + call dgtsv( ndim, nrhs, subd(2:ndim), diag, supd(1:ndim-1), & rhs, ndim, info ) +#ifndef NDEBUG +#if defined(ARCH_MIC_KNL) && defined(CPRINTEL) + call ieee_set_halting_mode(IEEE_DIVIDE_BY_ZERO, .true.) ! Turn back on stopping on div-by-zero only +#endif +#endif else if ( kind( diag(1) ) == sp ) then call sgtsv( ndim, nrhs, subd(2:ndim), diag, supd(1:ndim-1), &