Skip to content

Commit

Permalink
Making the Micro Manager interface compliant to dynamic load balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Jan 15, 2025
1 parent 19ce49e commit 79ccc91
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion micro_manager/adaptivity/global_adaptivity_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def __init__(
comm : MPI.COMM_WORLD
Global communicator of MPI.
"""
super().__init__(configurator, rank)
super().__init__(configurator, global_number_of_sims, global_ids, rank, comm)
42 changes: 38 additions & 4 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

from .micro_simulation import create_simulation_class
from .tools.logging_wrapper import Logger
from .tools.misc import divide_in_parts


try:
Expand Down Expand Up @@ -123,6 +124,9 @@ def __init__(self, config_file: str) -> None:
self._config.is_adaptivity_with_load_balancing()
)

if self._is_adaptivity_with_load_balancing:
self._load_balancing_n = self._config.get_load_balancing_n()

self._adaptivity_output_n = self._config.get_adaptivity_output_n()
self._output_adaptivity_cpu_time = self._config.output_adaptivity_cpu_time()

Expand Down Expand Up @@ -320,10 +324,7 @@ def initialize(self) -> None:
self._local_number_of_sims, _ = self._mesh_vertex_coords.shape
else: # When load balancing, each rank needs to manually determine how many micro simulations it starts with
total_number_of_sims, _ = self._mesh_vertex_coords.shape
quotient, remainder = divmod(total_number_of_sims, self._size) # cp
cpu_wise_number_of_sims = [quotient + 1] * remainder + [quotient] * (
self._size - remainder
) # cp
cpu_wise_number_of_sims = divide_in_parts(total_number_of_sims, self._size)
self._local_number_of_sims = cpu_wise_number_of_sims[self._rank]

if self._local_number_of_sims == 0:
Expand Down Expand Up @@ -619,6 +620,39 @@ def _read_data_from_precice(self, dt) -> list:

return [dict(zip(read_data, t)) for t in zip(*read_data.values())]

def read_data_from_precice_lb(self, dt) -> list:
"""
Read data from preCICE for load balancing.
Parameters
----------
dt : float
Time step size at which data is to be read from preCICE.
Returns
-------
local_read_data : list
List of dicts in which keys are names of data being read and the values are the data from preCICE.
"""
read_data: Dict[str, list] = dict()
for name in self._read_data_names.keys():
read_data[name] = []

for name in self._read_data_names.keys():
read_data.update(
{
name: self._participant.read_data(
self._macro_mesh_name, name, self._mesh_vertex_ids, dt
)
}
)

if self._is_adaptivity_on:
if name in self._adaptivity_macro_data_names:
self._data_for_adaptivity[name] = read_data[name]

return [dict(zip(read_data, t)) for t in zip(*read_data.values())]

def _write_data_to_precice(self, data: list) -> None:
"""
Write data to preCICE.
Expand Down

0 comments on commit 79ccc91

Please sign in to comment.