OpenImageIO icon indicating copy to clipboard operation
OpenImageIO copied to clipboard

[BUG] Cannot force single threaded behaviour via OPENIMAGEIO_THREADS

Open e4lam opened this issue 3 years ago • 0 comments
trafficstars

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(), 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(), we have:

    int n = Strutil::from_string<int>(
        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.

e4lam avatar Nov 10 '22 15:11 e4lam