Skip to content

Commit 19c5b8f

Browse files
Merge pull request #1506 from lplewa/v1.0.x
initialize hwloc topology only before first fork, not always
2 parents aea2135 + 3fd44ee commit 19c5b8f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/libumf.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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+
5966
umf_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

0 commit comments

Comments
 (0)