Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unnecessary Pool creation in searchlight #386

Merged
merged 3 commits into from Oct 16, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 27 additions & 10 deletions brainiak/searchlight/searchlight.py
Expand Up @@ -420,18 +420,35 @@ def run_block_function(self, block_fn, extra_block_fn_params=None,
processes = usable_cpus
else:
processes = min(pool_size, usable_cpus)
with Pool(processes) as pool:

if processes > 1:
with Pool(processes) as pool:
for idx, block in enumerate(self.blocks):
result = pool.apply_async(
block_fn,
([subproblem[idx] for subproblem in self.subproblems],
self.submasks[idx],
self.sl_rad,
self.bcast_var,
extra_block_fn_params))
results.append((block[0], result))
local_outputs = [(result[0], result[1].get())
for result in results]
else:
# If we only are using one CPU core, no need to create a Pool, cause an underlying
# fork(), and send the data to that process. Just do it here in serial. This
# will save copying the memory and will stop a fork() which can cause problems in
# some MPI implementations.
for idx, block in enumerate(self.blocks):
result = pool.apply_async(
block_fn,
([subproblem[idx] for subproblem in self.subproblems],
self.submasks[idx],
self.sl_rad,
self.bcast_var,
extra_block_fn_params))
subprob_list = [subproblem[idx] for subproblem in self.subproblems]
result = block_fn(
subprob_list,
self.submasks[idx],
self.sl_rad,
self.bcast_var,
extra_block_fn_params)
results.append((block[0], result))
local_outputs = [(result[0], result[1].get())
for result in results]
local_outputs = [(result[0], result[1]) for result in results]

# Collect results
global_outputs = self.comm.gather(local_outputs)
Expand Down