File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ void initialize_ctl(void) {
5656 }
5757}
5858
59+ // Benchmarks may fork multiple times and topology init is slow.
60+ // Init topology before fork (if not already) so children don't repeat it.
61+ // TODO: This is a hack. Better solution is needed.
62+ #if !defined(_WIN32 ) && !defined(UMF_NO_HWLOC )
63+ static void atfork_prepare (void ) { umfGetTopologyReduced (); }
64+ #endif
65+
5966umf_result_t umfInit (void ) {
6067 utils_init_once (& initMutexOnce , initialize_init_mutex );
6168
@@ -91,11 +98,11 @@ umf_result_t umfInit(void) {
9198 if (TRACKER ) {
9299 LOG_DEBUG ("UMF library initialized" );
93100 }
94- #if !defined(UMF_NO_HWLOC )
95- // some benchmarks uses multiple forks, and topology initialization is very slow
96- // so if we initialize topology before the first fork, we can get significant performance gain.
97- umfGetTopologyReduced ();
101+
102+ #if !defined(_WIN32 ) && !defined(UMF_NO_HWLOC )
103+ pthread_atfork (atfork_prepare , NULL , NULL );
98104#endif
105+
99106 return UMF_RESULT_SUCCESS ;
100107}
101108
You can’t perform that action at this time.
0 commit comments