The procedure for running Python simulations, whether serial or parallel, is identical to the procedure for running C/C++/Fortran applications, except that the user needs to replace the executable’s name main.exe
with python main.py
on a command prompt to run the Python script. Here, main
is the name of the Python script containing your ParaMonte simulation code (whether serial or parallel, does not matter).
Running Python simulations on the command-prompt
Running Python simulations on the command-prompt on a single processor
Suppose you want to run this Python script named main.py
which calls the ParaMonte library routines to sample a mathematical objective function implemented in this Python file named logfunc.py
on a single processor. Assuming that you have already successfully installed the ParaMonte Python library on your system, all you need to do is to,
- open a Python-aware terminal (e.g., the Anaconda3 command-prompt on Windows or the Bash terminal on Linux/macOS),
- navigate to the folder containing your code, and,
- type the following on the command line,
python main.py
Running Python simulations on the command-prompt on multiple processors
Suppose you want to run this MPI-enabled Python script named main_mpi.py
which calls the ParaMonte library parallel routines to sample a mathematical objective function implemented in this Python file named logfunc.py
on multiple processors.
main_mpi.py
and
the corresponding serial Python script main.py
is the additional simulation attribute,
which ensures the MPI-enabled ParaMonte library routines will be called for the parallel simulation. Absolutely NO MPI parallel programming is needed by the user to run the ParaMonte Python simulations in parallel.
Assuming that you have already successfully installed the ParaMonte Python library on your system, all you need to do is to,
- open a Python-aware terminal (e.g., the Anaconda3 command-prompt on Windows or the Bash terminal on Linux/macOS),
- navigate to the folder containing your code, and,
- run the following on the command line,
- On Windows
Invoke the MPI launchermpiexec
on the command line via,mpiexec -localonly -n 3 python main_mpi.py
where the flag
-localonly
ensures that the simulation is run only on a single node. This option avoids the invocation of the Hydra service which would require prior registration of the service. The flag-n 3
assigns three MPI tasks to three physical processors for the simulation. Change the number 3 to as many processor counts as you wish to use.Tip: To run your simulation on a cluster of nodes, follow the guidelines and instructions provided by the Intel MPI library development team. - On Linux / macOS
Invoke the MPI launchermpiexec
on the command line via,mpiexec -n 3 python main_mpi.py
The flag
-n 3
assigns three MPI tasks to three physical processors for the simulation. Change the number 3 to as many processor counts as you wish to use.Note: Some supercomputing centers (for example, the Texas Advanced Computing Center) may have their dedicated MPI launchers other thanmpiexec
to run applications in parallel. A prime example of this isibrun
. Consult your supercomputing center to ensure you invoke the right MPI launcher for parallel applications, in particular, when running the application on a cluster of nodes of multiple processors.
- On Windows
-n 3
or -n 4
at most, when invoking the MPI launcher).Running Python simulations from within an IPython session
The procedures for running ParaMonte python simulations from within an IPython or Jupyter session, whether serial or parallel, are the same as the procedures for running Python simulations on the command-line, except that you need to add an exclamation mark (!
) before the commands. For example,
!python main.py
in an IPython or Jupyter session is equivalent to,
python main.py
on a Bash terminal on Linux/macOS or an Anaconda3 command-prompt on Windows. So is the syntax for running MPI-enabled ParaMonte Python simulations from within IPython or Jupyter.
- On Windows
!mpiexec -localonly -n 3 python main_mpi.py
- On Linux / macOS
!mpiexec -n 3 python main_mpi.py