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,

  1. open a Python-aware terminal (e.g., the Anaconda3 command-prompt on Windows or the Bash terminal on Linux/macOS),
  2. navigate to the folder containing your code, and,
  3. 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.

Assuming that you have already successfully installed the ParaMonte Python library on your system, all you need to do is to,

  1. open a Python-aware terminal (e.g., the Anaconda3 command-prompt on Windows or the Bash terminal on Linux/macOS),
  2. navigate to the folder containing your code, and,
  3. run the following on the command line,
    • On Windows
      Invoke the MPI launcher mpiexec 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.

    • On Linux / macOS
      Invoke the MPI launcher mpiexec 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.

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
    


If you have any questions about the topics discussed on this page, feel free to ask in the comment section below, or raise an issue on the GitHub page of the library, or reach out to the ParaMonte library authors.