Skip to content

Commit

Permalink
Add parallelization management
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuhlich committed Oct 25, 2023
1 parent 134b4cb commit c24cb7d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions roadie/scripts/recyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ def run(self):
parser.add_argument('--w', type=int, required=False, default=None, help="Crop Width")
parser.add_argument('--h', type=int, required=False, default=None, help="Crop Height")
parser.add_argument('--channels', type=int, nargs="+", required=False, default=None, help="Channels")
parser.add_argument(
'--num-threads', type=int, required=False, default=0, metavar="N",
help="Worker thread count (Default: auto-scale based on number of available CPUs)",
)
argument = parser.parse_args()

# Automatically infer the output filename, if not specified
Expand All @@ -256,6 +260,15 @@ def run(self):
stem = os.extsep.join(tokens[0:-1]) + "_crop"
out_path = os.extsep.join([stem, tokens[-1]])

num_threads = argument.num_threads
if num_threads == 0:
if hasattr(os, "sched_getaffinity"):
num_threads = len(os.sched_getaffinity(0))
else:
num_threads = os.cpu_count()
tifffile.TIFF.MAXWORKERS = num_threads
tifffile.TIFF.MAXIOWORKERS = num_threads * 5

writer = PyramidWriter(in_path, out_path, argument.channels, argument.x, argument.y,
argument.x2, argument.y2, argument.w, argument.h)
writer.run()

0 comments on commit c24cb7d

Please sign in to comment.