vfhe.util.parallel

Sets how many threads vfhe uses: one library-wide limit, and a local one per thread.

  • set_num_threads and num_threads set and read the library-wide limit. Functions taking n_threads never exceed it, and their default n_threads=0 means “up to the limit”.

  • local_num_threads lowers the limit for the vfhe calls the current thread makes inside a with block.

The default limit is VFHE_NUM_THREADS if set, otherwise 1, so vfhe is single-threaded unless asked.

>>> from vfhe.util import parallel
>>> parallel.set_num_threads(8)
>>> with parallel.local_num_threads(2):
...     pass  # vfhe calls made here use at most 2 threads
>>> parallel.set_num_threads()
vfhe.util.parallel.local_num_threads(n: int) → Generator[None, None, None]

Limits the threads of the vfhe calls this thread makes inside to n.

0 sets no local limit. The library limit still applies, and a local limit set inside another can only lower it.

vfhe.util.parallel.num_threads() → int

Returns the library-wide thread limit (see set_num_threads).

vfhe.util.parallel.set_num_threads(n: int | None = None) → None

Limits the threads any vfhe operation may use to n.

None restores the default: VFHE_NUM_THREADS if set, otherwise 1.