Skip to content

setNumThreads

Core and matricesfunctionOpenCV 5.0.0
import { setNumThreads } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSnthreads
FUNCTIONsetNumThreads
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

OpenCV will try to set the number of threads for subsequent parallel regions.

If threads == 1, OpenCV will disable threading optimizations and run all it's functions sequentially. Passing threads < 0 will reset threads number to system default. The function is not thread-safe. It must not be called in parallel region or concurrent threads.

OpenCV will try to run its functions with specified threads number, but some behaviour differs from framework:

  • TBB - User-defined parallel constructions will run with the same threads number, if another is not specified. If later on user creates his own scheduler, OpenCV will use it.
  • OpenMP - No special defined behaviour.
  • Concurrency - If threads == 1, OpenCV will disable threading optimizations and run its functions sequentially.
  • GCD - Supports only values <= 0.
  • C= - No special defined behaviour.

See: getNumThreads, getThreadNum

setNumThreads(nthreads: number): void;
nthreads

Number of threads used by OpenCV.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.