Hints for MPI Programming

In general a script based on the esys.escript module does not require modifications when running under MPI . However, one needs to be careful if other modules are used.

When MPI is used on more than one process ( $ \var{nn} \cdot \var{np}>1$) the user needs to keep in mind that several copies of his script are executed at the same time [*] while data exchange is performed through the esys.escript module. At any time, esys.escript assumes that an argument of the type int, float, str and numarray has an identical value across all processors. All values of these types returned by esys.escript have the same value on all processors. If values produced by other modules are used as argument the user has to make sure that the value is identical on all processors. For instance, the usage of a random number generator to create a value for argument bears the risk that the value may depend on the processor.

An other case which needs special attention is the usage of files. When reading data from a file it advisable to use the 'r' for readable when opened. Keep in mind that several scripts will simultaneously access the file. If data are written to a file only one processor must open the file for writing. The function getMPIRankWorld which returns the processor id between 0 and the number of processors helps to achieve this. The following script writes to the file 'test.txt' on the processor with id 0 only:
\begin{python}
from esys.escript import *
if getMPIRankWorld() == 0 :
f = open('test.txt', 'w')
f.write('test message')
f.close()
\end{python}
Another technique is to extend the file name by the processor id to avoid conflicts while writing into a shared file system:
\begin{python}
from esys.escript import *
f = open('test.txt.%s'%getMPIRankWorld(), 'w')
f.write('test message')
f.close()
\end{python}
creating files with names test.txt.0, test.txt.1, test.txt.2, $ \ldots$.

If there is the situation that if execution on one of the processors is throwing an exception, for instance as opening a file for writing fails, are not made aware of this as MPI is not handling exceptions. However, MPI will terminate the other processes but may not inform the user of the reason in the obvious way. The user needs to inspect the error output files to identify the exception.

esys@esscc.uq.edu.au