vfhe.util.parallel¶
Sets how many threads vfhe uses: one library-wide limit, and a local one per thread.
set_num_threadsandnum_threadsset and read the library-wide limit. Functions takingn_threadsnever exceed it, and their defaultn_threads=0means “up to the limit”.local_num_threadslowers the limit for the vfhe calls the current thread makes inside awithblock.
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.0sets 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.Nonerestores the default:VFHE_NUM_THREADSif set, otherwise 1.