-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
communicate with mpi_comm_spawn_child
- Loading branch information
Showing
4 changed files
with
45 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
"""Script for running parallel simulations with MPI when called with mpiexec. | ||
This script is called directly from MPIBackend.simulate() | ||
""" | ||
|
||
# Authors: Blake Caldwell <[email protected]> | ||
# Ryan Thorpe <[email protected]> | ||
|
||
from hnn_core.network_builder import _simulate_single_trial | ||
|
||
|
||
class MPISimulation(object): | ||
"""The MPISimulation class. | ||
Parameters | ||
---------- | ||
skip_mpi_import : bool | None | ||
|
@@ -22,6 +30,7 @@ def __init__(self, skip_mpi_import=False): | |
else: | ||
from mpi4py import MPI | ||
|
||
self.intercomm = MPI.Comm.Get_parent() | ||
self.comm = MPI.COMM_WORLD | ||
self.rank = self.comm.Get_rank() | ||
|
||
|
@@ -31,5 +40,32 @@ def __enter__(self): | |
def __exit__(self, type, value, traceback): | ||
# skip Finalize() if we didn't import MPI on __init__ | ||
if hasattr(self, 'comm'): | ||
from mpi4py import MPI | ||
MPI.Finalize() | ||
self.intercomm.Disconnect() | ||
|
||
def _read_net(self): | ||
"""Read net and associated objects broadcasted to all ranks on stdin""" | ||
|
||
return self.intercomm.bcast(None, root=0) | ||
|
||
def run(self, net, tstop, dt, n_trials): | ||
"""Run MPI simulation(s) and write results to stderr""" | ||
|
||
sim_data = [] | ||
for trial_idx in range(n_trials): | ||
single_sim_data = _simulate_single_trial(net, tstop, dt, trial_idx) | ||
|
||
# go ahead and append trial data for each rank, though | ||
# only rank 0 has data that should be sent back to MPIBackend | ||
sim_data.append(single_sim_data) | ||
|
||
return sim_data | ||
|
||
|
||
if __name__ == '__main__': | ||
"""This file is called on command-line from nrniv""" | ||
|
||
with MPISimulation() as mpi_sim: | ||
net, tstop, dt, n_trials = mpi_sim._read_net() | ||
sim_data = mpi_sim.run(net, tstop, dt, n_trials) | ||
if mpi_sim.rank == 0: | ||
mpi_sim.intercomm.send(sim_data, dest=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters