Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use task scheduler handle
  • Loading branch information
Ivan Butygin ivan.butygin
Ivan Butygin authored and ivan.butygin committed Mar 22, 2021
commit f960964c352b094062702706cdde1e799ee5d949
20 changes: 19 additions & 1 deletion numba/np/ufunc/tbbpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Implement parallel vectorize workqueue on top of Intel TBB.
#endif

#define HAS_TASK_SCHEDULER_INIT (TBB_INTERFACE_VERSION < 12002)
#define HAS_TASK_SCHEDULER_HANDLE (TBB_INTERFACE_VERSION >= 12003)

#if HAS_TASK_SCHEDULER_INIT
#define TSI_INIT(count) tbb::task_scheduler_init(count)
Expand All @@ -48,6 +49,10 @@ static tbb::task_scheduler_init *tsi = NULL;
static int tsi_count = 0;
#endif

#if HAS_TASK_SCHEDULER_HANDLE
static tbb::task_scheduler_handle tsh;
#endif

#ifdef _MSC_VER
#define THREAD_LOCAL(ty) __declspec(thread) ty
#else
Expand Down Expand Up @@ -261,6 +266,12 @@ static void prepare_fork(void)
}
}
#endif
#if HAS_TASK_SCHEDULER_HANDLE
if (!tbb::finalize(tsh, std::nothrow))
{
puts("Unable to join threads to shut down before fork(). It can break multithreading in child process\n");
}
#endif
}

static void reset_after_fork(void)
Expand Down Expand Up @@ -303,6 +314,10 @@ static void unload_tbb(void)
tsi = NULL;
}
#endif
#if HAS_TASK_SCHEDULER_HANDLE
// bloking terminate is not strictly required here, ignore return value
(void)tbb::finalize(tsh, std::nothrow);
#endif
}
#endif

Expand All @@ -320,6 +335,10 @@ static void launch_threads(int count)
tsi_count = count;
tsi = new tbb::task_scheduler_init(count);
#endif

#if HAS_TASK_SCHEDULER_HANDLE
tsh = tbb::task_scheduler_handle::get();
#endif
tg = new tbb::task_group;
tg->run([] {}); // start creating threads asynchronously

Expand All @@ -341,7 +360,6 @@ static void ready(void)
{
}


MOD_INIT(tbbpool)
{
PyObject *m;
Expand Down