Skip to main content
skill CX Codex

mpi — Claude Code skill: what it does, how to install

Guides agents through distributed-memory programming with MPI, collective communications, hybrid OpenMP patterns, and mpirun execution.

MIT 354 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill mpi -a claude-code
Open on GitHub

What mpi does

This skill supplies the agent with reference patterns for low-level Message Passing Interface programming in C. It covers basic lifecycle calls like MPI_Init and MPI_Finalize, point-to-point exchanges, collective routines including MPI_Bcast and MPI_Allreduce, plus communicator splitting with MPI_Comm_split.

The workflows address latency hiding using non-blocking routines MPI_Isend and MPI_Wait, parallel file operations with MPI-IO, and job launching via hostfiles or Slurm srun. In hybrid setups, mismatched rank and thread counts cause CPU oversubscription, so the guidelines enforce calculating OMP_NUM_THREADS and core binding with --bind-to core.

Diagnostics target common parallel pitfalls: circular deadlocks, buffer mismatches causing MPI_ERR_TRUNCATE, serial bottlenecks on rank 0, and lightweight profiling using mpiP.

What it helps with

  • implement point-to-point and collective message passing in C
  • overlap communication and computation using non-blocking MPI calls
  • configure hybrid MPI plus OpenMP jobs with proper core binding
  • diagnose deadlocks, tag mismatches, and rank 0 bottlenecks

Example prompts for the agent

  • Write a point-to-point ring communication program using MPI_Isend and MPI_Irecv
  • Set up an MPI plus OpenMP hybrid program with MPI_Allreduce across all nodes
  • Show how to write distributed matrix output using collective MPI-IO routines

How to install mpi

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill mpi -a claude-code

2Manually: put the files in place

~/.claude/skills/mpi/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/mpi/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about mpi

How to install mpi in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill mpi -a claude-code. The file will be placed into ~/.claude/skills/mpi/SKILL.md.

What does the mpi skill cover?

It provides patterns for distributed algorithms, collective operations, subcommunicators, MPI-IO, OpenMP hybrid parallelism, and launch commands for HPC clusters.

How does it handle MPI process debugging?

It supplies strategies for inspecting hangs at MPI_Recv, fixing buffer mismatches, tagging output per rank, and stepping through ranks via mpirun -gdb.

Source text

SKILL.md · MIT
---
name: mpi
description: MPI skill for distributed-memory parallel programming. Use when writing MPI_Send/Recv programs, collective operations, non-blocking communication, MPI+OpenMP hybrid, or debugging with mpirun. Activates on queries about MPI_Init, MPI_Allreduce, MPI_Isend, mpirun, MPI-IO, or MPI performance.
---

# MPI

## Purpose

Guide agents through MPI (Message Passing Interface) programming: point-to-point and collective communication, non-blocking operations, subcommunicators, MPI+OpenMP hybrid patterns, process launching with `mpirun`, debugging techniques, MPI-IO, and common performance issues.

## When to Use

- Parallelizing across multiple nodes or sockets
- Implementing distributed algorithms (matrix decompose, FFT)
- Combining MPI process parallelism with OpenMP thread parallelism
- Running HPC jobs with Slurm/PBS + `mpirun`
- Debugging deadlocks and message mismatches
- Parallel file I/O with MPI-IO

## Workflow

### 1. Minimal MPI program

```c
#include <mpi.h>
#include <stdio.h>

int main(int argc, char **argv) {
    MPI_Init(&argc, &argv);

    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    printf("Hello from rank %d of %d\n", rank, size);

    MPI_Finalize();
    return 0;
}
```

```bash
mpicc -o hello hello.c
mpirun -np 4 ./hello
# or
mpiexec -n 4 ./hello
```

### 2. Point-to-point

```c
if (rank == 0) {
    int data = 42;
    MPI_Send(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else if (rank == 1) {
    int recv;
    MPI_Recv(&recv, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    printf("rank 1 got %d\n", recv);
}
```

Tagged messages: match tag and source for `MPI_Recv`.

### 3. Collectives

```c
int local = rank + 1;
int global_sum;

MPI_Allreduce(&local, &global_sum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

// Broadcast
if (rank == 0) data = 100;
MPI_Bcast(&data, 1, MPI_INT, 0, MPI_COMM_WORLD);

// Scatter/Gather
MPI_Scatter(sendbuf, sendcount, MPI_INT, recvbuf, recvcount, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(sendbuf, sendcount, MPI_INT, recvbuf, recvcount, MPI_INT, 0, MPI_COMM_WORLD);
```

| Collective | Purpose |
|------------|---------|
| `MPI_Bcast` | One-to-all |
| `MPI_Scatter` | Distribute chunks |
| `MPI_Gather` | Collect chunks |
| `MPI_Allreduce` | Reduce + broadcast result |
| `MPI_Barrier` | Synchronization |
| `MPI_Alltoall` | All-to-all exchange |

### 4. Non-blocking communication

```c
MPI_Request req;
MPI_Isend(buf, count, MPI_INT, dest, tag, MPI_COMM_WORLD, &req);
// overlap computation here
do_local_work();
MPI_Wait(&req, MPI_STATUS_IGNORE);

// Multiple requests
MPI_Request reqs[2];
MPI_Irecv(buf0, n, MPI_INT, 0, 0, comm, &reqs[0]);
MPI_Irecv(buf1, n, MPI_INT, 1, 0, comm, &reqs[1]);
MPI_Waitall(2, reqs, MPI_STATUSES_IGNORE);
```

Overlap communication with computation to hide latency.

### 5. Subcommunicators

```c
int color = rank / 4;  // groups of 4
MPI_Comm subcomm;
MPI_Comm_split(MPI_COMM_WORLD, color, rank, &subcomm);

int subrank, subsize;
MPI_Comm_rank(subcomm, &subrank);
MPI_Comm_size(subcomm, &subsize);

MPI_Comm_free(&subcomm);
```

### 6. MPI + OpenMP hybrid

```c
#pragma omp parallel
{
    int tid = omp_get_thread_num();
    // thread-local work on rank's data partition
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Allreduce(...);
```

```bash
export OMP_NUM_THREADS=4
mpirun -np 8 --bind-to core ./hybrid_app
# 8 ranks × 4 threads = 32 cores
```

Bind ranks to sockets with `--map-by ppr:2:socket`.

### 7. Launching with hostfile

```bash
# hostfile:
# node0 slots=4
# node1 slots=4

mpirun -np 8 --hostfile hosts.txt ./app

# Slurm integration
srun -n 64 ./app
# or
mpirun -np $SLURM_NTASKS ./app
```

```bash
# Debug: tag output by rank
mpirun -np 4 --tag-output ./app

# Sequential debug (one rank at a time)
mpirun -np 4 -gdb ./app
```

### 8. MPI-IO

```c
#include <mpi.h>

MPI_File fh;
MPI_File_open(MPI_COMM_WORLD, "output.dat",
    MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &fh);

MPI_Offset offset = rank * chunk_size;
MPI_File_write_at(fh, offset, buf, count, MPI_DOUBLE, MPI_STATUS_IGNORE);

MPI_File_close(&fh);
```

Collective I/O for better performance:

```c
MPI_File_write_at_all(fh, offset, buf, count, MPI_DOUBLE, MPI_STATUS_IGNORE);
```

### 9. Performance issues

```
Common bottlenecks
├── Load imbalance → dynamic scheduling (OpenMP) or redistribute MPI chunks
├── Serialization at rank 0 → tree-based reduce, parallel I/O
├── Excessive sync → replace Barrier with point-to-point where possible
├── Small messages → aggregate; use MPI_Pack or larger blocks
└── Alltoall on large process counts → consider MPI neighborhood collectives
```

```bash
# MPI profiling
mpiP  # lightweight profiler
# or IPM, TAU MPI wrappers
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| Hang at MPI_Recv | Tag/source mismatch | Check Send/Recv pairing; use `MPI_ANY_TAG` debug |
| Deadlock | Circular wait | Reorder comm pattern; use non-blocking |
| Wrong result in Allreduce | Wrong datatype/count | Verify MPI_INT vs MPI_DOUBLE |
| Poor scaling | Rank 0 bottleneck | Distribute I/O and aggregation |
| `MPI_ERR_TRUNCATE` | Receive buffer too small | Match send/recv counts |
| Hybrid oversubscription | Too many threads×ranks | `OMP_NUM_THREADS = cores/ranks` |

## Related Skills

- `skills/hpc/openmp` — thread-level parallelism within MPI ranks
- `skills/hpc/rdma-verbs` — low-latency interconnect under MPI
- `skills/allocators/numa-programming` — bind ranks to NUMA nodes
- `skills/profilers/linux-perf` — profile MPI rank hotspots
- `skills/debuggers/gdb` — debug individual MPI processes
- `skills/compilers/gcc` — MPI compiler wrapper flags

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Science and research →

From the same set140

The whole set →
af-xdp Configures AF_XDP sockets and shared UMEM buffers for low-latency packet processing. Helps implement fast network filtering directly in userspace. CX Codex +1 359installs triton-lang triton-lang is a Claude Code skill that teaches agents to write Triton GPU kernels with @triton.jit, masked block operations, atomics, autotuning, and PyTorch integration. CX Codex +1 358installs containers-internals containers-internals is a Claude Code skill for Linux container internals, activated for queries about namespaces, runc, seccomp, and escape vulnerabilities. CX Codex +1 358installs rdma-verbs rdma-verbs guides coding agents through RDMA programming using libibverbs for InfiniBand and RoCE fabrics. Useful when setting up queue pairs or perftest benchmarks. CX Codex +1 356installs riscv-privileged The riscv-privileged skill supports RISC-V kernel and firmware development, covering privileged modes, CSRs, traps, interrupt controllers, OpenSBI, page tables, and QEMU testing. CX Codex +1 355installs verilog-basics-for-lowlevel verilog-basics-for-lowlevel — a skill that teaches firmware and kernel engineers to read Verilog RTL: modules, clocking, reset logic, bus protocols. Use it when docs are unclear and hardware behavior explains driver bugs. CX Codex +1 345installs hare-lang hare-lang teaches AI assistants systems programming in Hare: hare build workflows, manual hare.mod project layout, tagged union errors, and C FFI via @extern. CX Codex +1 330installs carbon-lang carbon-lang is a Claude Code skill for exploring Carbon syntax, C++ interoperability, and toolchain builds. It supports migration prototyping and language assessment. CX Codex +1 329installs

Project sponsors

Companies that keep this analytics open