Skip to content

Commit

Permalink
Fix #423: change -ffast-math to -mtune=native
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ftessier committed Apr 19, 2018
1 parent 98126e4 commit 2641e83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions HEN_HOUSE/gui/egs_configure/egs_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand All @@ -809,15 +809,15 @@ 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";
optimiz = "-O2";
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;
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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"){
Expand Down
4 changes: 2 additions & 2 deletions HEN_HOUSE/scripts/configure
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ for test_arg in -v; do
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"
Expand All @@ -357,7 +357,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"
Expand Down
2 changes: 1 addition & 1 deletion HEN_HOUSE/scripts/configure_c++
Original file line number Diff line number Diff line change
Expand Up @@ -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";;
Expand Down

0 comments on commit 2641e83

Please sign in to comment.