From d4c5d1011261b472c7447eebea51db7b5eb25835 Mon Sep 17 00:00:00 2001 From: Frederic Tessier Date: Thu, 19 Apr 2018 10:02:12 -0400 Subject: [PATCH] Fix #423: change -ffast-math to -mtune=native Update the default gcc optimization configuration to -mtune=native instead of -ffast-math. The latter causes various floating-point exceptions on newer cpus and compilers. Note that if everything is compiled and run on identical cpu, then the more aggressive -march=native option should be considered during configuration. Also add a test in the Fortran compiler version check to catch the gfortran version string, and fix a duplicate echo for the default fortran debugger flag. --- HEN_HOUSE/gui/egs_configure/egs_tools.cpp | 18 +++++++++--------- HEN_HOUSE/scripts/configure | 15 ++++++++++++--- HEN_HOUSE/scripts/configure_c++ | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/HEN_HOUSE/gui/egs_configure/egs_tools.cpp b/HEN_HOUSE/gui/egs_configure/egs_tools.cpp index 17ef5fd42..be6c65053 100644 --- a/HEN_HOUSE/gui/egs_configure/egs_tools.cpp +++ b/HEN_HOUSE/gui/egs_configure/egs_tools.cpp @@ -788,7 +788,7 @@ void MCompiler::init(){ dso = 0; the_name = "gfortran"; vopt = "--version"; opt = is_x86_64() ? "-fPIC" : QString(); // Only for 64-bit GNU compilers - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; deb = "-g"; eext = QString(); oflag = "-o "; @@ -809,7 +809,7 @@ void MCompiler::setLanguage(Language l){ switch(l){ case F: the_name = "gfortran"; - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; break; case C: the_name = "gcc"; @@ -817,7 +817,7 @@ void MCompiler::setLanguage(Language l){ break; case CPP: the_name = "g++"; - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; dso = new EGS_DSO(name());// Creates dso, sets flibs to -lgfortran literally dso->flibs = getFlibs2LinkCPP("gfortran",path()); break; @@ -922,7 +922,7 @@ void MCompiler::setUpCCompiler(){ optimiz = "-O3 -no-prec-div -fp-model fast=2"; } else if ( the_name.contains("gcc") ){ - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; } else{ optimiz = "-O2"; @@ -940,14 +940,14 @@ void MCompiler::setUpCPPCompiler(const QString& link_to_name){ vopt = QString(); } else if ( the_name.contains("g++") ){ - optimiz = "-O3 -ffast-math -DWIN32"; + optimiz = "-O3 -mtune=native -DWIN32"; } else if (the_name.toLower()== "icpc"){ optimiz = "-O3 -no-prec-div -fp-model fast=2 -DWIN32"; } #else if ( the_name.contains("g++") ){ - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; } else if (the_name.toLower()== "icpc"){ optimiz = "-O3 -no-prec-div -fp-model fast=2"; @@ -1034,7 +1034,7 @@ void MCompiler::setUpFortranCompiler(){ the_name.contains("g77") ){ vopt = "--version"; opt = is_x86_64() ? "-fPIC" : QString(); // Only for 64-bit GNU compilers - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; } else if (the_name == "ifl"){ vopt = "-V"; @@ -1080,7 +1080,7 @@ void MCompiler::setUpFortranCompiler(){ if ( the_name.contains("gfortran") || the_name == "g95" || the_name.contains("g77") ){ // GNU Fortran vopt = "-v --version"; opt = is_x86_64() ? "-fPIC" : QString(); // Only for 64-bit GNU compilers - optimiz = "-O3 -ffast-math"; + optimiz = "-O3 -mtune=native"; deb = "-g"; } _version = getVersion(); _version = _version.split("\n").takeFirst(); @@ -1101,7 +1101,7 @@ void MCompiler::setUpFortranCompiler(){ _version = getVersion(); _version = _version.split("\n").takeFirst(); #elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX) if ( the_name.contains("gfortran") || the_name == "g95" || the_name.contains("g77")){ // GNU Fortran - vopt = "--version"; optimiz = "-O3 -ffast-math"; deb = "-g"; + vopt = "--version"; optimiz = "-O3 -mtune=native"; deb = "-g"; opt = is_x86_64() ? "-fPIC" : QString(); // Only for 64-bit GNU compilers } else if (the_name == "ifort"){ diff --git a/HEN_HOUSE/scripts/configure b/HEN_HOUSE/scripts/configure index bb910942d..bfadc7559 100755 --- a/HEN_HOUSE/scripts/configure +++ b/HEN_HOUSE/scripts/configure @@ -340,13 +340,23 @@ for test_arg in -v; do echo $f_test_output >&5 if test -s conftest.$test_objext; then if test "x$f_test_output" != x; then + junk=$(echo $f_test_output | grep "GNU Fortran") + if test "x$junk" != x; then + f_version=$(echo $junk | grep -o -m1 'GNU Fortran [^\s]* version [0-9.]*'| head -1) + f_oflags="-O2 -mtune=native" + f_dflags="-g" + if test ! x$is_x86_64 = x; then + f_fflags="-fPIC" + fi + break + fi junk=$(echo $f_test_output | grep "GNU F77 version") if test "x$junk" != x; then junk=$(echo $junk | sed 's/.*GNU F77 version//g' | awk '{print $1}') f_version="GNU F77 version $junk" #f_fflags="-fno-automatic -finit-local-zero" # don't need this with new EGSnrc - f_oflags="-O2" + f_oflags="-O2 -mtune=native" f_dflags="-g" if test ! x$is_x86_64 = x; then f_fflags="-fPIC" @@ -357,7 +367,7 @@ for test_arg in -v; do if test "x$junk" != x; then junk=$(echo $junk | sed 's/.*GNU F95 version//g' | awk '{print $1}') f_version="GNU F95 version $junk" - f_oflags="-O2" + f_oflags="-O2 -mtune=native" f_dflags="-g" if test ! x$is_x86_64 = x; then f_fflags="-fPIC" @@ -507,7 +517,6 @@ done while true; do printf $format "Input flags for debugging: " >&2 -printf "[-g] " >&2 if test ! "x$f_dflags" = x; then printf "[$f_dflags] " >&2 fi diff --git a/HEN_HOUSE/scripts/configure_c++ b/HEN_HOUSE/scripts/configure_c++ index b8b6b4be3..1c1cece58 100755 --- a/HEN_HOUSE/scripts/configure_c++ +++ b/HEN_HOUSE/scripts/configure_c++ @@ -165,7 +165,7 @@ if test $create_config=yes; then case $CXX in - *g++*) opt="-O3 -ffast-math";;# mingw32-g++ and g++4 also taken into account + *g++*) opt="-O3 -mtune=native";;# mingw32-g++ and g++4 also taken into account icpc) opt="-O3 -no-prec-div -fp-model fast=2";; icc) opt="-O3 -no-prec-div -fp-model fast=2";; cl) opt="-Ox -Ob2 -MD -GX -GR -nologo";;