Skip to content

Fix numba warning on Linux for using TBB#2010

Merged
psavery merged 2 commits into
masterfrom
fix-numba-warning
May 20, 2026
Merged

Fix numba warning on Linux for using TBB#2010
psavery merged 2 commits into
masterfrom
fix-numba-warning

Conversation

@psavery
Copy link
Copy Markdown
Collaborator

@psavery psavery commented May 13, 2026

This fixes the following numba warning on Linux:

Numba: Attempted to fork from a non-main thread, the TBB library may be in an invalid state in the child process.

The main idea is that forked subprocesses (which we indeed do, in order to take advantage of copy-on-write mechanics and let subprocesses share data), which only happen on Linux (Windows and Mac do "spawn"), would always print this numba warning, even though we were never actually using TBB in an invalid way.

There's no way to suppress this warning, so we switch to OpenMP on Linux, which is just as performant.

In fact, it has one better feature too: it will crash if we try to run numba in parallel mode on a forked subprocess. TBB was just undefined, but the OpenMP implementation will actually crash, which prevents developers from ever doing that.

@psavery psavery requested review from bnmajor and saransh13 May 13, 2026 22:13
psavery added 2 commits May 20, 2026 14:21
This fixes the following numba warning on Linux:

```
Numba: Attempted to fork from a non-main thread, the TBB library may be in an invalid state in the child process.
```

The main idea is that forked subprocesses (which we indeed do, in order
to take advantage of copy-on-write mechanics and let subprocesses share
data), which only happen on Linux (Windows and Mac do "spawn"), would
always print this numba warning, even though we were never actually using
TBB in an invalid way.

There's no way to suppress this warning, so we switch to OpenMP on Linux,
which is just as performant.

In fact, it has one better feature too: it will crash if we try to run
numba in parallel mode on a forked subprocess. TBB was just undefined,
but the OpenMP implementation will actually crash, which prevents
developers from ever doing that.

Crossref: https://numba.discourse.group/t/fork-from-non-main-thread-warning/1753

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
@psavery psavery force-pushed the fix-numba-warning branch from 98d61fa to a8eba67 Compare May 20, 2026 19:21
Copy link
Copy Markdown
Member

@saransh13 saransh13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@psavery psavery merged commit 76428f2 into master May 20, 2026
11 checks passed
@psavery psavery deleted the fix-numba-warning branch May 20, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants