Skip to content

Commit 315c76d

Browse files
committed
Set ITK to be single threaded in the characterize_data script.
The characterize_data script uses multi-processing for concurrency. ITK filters use multi-threading as part of each process. There is the potential for contention when too many threads are created as compared to the number of available cores on the CPU. The solution here is to set ITK to run in single threaded mode and the speedup is obtained from the parallel processes.
1 parent 7ab41da commit 315c76d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Python/scripts/characterize_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,14 @@ def xyz_to_index(x, y, z, thumbnail_size, tile_size):
10491049
)
10501050
return 1
10511051

1052+
# This script uses concurrent.futures ProcessPoolExecutor for parallel processing at
1053+
# the process level. ITK filters implement concurrency at the thread level.
1054+
# The combination of these two parallelization approaches can potentially be
1055+
# detrimental, as each of N processes creates M threads which can overwhelm a
1056+
# system if it has less than NM cores. We therefor configure SimpleITK to work
1057+
# in a single threaded fashion and only use process level parallelization.
1058+
sitk.ProcessObject.SetGlobalDefaultNumberOfThreads(1)
1059+
10521060
thumbnail_settings = {}
10531061
if args.create_summary_image:
10541062
thumbnail_settings["thumbnail_sizes"] = args.thumbnail_sizes

0 commit comments

Comments
 (0)