Skip to content

Commit

Permalink
Update algo. for MPAS possible MPAS partition cores
Browse files Browse the repository at this point in the history
The old algorithm wasn't generating the breadth of parition
sizes that the E3SM team needs.  The updated algorithm seems
likely to generate nearly all of the partition sizes that
could conceivable be useful for a given mesh.
  • Loading branch information
xylar committed Mar 14, 2023
1 parent 568f36c commit c8a6117
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions compass/ocean/tests/global_ocean/files_for_e3sm/graph_partition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np


def get_core_list(ncells, max_cells_per_core=6000, min_cells_per_core=100):
def get_core_list(ncells, max_cells_per_core=30000, min_cells_per_core=2):
"""
Get a fairly exhaustive list of core counts to partition a given number of
cells into
Expand All @@ -26,15 +26,36 @@ def get_core_list(ncells, max_cells_per_core=6000, min_cells_per_core=100):
"""
min_graph_size = int(ncells / max_cells_per_core)
max_graph_size = int(ncells / min_cells_per_core)
n_power2 = 2**np.arange(1, 21)
n_multiples12 = 12 * np.arange(1, 9)

cores = n_power2
for power10 in range(3):
cores = np.concatenate([cores, 10**power10 * n_multiples12])

mask = np.logical_and(cores >= min_graph_size,
cores <= max_graph_size)
cores = cores[mask]

return cores
print(min_graph_size, max_graph_size)

cores = []
for candidate in range(min_graph_size, max_graph_size):
factors = _prime_factors(candidate)
twos = np.count_nonzero(factors == 2)
fives = np.count_nonzero(factors == 5)
gt_five = np.count_nonzero(factors > 5)
big_factor = factors.max()
if twos > 0 and fives <= twos and gt_five <= 1 and big_factor <= 7:
cores.append(candidate)
# small odd powers of 3 and a few that correspond to divisors of the
# ne30 (30x30x6=5400) size
elif candidate in [3, 9, 15, 21, 225, 675, 1350]:
cores.append(candidate)

return np.array(cores)


# https://stackoverflow.com/a/22808285
def _prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return np.array(factors)

0 comments on commit c8a6117

Please sign in to comment.