When MPI is used on more than one process (
) 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.
This has three main implications:
With a few exceptions
, values of types int, float, str
and numpy returned by esys.escript will have the same value on all processors.
If values produced by other modules are used as arguments, the user has to make sure that the argument values are identical
on all processors. For instance, the usage of a random number generator to create argument values bears the risk that
the value may depend on the processor.
Some operations in esys.escript require communication with all processors executing the job. It is not always obvious which operations these are. For example, Lsup returns the largest value on all processors. getValue on Locator may refer to a value stored on another processor. For this reason it is better if scripts do not have conditional operations (which manipulate data) based on which processor the script is on. Crashing or hanging scripts can be an indication that this has happened.
It is not always possible to divide data evenly amongst processors. In fact some processors might not have any data at all. Try to avoid writing scripts which iterate over data points, instead try to describe the operation you wish to perform as a whole.
Special attention is required when using files on more than one processor as several processors access the file at the same time. Opening a file for reading is safe, however the user has to make sure that the variables which are set from reading data from files are identical on all processors.
When writing data to a file it is important that only one processor is writing to
the file at any time. As all values in esys.escript are global it is sufficient
to write values on the processor with MPI rank 0
only.
The FileWriter class provides a convenient way to write global data
to a simple file. The following script writes to the file
'test.txt' on the processor with id 0
only:
We strongly recommend using this class rather than the built-in open
function as it will guarantee a script which will run in single processor mode as well as under MPI.
If there is the situation that one of the processors is throwing an exception, for instance as opening a file for writing fails, the other processors are not automatically made aware of this since MPI dioes not handle exceptions. However, MPI will terminate the other processes but may not inform the user of the reason in an obvious way. The user needs to inspect the error output files to identify the exception.