Skip to content

Commit

Permalink
Simplify the algorithm for domain decomposition to make sure it works…
Browse files Browse the repository at this point in the history
… for all cases
  • Loading branch information
IshaanDesai committed Feb 3, 2025
1 parent 21fe820 commit 04323c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
39 changes: 11 additions & 28 deletions micro_manager/domain_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,23 @@ def decompose_macro_domain(self, macro_bounds: list, ranks_per_axis: list) -> li
np.prod(ranks_per_axis) == self._size
), "Total number of processors provided in the Micro Manager configuration and in the MPI execution command do not match."

for z in range(ranks_per_axis[2]):
for y in range(ranks_per_axis[1]):
for x in range(ranks_per_axis[0]):
n = (
x
+ y * ranks_per_axis[0]
+ z * ranks_per_axis[0] * ranks_per_axis[1]
)
if n == self._rank:
rank_in_axis = [x, y, z]

dx = []
for d in range(self._dims):
dx.append(
abs(macro_bounds[d * 2 + 1] - macro_bounds[d * 2]) / ranks_per_axis[d]
)

rank_in_axis: list[int] = [0] * self._dims
if ranks_per_axis[0] == 1: # if serial in x axis
rank_in_axis[0] = 0
else:
rank_in_axis[0] = self._rank % ranks_per_axis[0] # x axis

if self._dims == 2:
if ranks_per_axis[1] == 1: # if serial in y axis
rank_in_axis[1] = 0
else:
rank_in_axis[1] = int(self._rank / ranks_per_axis[0]) # y axis
elif self._dims == 3:
if ranks_per_axis[2] == 1: # if serial in z axis
rank_in_axis[2] = 0
else:
rank_in_axis[2] = int(
self._rank / (ranks_per_axis[0] * ranks_per_axis[1])
) # z axis

if ranks_per_axis[1] == 1: # if serial in y axis
rank_in_axis[1] = 0
else:
rank_in_axis[1] = (
self._rank - ranks_per_axis[0] * ranks_per_axis[1] * rank_in_axis[2]
) % ranks_per_axis[
2
] # y axis

mesh_bounds = []
for d in range(self._dims):
if rank_in_axis[d] > 0:
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_domain_decomposition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from unittest import TestCase
from unittest.mock import MagicMock

import numpy as np

Expand All @@ -17,6 +17,23 @@ def setUp(self) -> None:
8,
] # Cuboid which is not symmetric around origin

def test_rank1_out_of_4_3d(self):
"""
Check bounds for rank 1 in a setting of axis-wise ranks: [2, 2, 1]
"""
rank = 1
size = 4
ranks_per_axis = [2, 2, 1]
domain_decomposer = DomainDecomposer(3, rank, size)
domain_decomposer._dims = 3
mesh_bounds = domain_decomposer.decompose_macro_domain(
self._macro_bounds_3d, ranks_per_axis
)

print("mesh_bounds", mesh_bounds)

self.assertTrue(np.allclose(mesh_bounds, [0.0, 1, -2, 0.0, -2, 8]))

def test_rank5_outof_10_3d(self):
"""
Test domain decomposition for rank 5 in a setting of axis-wise ranks: [1, 2, 5]
Expand Down

0 comments on commit 04323c5

Please sign in to comment.