Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #423: change -ffast-math to -mtune=native #432

Merged
merged 1 commit into from
Sep 26, 2018
Merged

Conversation

ftessier
Copy link
Member

Update the default gcc optimization configuration to use -march=native
instead of -ffast-math. The latter causes various floating-point
exceptions on newer cpus and compilers. If the programs are run on a
different cpu, then one should use the corresponding -march option for
that architecture instead of "native", or else use the less aggressive
-mtune=native if the compiling and running cpus are in the same family.

The alternatives -march and -mtune were suggested by @Kawrakow in
issue #174.

See also #85, #91, #174, #204 and #423.

@marenaud
Copy link
Contributor

marenaud commented Apr 19, 2018

You should be mindful that this change will break some cluster installations of EGS. For example, many users on our cluster install/compile their own version of EGS in their home area, which is mounted on an NFS partition and shared across a heterogeneous cluster (5 nodes, 3 different generations of CPU architectures). Compiling with march=native will produce a binary that is only "valid" for the CPU architecture of the node that the user was logged in on, not other compute nodes.

In this setup, it wouldn't really be possible to compile with different architectures as the binaries would just be overwritten since it's all the same mount. (mtune will work, though I'm curious about the performance penalty of losing ffast-math and only using mtune or doing march=oldest_cpu_in_cluster)

I predict many headaches for people in charge of their department's clusters as new users install EGS from the github repo and have code that runs fine interactively but crashes when they submit batch jobs to their cluster.

@ftessier
Copy link
Member Author

ftessier commented Apr 19, 2018

Very good point @marenaud. Then I suggest settling for -mtune=native (or even -mtune=generic) which is backward compatible within cpu families, or else just leave out -ffast-math and -m options entirely in the default configuration (and provide some guidance about these optimization options in the installation instructions). At any rate -ffast-math does not seem like a safe default any more.

@marenaud
Copy link
Contributor

marenaud commented Apr 19, 2018

Agreed, alternatively we could also look at which flag is causing issues. According to the gcc website, -ffast-math is equivalent to:

-fno-trapping-math, -funsafe-math-optimizations, -ffinite-math-only, -fno-errno-math, -fno-signaling-nans, -fno-rounding-math, -fcx-limited-range and -fno-signed-zeros

If we're lucky, maybe only one of these is causing all the trouble. Not sure I would count on that though...

@ftessier
Copy link
Member Author

I would not count on that either! I think -mtune=native is a reasonable default, since an environment with different cpu families is unlikely, and one must then anyways handle multiple executables. I will update this pull request with -mtune.

@ftessier ftessier force-pushed the fix-fast-math branch 2 times, most recently from b30d5f7 to 2641e83 Compare April 19, 2018 17:01
@ftessier
Copy link
Member Author

Just added -mtune=native to the default fortran optimization options in the configure script.

@rtownson rtownson changed the title Fix #423: change -ffast-math to -march=native Fix #423: change -ffast-math to -mtune=native Apr 19, 2018
@ftessier ftessier force-pushed the fix-fast-math branch 2 times, most recently from b3a7f71 to d4c5d10 Compare September 26, 2018 13:41
@mainegra
Copy link
Contributor

@ftessier this must be also added to the config GUI!

@ftessier
Copy link
Member Author

I think it has, see changes in egs_tools.cpp. Can you check if I missed anything?

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.

Change the default optimization level to -O2 instead of -O3. There have
been cases where upgrading to a newer compiler revealed bugs under -O3,
and more aggressive optimization does not always lead to increased
performance. The -O2 option is a better default, and another level can
be selected at configuration time.

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.
@ftessier
Copy link
Member Author

Also changed the default optimization level from -O3 to -O2

@ftessier ftessier merged commit 37650ea into develop Sep 26, 2018
@ftessier ftessier deleted the fix-fast-math branch September 26, 2018 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants