The procedure for running MATLAB 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 matlab -batch "main" on a command prompt to run the MATLAB script. Here, main is the name of the MATLAB script containing your ParaMonte simulation code (whether serial or parallel, does not matter).

Running MATLAB simulations on the command-prompt

Running MATLAB simulations on the command-prompt on a single processor

Suppose you want to run this MATLAB script named main.m which calls the ParaMonte library routines to sample a mathematical objective function implemented in this MATLAB file named logfunc.m on a single processor. Assuming that you have already successfully installed the ParaMonte MATLAB library on your system, all you need to do is to,

  1. open a MATLAB-aware terminal (e.g., the Windows cmd.exe 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,
    matlab -batch "main"
    

Running MATLAB simulations on the command-prompt on multiple processors

Suppose you want to run this MPI-enabled MATLAB script named main_mpi.m which calls the ParaMonte library parallel routines to sample a mathematical objective function implemented in this MATLAB file named logfunc.m on multiple processors.

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

  1. open a MATLAB-aware terminal (e.g., the Windows cmd.exe 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 matlab -batch "main_mpi"
      

      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 matlab -batch "main_mpi"
      

      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 MATLAB simulations from within a MATLAB session

You can also run the ParaMonte simulations from within a MATLAB session, but only in serial mode (since parallel simulations cannot be performed from within a MATLAB session). To run serial simulations from within MATLAB,

  1. Depending on your operating system,
    • on Windows, either open a MATLAB session from the Windows Startup Menu or simply call the MATLAB executable on the Windows command line.
    • on Linux/macOS, open a MATLAB session by calling the MATLAB executable on the Bash terminal,
      matlab
      
  2. Change the working directory of MATLAB to the folder containing your main.m script.
  3. Before running the script, make sure you have added the path to the root directory of the ParaMonte library to your MATLAB’s list of search paths via,
    addpath(genpath(ParaMonteRootDir));
    

    where you will have to replace the variable ParaMonteRootDir with a string (e.g., "./") that points to the root directory of the ParaMonte MATLAB library (i.e., the directory in which the ParaMonte library’s license file LICENSE exists).


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