File: mpi.py

package info (click to toggle)
montage-wrapper 0.9.9-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,092 kB
  • sloc: python: 8,325; makefile: 116; ansic: 88
file content (34 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
MPI_COMMAND = 'mpirun -n {n_proc} {executable}'

def set_mpi_command(command):
    """
    Set the MPI Command to use.
    
    This should contain {n_proc} to indicate the number of processes, and
    {executable} to indicate the name of the executable.
    
    Parameters
    ----------
    command: str
        The MPI command for running executables
        
    Examples
    --------
    
    Use ``mpirun``:
    
    >>> set_mpi_command('mpirun -n {n_proc} {executable}')

    Use ``mpiexec`` with host list:
    
    >>> set_mpi_command('mpiexec -f mpd.hosts -np {n_proc} {executable}')
    """
    global MPI_COMMAND
    if "{n_proc}" not in command:
        raise ValueError("MPI command does not include {n_proc}")
    if "{executable}" not in command:
        raise ValueError("MPI command does not include {executable}")
    MPI_COMMAND = command
    
def _get_mpi_command(executable=None, n_proc=None):
    return MPI_COMMAND.format(executable=executable, n_proc=n_proc)