AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO

[BUG] Cannot force single threaded behaviour via OPENIMAGEIO_THREADS

Open
#3,657 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.4k
Forks
698
Avg merge
3d 9h
Merged PRs (30d)
48

Description

I'm trying to force openexr output to be single threaded via OPENIMAGEIO_THREADS, but that seems to be impossible. Should it be possible?

In exroutput.cpp's [set_exr_threads()](https://github.com/OpenImageIO/oiio/blob/master/src/openexr.imageio/exroutput.cpp#L265), we have:
```
int oiio_threads = 1;
OIIO::getattribute("exr_threads", oiio_threads);

// 0 means all threads in OIIO, but single-threaded in OpenEXR
// -1 means single-threaded in OIIO
if (oiio_threads == 0) {
oiio_threads = Sysutil::hardware_concurrency();
} else if (oiio_threads == -1) {
oiio_threads = 0;
```
So this code would imply that setting `OPENIMAGEIO_THREADS` to `-1` should do it.

However, in imageio.cpp's [threads_default()](https://github.com/OpenImageIO/oiio/blob/master/src/libOpenImageIO/imageio.cpp#L29), we have:
```
int n = Strutil::from_string(
Sysutil::getenv("OPENIMAGEIO_THREADS", Sysutil::getenv("CUE_THREADS")));
if (n < 1)
n = Sysutil::hardware_concurrency();
```
So what happens is that we end up with "exr_threads" set to `Sysutil::hardware_concurrency()` before we even get to the check in `set_exr_threads()`, making it impossible to be single threaded.

Contributor guide

Open the contributing guide

Research direction

Start with set_exr_threads() in src/openexr.imageio/exroutput.cpp and threads_default() in src/libOpenImageIO/imageio.cpp. Trace how OPENIMAGEIO_THREADS is converted into the exr_threads value before OpenEXR output configuration. Done means the documented single-threaded setting can reach the OpenEXR configuration without being replaced by the hardware concurrency value.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.