camber.mpi

Last updated:

Camber has a built-in engine to run workloads for OpenMPI, a library for high-performance, parallel computing.

import camber.mpi

You can access the MPI engine through camber.mpi with the following methods

Examples

Hello World

Build and run a simple “Hello World” C program over MPI.

import camber.mpi

# Compile the C program in the cloud
make = camber.mpi.create_job(
    command="make",
    node_size="XXSMALL"
)

# Wait for compilation to complete, then run with 4 MPI processes
run = camber.mpi.create_job(
    command="mpirun -np 4 mpi_hello_world",
    node_size="XXSMALL"
)

# Read logs from the run
run.read_logs()

Fluid Dynamics (Orszag-Tang Vortex)

Use the MPI engine to compile and run an Athena++ simulation of the Orszag-Tang Vortex.

import camber.mpi

# Clone Athena++ and compile with MPI and HDF5 support
compile_job = camber.mpi.create_job(
    command="cd athena && python configure.py -b --prob=orszag_tang -mpi -hdf5 --hdf5_path=${HDF5_HOME} && make clean && make all -j$(nproc)",
    node_size="SMALL"
)

# Once compile_job.status is COMPLETED, run the simulation on 16 cores
run_job = camber.mpi.create_job(
    command="mpirun -np 16 athena/bin/athena -i athinput.orszag-tang",
    node_size="MEDIUM"
)

run_job.read_logs(tail_lines=10)

Parameter Sweep

Run a grid of parallel simulations by looping over parameter values.

import camber.mpi

# Compile Athena++ for the blast wave problem
compile_job = camber.mpi.create_job(
    command="cd athena && python configure.py --prob=blast -mpi -hdf5 --hdf5_path=${HDF5_HOME} && make clean && make all -j$(nproc)",
    node_size="SMALL"
)

# Submit one job per pressure ratio value
params = ["10", "30", "100", "300"]
jobs = []
for prat in params:
    jobs.append(
        camber.mpi.create_job(
            node_size="MEDIUM",
            command=f"mpirun -np 16 athena/bin/athena -i athinput.blast problem/prat={prat} -d run{prat}",
        )
    )

Methods

create_job

Creates a CamberJob using the MPI engine.

Args

command: str
Base command in string form
e.g. mpirun -np 2 athena/bin/athena -i athinput.orszag-tang
node_size: Optional[str]
Size of node, one of XMICRO, MICRO, XXSMALL, XSMALL, SMALL, MEDIUM, LARGE.
Default is XSMALL.
mount_dir: Optional[str]
The directory to mount as the working directory for the job.
Defaults to the current working directory.
extra_env_vars: Optional[Dict[str, str]]
Extra environment variables to give the node.
e.g. {"MY_ENV_VAR":"my_value"}
tags: Optional[Union[str, List]]
Tags to help identify the job.
e.g. ["tag1", "tag2"] or "tag1".

Returns

CamberJob
The CamberJob object representing the created job.