User and Programmers Guide to the Neutron Ray-Tracing Package McStas, version 3.8.6

3.7  Using MPI for parallel computing

Parallelizing a computation is in general possible when dependencies between each computation are not too strong. The situation of McStas is ideal since each neutron ray can be simulated without interfering with other simulated neutron rays. Therefore each neutron ray can be simulated independently on a set of computers.

When computing \(N\) neutron rays with \(p\) computers, each computer will simulate \(\frac {N}{p}\) neutrons. As a result there will be \(p \cdot \frac {N}{p} = N\) neutrons simulated. As a result, McStas generates two kinds of data sets:

McStas provides two methods in order to distribute computations on many computers.

All of these methods can be used, when available, from mcgui.

3.7.1  Parallel computing (MPI)

The MPI support requires that an MPI implementation (MPICH or OpenMPI are both known to work) is installed on a set of nodes, together with a properly configured passwordless ssh between nodes if running across more than one machine.

There are 2 methods for using MPI

The MPI support is especially suited on clusters.

Requirements and limitation (MPI)

To use MPI you will need

  1. A working MPI installation (MPICH or OpenMPI) on all nodes, and a McStas installation accessible from all nodes (e.g. on a shared filesystem, or installed identically on each node).

  2. If running across more than one machine, ssh access between nodes without a password (e.g. using ssh-keygen and ssh-copy-id), and a machine list file (see --machines in Table 3.1).

  3. Signals are not supported while simulating with MPI (since asynchronous events cannot be easily transmitted to all nodes). This means it is not possible to cancel an on-going computation. However, simulation scans can be interrupted as soon as the on-going computation step ends.

MPI Basic usage

To enable parallel computation, compile mcstas-generated C code with mpicc with the flag -DUSE_MPI and run it using the wrapper of your MPI implementation (mpirun for mpich or lammpi) :

1  # generate a C-source file [sim.c] 
2  mcstas sim.instr 
3 
4  # generate an executable with MPI support [sim.mpi] 
5  mpicc -DUSE_MPI -o sim.mpi sim.c 
6 
7  # execute with parallel processing over <N> computers 
8  # here you have to list the computers you want to use 
9  # in a file [machines.list] (using mpich implementation) 
10  # (refer to MPI documentation for a complete description) 
11  mpirun -machinefile machines.list -n <N> \ 
12        ./sim.mpi <instrument parameters> 
13  ...
 
14

If you don’t want to spread the simulation, run it as usual:

1  ./sim.mpi <instrument parameters>
 
2

3.7.2  McRun options for MPI

The two relevant mcrun options are (see Table 3.1):

When available, the MPI option will show up in the mcgui Run dialog. Specify the number of nodes required.

Suppose you have four machines named node1 to node4. A typical machine list file, machines.list looks like :

1node1 
2node2 
3node3 
4node4

You can then spread a simulation sim.instr using mcrun :

1  mcrun -c --mpi=4 --machines=machines.list \ 
2        sim.instr <instrument parameters>
 
3

Warning: when using mcrun with MPI, be sure to recompile your simulation with MPI support (see -c flag of mcrun): a simulation compiled without MPI support cannot be used with MPI, whereas a simulation compiled with MPI support can be used without MPI.

3.7.3  McStas/MPI Performance

Theoretically, a computation which lasts \(T\) seconds on a single computer, should lasts at least \(\frac {T}{p}\) seconds when it is distributed over \(p\) computers. In practice, there will be overhead time due to the split and merge operations.

The efficiency of McStas using MPI has been tested on large clusters, up to 500 nodes. The computation time decreases in the same proportion as the number of nodes, showing an ideal efficiency. However, a small overhead may appear depending on the cluster internal network load, which may be estimated at most of about 10-20 s. This overhead comes from the spread and the fusion of the computations. For instance, spreading a computation implies often an rsh or and ssh session to be opened on every node. To reach the best efficiency, the computation time should not be lower than 30 seconds, or the overhead time may become significant compared to total time.


PIC


Figure 3.6.: McStas/MPI execution time as a function of computing nodes, with templateTOF instrument and 1e8 initial neutron events. Tests performed on Lonestar@TACC (US Teragrid, 2008).


3.7.4  MPI Bugs and limitations