MCPcopy
hub / github.com/mapillary/OpenSfM / parallel_map

Function parallel_map

opensfm/context.py:32–48  ·  view source on GitHub ↗

Run function for all arguments using multiple processes.

(func, args, num_proc, max_batch_size=1)

Source from the content-addressed store, hash-verified

30
31# Parallel processes
32def parallel_map(func, args, num_proc, max_batch_size=1):
33 """Run function for all arguments using multiple processes."""
34 # De-activate/Restore any inner OpenCV threading
35 threads_used = cv2.getNumThreads()
36 cv2.setNumThreads(0)
37
38 num_proc = min(num_proc, len(args))
39 if num_proc <= 1:
40 res = list(map(func, args))
41 else:
42 with parallel_backend('loky', n_jobs=num_proc):
43 batch_size = max(1, int(len(args) / (num_proc * 2)))
44 batch_size = min(batch_size, max_batch_size) if max_batch_size else batch_size
45 res = Parallel(batch_size=batch_size)(delayed(func)(arg) for arg in args)
46
47 cv2.setNumThreads(threads_used)
48 return res
49
50
51# Memory usage

Callers 4

compute_depthmapsFunction · 0.90
compute_image_pairsFunction · 0.90
runMethod · 0.90

Calls 1

mapFunction · 0.85

Tested by

no test coverage detected