Skip to content

Commit

Permalink
Stop using coupling mesh vertex ids as global ids of micro simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Feb 11, 2025
1 parent f448bbf commit 5423f19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
12 changes: 9 additions & 3 deletions micro_manager/adaptivity/global_adaptivity_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def redistribute_sims(self, micro_sims: list) -> None:

def _redistribute_active_sims(self, micro_sims: list) -> None:
"""
Redistribute simulations among ranks.
Redistribute active simulations as per the configured load balancing settings.
Parameters
----------
Expand Down Expand Up @@ -126,6 +126,7 @@ def _redistribute_active_sims(self, micro_sims: list) -> None:

if n_global_send_sims == 0 or n_global_recv_sims == 0:
self._nothing_to_balance = True
# TODO: Add a warning log before returning
return

if n_global_send_sims < n_global_recv_sims:
Expand Down Expand Up @@ -175,9 +176,14 @@ def _redistribute_active_sims(self, micro_sims: list) -> None:
self._communicate_micro_sims(micro_sims, send_map, recv_map)
# TODO: Add a warning if the probable send or receive requests are zero, because then two step load balancing does not happen

def _redistribute_inactive_sims(self, micro_sims):
def _redistribute_inactive_sims(self, micro_sims: list) -> None:
"""
...
Redistribute inactive simulations based on where the associated active simulations are.
Parameters
----------
micro_sims : list
List of objects of class MicroProblem, which are the micro simulations
"""
ranks_of_sims = self._get_ranks_of_sims()

Expand Down
29 changes: 18 additions & 11 deletions micro_manager/micro_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, config_file: str) -> None:
)
self._interpolate_crashed_sims = False
else:
# The following parameters can potentially become configurable by the user in the future
# TODO: Make these parameters configurable
self._crash_threshold = 0.2
self._number_of_nearest_neighbors = 4

Expand Down Expand Up @@ -446,14 +446,11 @@ def initialize(self) -> None:
self._data_for_adaptivity[name] = [0] * self._local_number_of_sims

# Create lists of local and global IDs
if self._is_adaptivity_with_load_balancing:
sim_id = np.sum(nms_all_ranks[: self._rank])
self._global_ids_of_local_sims = [] # DECLARATION
for i in range(self._local_number_of_sims):
self._global_ids_of_local_sims.append(sim_id)
sim_id += 1
else:
self._global_ids_of_local_sims = list(self._mesh_vertex_ids)
sim_id = np.sum(nms_all_ranks[: self._rank])
self._global_ids_of_local_sims = [] # DECLARATION
for i in range(self._local_number_of_sims):
self._global_ids_of_local_sims.append(sim_id)
sim_id += 1

# Setup for simulation crashes
self._has_sim_crashed = [False] * self._local_number_of_sims
Expand Down Expand Up @@ -656,14 +653,19 @@ def _read_data_from_precice(self, dt) -> list:
"""
read_data: dict[str, list] = dict()

if self._is_adaptivity_with_load_balancing:
read_vertex_ids = self._global_ids_of_local_sims
else:
read_vertex_ids = self._mesh_vertex_ids

for name in self._read_data_names:
read_data[name] = []

for name in self._read_data_names:
read_data.update(
{
name: self._participant.read_data(
self._macro_mesh_name, name, self._global_ids_of_local_sims, dt
self._macro_mesh_name, name, read_vertex_ids, dt
)
}
)
Expand All @@ -683,6 +685,11 @@ def _write_data_to_precice(self, data: list) -> None:
data : list
List of dicts in which keys are names of data and the values are the data to be written to preCICE.
"""
if self._is_adaptivity_with_load_balancing:
write_vertex_ids = self._global_ids_of_local_sims
else:
write_vertex_ids = self._mesh_vertex_ids

data_dict: dict[str, list] = dict()
if not self._is_rank_empty:
for name in data[0]:
Expand All @@ -696,7 +703,7 @@ def _write_data_to_precice(self, data: list) -> None:
self._participant.write_data(
self._macro_mesh_name,
dname,
self._global_ids_of_local_sims,
write_vertex_ids,
data_dict[dname],
)
else:
Expand Down

0 comments on commit 5423f19

Please sign in to comment.