ClimaComms.jl provides the abstractions for computing devices and
communication contexts that the CliMA Earth System
Model is built on. It lets the same simulation code
run unchanged on a single CPU thread, on multiple CPU threads, on NVIDIA and
Apple GPUs, and across many nodes with MPI: the device and the parallelism are
selected at runtime, typically through environment variables.
| Documentation | |
| Version | |
| License | |
| Tests | |
| Downloads |
using Pkg
Pkg.add("ClimaComms")To run on GPUs or with MPI, also install the corresponding backend packages
(ClimaComms loads them through package extensions, so they are not hard
dependencies):
Pkg.add("CUDA") # for NVIDIA GPUs
Pkg.add("Metal") # for Apple GPUs (Float32 only)
Pkg.add("MPI") # for distributed runsClimaComms.jl is built around two objects: a device (the hardware a
computation runs on) and a context (the environment through which processes
communicate). Both are selected at runtime from the CLIMACOMMS_DEVICE and
CLIMACOMMS_CONTEXT environment variables, so the same script runs anywhere:
import ClimaComms
# Load MPI.jl, CUDA.jl, or Metal.jl, as the environment variables request.
ClimaComms.@import_required_backends
context = ClimaComms.context() # e.g., SingletonCommsContext or MPICommsContext
device = ClimaComms.device(context) # e.g., CPUSingleThreaded() or CUDADevice()
ClimaComms.init(context) # initialize (e.g., MPI setup, GPU assignment)
# Allocate arrays on the right device.
ArrayType = ClimaComms.array_type(device)
x = ArrayType([1.0, 2.0, 3.0])
# Communicate across processes (a no-op in single-process runs).
total = ClimaComms.reduce(context, sum(x), +)
ClimaComms.iamroot(context) && @show totalTo run the same script on a GPU, or on four MPI processes:
CLIMACOMMS_DEVICE=CUDA julia script.jl
CLIMACOMMS_DEVICE=Metal julia script.jl
CLIMACOMMS_CONTEXT=MPI mpiexec -n 4 julia script.jlThe ClimaComms.@threaded macro generalizes Threads.@threads: the same loop
runs serially on a single-threaded CPU, across threads on a multi-threaded CPU,
and as a kernel on a GPU:
function threaded_add!(a, b, device)
ClimaComms.@threaded device for i in eachindex(a, b)
a[i] += b[i]
end
end- Device abstraction:
CPUSingleThreaded,CPUMultiThreaded,CUDADevice, andMetalDevicetypes select hardware-specific implementations via dispatch. - Context abstraction:
SingletonCommsContextandMPICommsContextprovide a unified interface (reduce,gather,bcast,barrier, ...) for single-process and distributed runs. - Runtime configuration: devices and contexts are chosen through environment variables, so simulations move from a laptop to a GPU cluster without code changes.
- Zero-cost fallbacks: communication primitives are no-ops in
single-process runs, and single-threaded loops compile to plain
forloops. - Optional backends:
CUDA.jl,Metal.jl, andMPI.jlare weak dependencies, loaded through package extensions only when needed, which keeps load times low. - Distributed logging: loggers that silence non-root processes, prefix messages with MPI ranks, or write per-rank log files.
Devices and contexts are lightweight (usually empty) structs. They carry no
state of their own; they exist so that Julia's multiple dispatch can select the
right implementation — Array vs. CuArray, a serial loop vs. a CUDA kernel,
a no-op vs. an MPI.Allreduce. Library code takes a device or context argument
and remains agnostic about what hardware it runs on.
Simulation code written against the ClimaComms interface does not mention
CUDA or MPI directly. The concrete backend is chosen when the program starts,
from environment variables, which makes the same driver script portable from
serial debugging on a laptop to multi-GPU production runs on a cluster.
Backend-specific code lives in package extensions (ext/), so ClimaComms
itself depends only on Julia's standard logging packages and Adapt.jl. Users
opt into GPU or MPI support by installing and loading CUDA.jl, Metal.jl, or
MPI.jl; the ClimaComms.@import_required_backends macro automates this based
on the requested configuration.
- Getting Started - Installation and a first parallel-safe script.
- How-To Guide - Recipes for common tasks.
- Design Philosophy - Why ClimaComms exists and how CliMA packages use it.
- API Reference - Detailed function documentation.
Contributors should follow the shared CliMA engineering standards in CliMA/DeveloperGuides, which cover architecture, performance, code quality, documentation, and workflows.
ClimaComms.jl is the device and communication layer for the
CliMA ecosystem. Nearly every CliMA package accepts
a ClimaComms device or context, including:
- ClimaCore - distributed fields and operators
- ClimaAtmos - atmosphere model
- ClimaLand - land model
- ClimaOcean - ocean model
- ClimaCoupler - coupled Earth system model
- ClimaTimeSteppers - time integration
- ClimaDiagnostics - simulation diagnostics
- RRTMGP - radiative transfer
For questions, check the documentation or open an issue on GitHub.