Skip to content

Commit bfd82fe

Browse files
committed
configure: do not set -march by default
1 parent b8ac0d5 commit bfd82fe

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

configure

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ ENVIRONMENT VARIABLES
8686
8787
ARCH
8888
the specific CPU architecture to compile for. This variable will be
89-
passed to the compiler using -march=$ARCH. If set to an empty string,
90-
no -march flag will be passed to the compiler. The default is
91-
'native'.
89+
passed to the compiler using -march=$ARCH. You can use 'ARCH=native' to
90+
get the best performance for your system. Note that this will result in
91+
executables that may not run on other systems if the same CPU
92+
extensions are not available.
9293
9394
CFLAGS
9495
Any additional flags to the compiler.
@@ -515,11 +516,6 @@ if 'ARCH' in os.environ.keys():
515516
if march:
516517
report ('Machine architecture set by ARCH environment variable to: ' + march + '\n')
517518
cpp_flags += [ '-march='+march ]
518-
else:
519-
report ('Empty ARCH string found: will not pass -march flag to compiler.\n')
520-
else:
521-
if system != 'darwin':
522-
cpp_flags += [ '-march=native' ]
523519

524520

525521

docs/installation/linux_install.rst

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,34 @@ compile *MRtrix3* on a modern distro (within a virtual machine for
204204
example), package it up, and install it on any Linux system without
205205
worrying about dependencies.
206206

207-
Important: setting the CPU architecture
208-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209-
210-
By default, ``configure`` will cause the build script to generate code
211-
suitable to run on your current CPU (using the ``-march=native``
212-
option). This means the executables will likely *not run* on a different
213-
CPUs with different instruction sets, resulting in 'illegal instruction'
214-
runtime errors. If you intend to run *MRtrix3* on a variety of different
215-
systems with a range of CPUs, or you have no idea what the CPU is on
216-
your target system, it is safest to specify an empty (generic) architecture
217-
when configuring *MRtrix3*, before invoking ``./build``::
218-
219-
ARCH= ./configure
207+
Setting the CPU architecture for optimal performance
208+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209+
210+
By default, ``configure`` will cause the build script to produce generic code
211+
suitable for any current CPU. If you want to ensure optimal performance on your
212+
system, you can request that ``configure`` produce code tailored to your
213+
specific CPU architecture, which will allow it to use all available CPU
214+
instructions and tune the code differently. This can improve performance
215+
particularly for linear algebra operations as `Eigen
216+
<http://eigen.tuxfamily.org>`__ will then make use of these extensions.
217+
However, note that this means the executables produced will likely *not run* on
218+
a different CPUs with different instruction sets, resulting in 'illegal
219+
instruction' runtime errors. If you intend to run *MRtrix3* on a variety of
220+
different systems with a range of CPUs, or you have no idea what the CPU is on
221+
your target system, it is safest to avoid changing the default.
222+
223+
Specifying a different CPU architecture is done by setting the ``ARCH`` environment
224+
variable prior to invoking ``./configure``. The value of this variable will
225+
then be passed to the compiler via the ``-march`` option. To get the best
226+
performance *on the current system*, you can specify ``native`` as
227+
the architecture, leaving it up to the compiler to detect your particular CPU
228+
and its available instructions. For example::
229+
230+
export ARCH=native
231+
./configure
220232
./build
221233

222-
For more specific architectures, you can provide any values from the `list of
234+
For more specific architectures, you can provide any value from the `list of
223235
specifiers understood by the compiler
224236
<https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/x86-Options.html#x86-Options>`_,
225237
for example ``ARCH='sandybridge' ./configure``
@@ -238,7 +250,7 @@ required). Then, from the main *MRtrix3* folder::
238250

239251
./build clean
240252
git pull
241-
ARCH="" ./configure -static [-nogui]
253+
./configure -static [-nogui]
242254
./build
243255

244256
Note that this requires the availability of static versions of the
@@ -341,7 +353,7 @@ required). Then, from the main *MRtrix3* folder::
341353

342354
./build clean
343355
git pull
344-
ARCH="" ./configure [-nogui]
356+
./configure [-nogui]
345357
./build
346358
./package_mrtrix -standalone
347359

docs/troubleshooting/compiler_error_during_build.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ If you encounter an error during the build process that resembles the following:
55

66
ERROR: (#/#) [CC] release/cmd/command.o
77

8-
/usr/bin/g++-4.8 -c -std=c++11 -pthread -fPIC -march=native -I/home/user/mrtrix3/eigen -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd cmd/command.cpp -o release/cmd/command.o
8+
/usr/bin/g++-4.8 -c -std=c++11 -pthread -fPIC -I/home/user/mrtrix3/eigen -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd cmd/command.cpp -o release/cmd/command.o
99

1010
failed with output
1111

docs/troubleshooting/display_issues.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ If you encounter an error during the build process that resembles the following:
309309

310310
ERROR: (#/#) [CC] release/cmd/command.o
311311
312-
/usr/bin/g++-4.8 -c -std=c++11 -pthread -fPIC -march=native -I/home/user/mrtrix3/eigen -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd cmd/command.cpp -o release/cmd/command.o
312+
/usr/bin/g++-4.8 -c -std=c++11 -pthread -fPIC -I/home/user/mrtrix3/eigen -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd cmd/command.cpp -o release/cmd/command.o
313313
314314
failed with output
315315

0 commit comments

Comments
 (0)