﻿# MPI thread support: the returned level controls the calling architecture

Check MPI_Init_thread's provided level before background workers call MPI, and distinguish FUNNELED ownership from SERIALIZED mutual exclusion.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/mpi-thread-support-level/
Language: en

A preprocessing pool works until a background thread begins exchanging a batch through MPI. The program requested multithreaded support, so the failure is attributed to transport. The missing check is whether the initialized runtime actually supplied the level that this calling architecture needs.

## Inventory the threads that call MPI

Name the initialization thread, computation workers and any communication helper. Distinguish a thread that prepares a buffer from one that invokes MPI. A single simultaneous caller can still be the wrong caller under FUNNELED. The related [OptiX concurrency guide](/journal/fg2-optix-concurrent-launch-pipeline-stream-ownership/) explains another library-specific contract: threads and execution streams alone never establish permission to share an API object or invoke it concurrently.

## Treat initialization as negotiation

The [MPI_Init_thread reference](https://docs.open-mpi.org/en/main/man-openmpi/man3/MPI_Init_thread.3.html) says provided need not meet required. Inspect the returned level before spawning a communication path that assumes otherwise. Preserve the library build, initialization arguments and effective launch environment. Open MPI also documents an environment override for the requested level; an application's source declaration therefore need not describe the effective request. Avoid claiming that a successful initialization confirms MULTIPLE support without examining provided.

## Choose a compatible call architecture

FUNNELED permits MPI calls only from the thread that initialized MPI. A mutex around calls from arbitrary pool threads does not satisfy that restriction. SERIALIZED permits multiple potential callers but forbids simultaneous MPI calls. MULTIPLE permits concurrent calls, while the application's buffer and operation-order obligations remain. SINGLE describes a single-threaded process. Decide whether to reject the launch or select a deliberately supported fallback instead of continuing with an unsupported arrangement.

## Query without pretending to upgrade

The [MPI_Query_thread reference](https://docs.open-mpi.org/en/main/man-openmpi/man3/MPI_Query_thread.3.html) returns the current support level, matching the initialization result when MPI_Init_thread was used. A dependent library can inspect this before enabling its worker path. Querying does not upgrade support or make it legal to initialize the world model repeatedly. Record one process-wide policy for libraries sharing that model, including which component initializes it and which components may issue communication during cleanup.

## Exercise the actual caller pattern

Use distinguishable small messages and record caller identities, provided support and the intended serialization path. Verify a FUNNELED fallback routes communication to the initialization thread rather than merely adding a lock. For SERIALIZED, include helper and cleanup calls in the exclusion design. Check buffer lifetime separately; [asynchronous stage ownership](/journal/learn-async-shared-copy-pipeline/) illustrates why permitting a call does not establish readiness to reuse the memory it references. No particular speedup follows from accepting more callers.

## Keep correctness and performance conclusions separate

Acceptance means every MPI invocation obeys the supplied thread level and the application preserves communication ordering and memory ownership. A short passing run cannot prove the absence of a race under another schedule. Measure any performance claim on the selected build and workload after correctness review. More thread support can alter costs, and it does not promise asynchronous progress, faster collective operations or freedom from a deadlock caused by inconsistent participation across processes.
