[docs]defget_max_num_threads():""" Return the maximum number of C++ threads that will be allowed for computation. Note that this is the maximum number of compute threads managed via Intel's Threading Building blocks. Sire additionally uses a small number of lightweight background threads for management, which are unaffected by this setting. """from.legacyimportBaseas_Basereturn_Base.get_max_num_threads()
[docs]defset_max_num_threads(n:int):""" Set the maximum number of C++ threads that will be allowed for computation. Note that this is the maximum number of compute threads managed via Intel's Threading Building blocks. Sire additionally uses a small number of lightweight background threads for management, which are unaffected by this setting. """from.legacyimportBaseas_Base_Base.set_max_num_threads(n)
[docs]defset_default_num_threads():""" Set a reasonable default number of C++ threads that will be allowed for computation. Note that this is the maximum number of compute threads managed via Intel's Threading Building blocks. Sire additionally uses a small number of lightweight background threads for management, which are unaffected by this setting. """importosas_osfrom.legacyimportBaseas_Basetry:n=int(_os.environ["TBB_NUM_THREADS"])exceptException:try:n=int(_os.environ["OMP_NUM_THREADS"])exceptException:n=NoneifnisNone:_Base.set_default_num_threads()else:ifn<1:n=1_Base.set_max_num_threads(n)
# start off setting the default number - this will take into# account any environment variables that have been setset_default_num_threads()