<spanclass="n">make</span><spanclass="n">mpi</span><spanclass="c1"># build with USER-OMP package, if settings added to Makefile.mpi</span>
<spanclass="n">make</span><spanclass="n">omp</span><spanclass="c1"># or Makefile.omp already has settings</span>
<spanclass="n">Make</span><spanclass="o">.</span><spanclass="n">py</span><spanclass="o">-</span><spanclass="n">v</span><spanclass="o">-</span><spanclass="n">p</span><spanclass="n">omp</span><spanclass="o">-</span><spanclass="n">o</span><spanclass="n">mpi</span><spanclass="o">-</span><spanclass="n">a</span><spanclass="n">file</span><spanclass="n">mpi</span><spanclass="c1"># or one-line build via Make.py</span>
<p>Your compiler must support the OpenMP interface. You should have one
or more multi-core CPUs so that multiple threads can be launched by
each MPI task running on a CPU.</p>
<p><strong>Building LAMMPS with the USER-OMP package:</strong></p>
<p>The lines above illustrate how to include/build with the USER-OMP
package in two steps, using the “make” command. Or how to do it with
one command via the src/Make.py script, described in <aclass="reference internal"href="Section_start.html#start-4"><spanclass="std std-ref">Section 2.4</span></a> of the manual. Type “Make.py -h” for
help.</p>
<p>Note that the CCFLAGS and LINKFLAGS settings in Makefile.machine must
include “-fopenmp”. Likewise, if you use an Intel compiler, the
CCFLAGS setting must include “-restrict”. The Make.py command will
add these automatically.</p>
<p><strong>Run with the USER-OMP package from the command line:</strong></p>
<p>The mpirun or mpiexec command sets the total number of MPI tasks used
by LAMMPS (one or multiple per compute node) and the number of MPI
tasks used per node. E.g. the mpirun command in MPICH does this via
its -np and -ppn switches. Ditto for OpenMPI via -np and -npernode.</p>
<p>You need to choose how many OpenMP threads per MPI task will be used
by the USER-OMP package. Note that the product of MPI tasks *
threads/task should not exceed the physical number of cores (on a
node), otherwise performance will suffer.</p>
<p>As in the lines above, use the “-sf omp”<aclass="reference internal"href="Section_start.html#start-7"><spanclass="std std-ref">command-line switch</span></a>, which will automatically append
“omp” to styles that support it. The “-sf omp” switch also issues a
default <aclass="reference internal"href="package.html"><spanclass="doc">package omp 0</span></a> command, which will set the
number of threads per MPI task via the OMP_NUM_THREADS environment
variable.</p>
<p>You can also use the “-pk omp Nt”<aclass="reference internal"href="Section_start.html#start-7"><spanclass="std std-ref">command-line switch</span></a>, to explicitly set Nt = # of OpenMP
threads per MPI task to use, as well as additional options. Its
syntax is the same as the <aclass="reference internal"href="package.html"><spanclass="doc">package omp</span></a> command whose doc
page gives details, including the default values used if it is not
specified. It also gives more details on how to set the number of
threads via the OMP_NUM_THREADS environment variable.</p>
<p><strong>Or run with the USER-OMP package by editing an input script:</strong></p>
<p>The discussion above for the mpirun/mpiexec command, MPI tasks/node,
and threads/MPI task is the same.</p>
<p>Use the <aclass="reference internal"href="suffix.html"><spanclass="doc">suffix omp</span></a> command, or you can explicitly add an
“omp” suffix to individual styles in your input script, e.g.</p>
<p>You must also use the <aclass="reference internal"href="package.html"><spanclass="doc">package omp</span></a> command to enable the
USER-OMP package. When you do this you also specify how many threads
per MPI task to use. The command doc page explains other options and
how to set the number of threads via the OMP_NUM_THREADS environment
variable.</p>
<p><strong>Speed-ups to expect:</strong></p>
<p>Depending on which styles are accelerated, you should look for a
reduction in the “Pair time”, “Bond time”, “KSpace time”, and “Loop
time” values printed at the end of a run.</p>
<p>You may see a small performance advantage (5 to 20%) when running a
USER-OMP style (in serial or parallel) with a single thread per MPI
task, versus running standard LAMMPS with its standard un-accelerated
styles (in serial or all-MPI parallelization with 1 task/core). This
is because many of the USER-OMP styles contain similar optimizations
to those used in the OPT package, described in <aclass="reference internal"href="accelerate_opt.html"><spanclass="doc">Section accelerate 5.3.6</span></a>.</p>
<p>With multiple threads/task, the optimal choice of number of MPI
tasks/node and OpenMP threads/task can vary a lot and should always be
tested via benchmark runs for a specific simulation running on a
specific machine, paying attention to guidelines discussed in the next
sub-section.</p>
<p>A description of the multi-threading strategy used in the USER-OMP
package and some performance examples are <aclass="reference external"href="http://sites.google.com/site/akohlmey/software/lammps-icms/lammps-icms-tms2011-talk.pdf?attredirects=0&d=1">presented here</a></p>
<p><strong>Guidelines for best performance:</strong></p>
<p>For many problems on current generation CPUs, running the USER-OMP
package with a single thread/task is faster than running with multiple
threads/task. This is because the MPI parallelization in LAMMPS is
often more efficient than multi-threading as implemented in the
USER-OMP package. The parallel efficiency (in a threaded sense) also
varies for different USER-OMP styles.</p>
<p>Using multiple threads/task can be more effective under the following
circumstances:</p>
<ulclass="simple">
<li>Individual compute nodes have a significant number of CPU cores but
the CPU itself has limited memory bandwidth, e.g. for Intel Xeon 53xx
(Clovertown) and 54xx (Harpertown) quad-core processors. Running one
MPI task per CPU core will result in significant performance
degradation, so that running with 4 or even only 2 MPI tasks per node
is faster. Running in hybrid MPI+OpenMP mode will reduce the
inter-node communication bandwidth contention in the same way, but
offers an additional speedup by utilizing the otherwise idle CPU
cores.</li>
<li>The interconnect used for MPI communication does not provide
sufficient bandwidth for a large number of MPI tasks per node. For
example, this applies to running over gigabit ethernet or on Cray XT4
or XT5 series supercomputers. As in the aforementioned case, this
effect worsens when using an increasing number of nodes.</li>
<li>The system has a spatially inhomogeneous particle density which does
not map well to the <aclass="reference internal"href="processors.html"><spanclass="doc">domain decomposition scheme</span></a> or
<aclass="reference internal"href="balance.html"><spanclass="doc">load-balancing</span></a> options that LAMMPS provides. This is
because multi-threading achives parallelism over the number of
particles, not via their distribution in space.</li>
<li>A machine is being used in “capability mode”, i.e. near the point
where MPI parallelism is maxed out. For example, this can happen when
using the <aclass="reference internal"href="kspace_style.html"><spanclass="doc">PPPM solver</span></a> for long-range
electrostatics on large numbers of nodes. The scaling of the KSpace
calculation (see the <aclass="reference internal"href="kspace_style.html"><spanclass="doc">kspace_style</span></a> command) becomes
the performance-limiting factor. Using multi-threading allows less
MPI tasks to be invoked and can speed-up the long-range solver, while
increasing overall performance by parallelizing the pairwise and
bonded calculations via OpenMP. Likewise additional speedup can be
sometimes be achived by increasing the length of the Coulombic cutoff
and thus reducing the work done by the long-range solver. Using the
<aclass="reference internal"href="run_style.html"><spanclass="doc">run_style verlet/split</span></a> command, which is compatible
with the USER-OMP package, is an alternative way to reduce the number
of MPI tasks assigned to the KSpace calculation.</li>
</ul>
<p>Additional performance tips are as follows:</p>
<ulclass="simple">
<li>The best parallel efficiency from <em>omp</em> styles is typically achieved
when there is at least one MPI task per physical CPU chip, i.e. socket
or die.</li>
<li>It is usually most efficient to restrict threading to a single
socket, i.e. use one or more MPI task per socket.</li>
<li>NOTE: By default, several current MPI implementations use a processor
affinity setting that restricts each MPI task to a single CPU core.
Using multi-threading in this mode will force all threads to share the
one core and thus is likely to be counterproductive. Instead, binding
MPI tasks to a (multi-core) socket, should solve this issue.</li>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.