@@ -40,6 +40,39 @@ extern "C" {
4040/*Set the number of threads on runtime.*/
4141void openblas_set_num_threads (int num_threads );
4242void goto_set_num_threads (int num_threads );
43+ /*
44+ * Intent:
45+ * Sets the thread-local number of threads that OpenBLAS functions should request.
46+ * This thread-local number only affects the current execution thread
47+ * and, when set, overrides the global default.
48+ * This is useful for controlling nested parallelism.
49+ * For example when the caller's own (e.g. OpenMP) threads each invoke
50+ * OpenBLAS, `num_threads` determines how many threads OpenBLAS may use
51+ * per such call, instead of the process-wide default of
52+ * `omp_get_max_threads()`.
53+ *
54+ * The intent of this was likely to match MKL's `mkl_set_num_threads_local()`
55+ * but implementation may not live up to the original intent yet.
56+ *
57+ * TODO:
58+ * Currently the implementation doesn't really do any of that:
59+ * * The setting is NOT thread-local.
60+ * * This function currently just calls `openblas_set_num_threads(num_threads)`,
61+ * changing the same process-wide thread count as that function,
62+ * and additionally records `num_threads` in an internal (global, not per-thread)
63+ * variable that is only consulted when OpenBLAS is invoked from within
64+ * a caller's OpenMP parallel region and the user has not made an
65+ * explicit thread-count choice.
66+ * * There is no special handling of `num_threads == 0`
67+ * (or other MKL-style reset values); the value is forwarded to
68+ * `openblas_set_num_threads()`, where values < 1 are treated
69+ * as "use the default" and large values are clamped to the number of cores.
70+ *
71+ * Returns the *previous* number of threads (as reported by
72+ * `openblas_get_num_threads()`), so the caller can save and later restore it.
73+ *
74+ * On single-threaded OpenBLAS builds this is a no-op that returns 1.
75+ */
4376int openblas_set_num_threads_local (int num_threads );
4477
4578/*Get the number of threads on runtime.*/
0 commit comments