File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ void initialize_ctl(void) {
56
56
}
57
57
}
58
58
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
+
59
66
umf_result_t umfInit (void ) {
60
67
utils_init_once (& initMutexOnce , initialize_init_mutex );
61
68
@@ -91,11 +98,11 @@ umf_result_t umfInit(void) {
91
98
if (TRACKER ) {
92
99
LOG_DEBUG ("UMF library initialized" );
93
100
}
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 );
98
104
#endif
105
+
99
106
return UMF_RESULT_SUCCESS ;
100
107
}
101
108
You can’t perform that action at this time.
0 commit comments