Skip to content

Commit 36b0332

Browse files
authored
Merge pull request mcdc-project#271 from alexandermote/dev
Variable-sized subdomains on CPU/GPU
2 parents a11382d + 81b49f2 commit 36b0332

9 files changed

Lines changed: 77 additions & 97 deletions

File tree

.github/workflows/regression_test-numba_cpu_mpi.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ jobs:
2626
pip list
2727
- name: Regression Test - Numba and MPI
2828
run: |
29-
cd test/regression
30-
python run.py --mode=numba --mpiexec=4
29+
cd test/regression
30+
python run.py --mode=numba --mpiexec=4
31+
python run.py --mode=numba --mpiexec=16 --name=slab_reed_dd_3d

.github/workflows/regression_test-python_mpi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ jobs:
2828
run: |
2929
cd test/regression
3030
python run.py --mpiexec=4
31+
python run.py --mpiexec=16 --name=slab_reed_dd_3d

mcdc/main.py

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,25 @@ def prepare():
861861
)
862862

863863
else: # decomposed mesh filters
864+
mcdc["technique"]["dd_xsum"] = len(input_deck.mesh_tallies[i].x) - 1
865+
mcdc["technique"]["dd_ysum"] = len(input_deck.mesh_tallies[i].y) - 1
866+
mcdc["technique"]["dd_zsum"] = len(input_deck.mesh_tallies[i].z) - 1
867+
864868
mxn, mxp, myn, myp, mzn, mzp = dd_mesh_bounds(i)
865869

866870
# Filters
867871
new_x = input_deck.mesh_tallies[i].x[mxn:mxp]
868872
new_y = input_deck.mesh_tallies[i].y[myn:myp]
869873
new_z = input_deck.mesh_tallies[i].z[mzn:mzp]
870-
mcdc["mesh_tallies"][i]["filter"]["x"] = new_x
871-
mcdc["mesh_tallies"][i]["filter"]["y"] = new_y
872-
mcdc["mesh_tallies"][i]["filter"]["z"] = new_z
874+
xlen = len(new_x)
875+
ylen = len(new_y)
876+
zlen = len(new_z)
877+
mcdc["mesh_tallies"][i]["filter"]["x"][:xlen] = new_x
878+
mcdc["mesh_tallies"][i]["filter"]["y"][:ylen] = new_y
879+
mcdc["mesh_tallies"][i]["filter"]["z"][:zlen] = new_z
880+
mcdc["technique"]["dd_xlen"] = xlen - 1
881+
mcdc["technique"]["dd_ylen"] = ylen - 1
882+
mcdc["technique"]["dd_zlen"] = zlen - 1
873883
for name in ["t", "mu", "azi", "g"]:
874884
N = len(getattr(input_deck.mesh_tallies[i], name))
875885
mcdc["mesh_tallies"][i]["filter"][name][:N] = getattr(
@@ -1632,9 +1642,9 @@ def dd_mergetally(mcdc, data):
16321642
d_Nz = input_deck.technique["dd_mesh"]["z"].size - 1
16331643

16341644
# capture tally lengths for reorganizing later
1635-
xlen = len(mcdc["mesh_tallies"][0]["filter"]["x"]) - 1
1636-
ylen = len(mcdc["mesh_tallies"][0]["filter"]["y"]) - 1
1637-
zlen = len(mcdc["mesh_tallies"][0]["filter"]["z"]) - 1
1645+
xlen = mcdc["technique"]["dd_xlen"]
1646+
ylen = mcdc["technique"]["dd_ylen"]
1647+
zlen = mcdc["technique"]["dd_zlen"]
16381648

16391649
# MPI gather
16401650
if (d_Nx * d_Ny * d_Nz) == MPI.COMM_WORLD.Get_size():
@@ -1648,6 +1658,10 @@ def dd_mergetally(mcdc, data):
16481658
MPI.COMM_WORLD.Gatherv(
16491659
sendbuf=tally[i], recvbuf=(dd_tally[i], sendcounts), root=0
16501660
)
1661+
# gather tally lengths for proper recombination
1662+
xlens = MPI.COMM_WORLD.gather(xlen, root=0)
1663+
ylens = MPI.COMM_WORLD.gather(ylen, root=0)
1664+
zlens = MPI.COMM_WORLD.gather(zlen, root=0)
16511665

16521666
# MPI gather for multiprocessor subdomains
16531667
else:
@@ -1669,6 +1683,10 @@ def dd_mergetally(mcdc, data):
16691683
# gather tallies
16701684
for i, t in enumerate(tally):
16711685
dd_comm.Gatherv(tally[i], (dd_tally[i], sendcounts), root=0)
1686+
# gather tally lengths for proper recombination
1687+
xlens = dd_comm.gather(xlen, root=0)
1688+
ylens = dd_comm.gather(ylen, root=0)
1689+
zlens = dd_comm.gather(zlen, root=0)
16721690
dd_group.Free()
16731691
if MPI.COMM_NULL != dd_comm:
16741692
dd_comm.Free()
@@ -1678,20 +1696,39 @@ def dd_mergetally(mcdc, data):
16781696
# reorganize tally data
16791697
# TODO: find/develop a more efficient algorithm for this
16801698
tally_idx = 0
1699+
offset = 0
1700+
ysum = mcdc["technique"]["dd_ysum"]
1701+
zsum = mcdc["technique"]["dd_zsum"]
16811702
for di in range(0, d_Nx * d_Ny * d_Nz):
16821703
dz = di // (d_Nx * d_Ny)
16831704
dy = (di % (d_Nx * d_Ny)) // d_Nx
16841705
dx = di % d_Nx
1706+
1707+
offset = 0
1708+
# calculate subdomain offset
1709+
for i in range(0, dx):
1710+
offset += xlens[i] * ysum * zsum
1711+
1712+
for i in range(0, dy):
1713+
y_ind = i * d_Nx
1714+
offset += ylens[y_ind] * zsum
1715+
1716+
for i in range(0, dz):
1717+
z_ind = i * d_Nx * d_Ny
1718+
offset += zlens[z_ind]
1719+
1720+
# calculate index within subdomain
1721+
xlen = xlens[di]
1722+
ylen = ylens[di]
1723+
zlen = zlens[di]
16851724
for xi in range(0, xlen):
16861725
for yi in range(0, ylen):
16871726
for zi in range(0, zlen):
16881727
# calculate reorganized index
1689-
ind_x = xi * (ylen * d_Ny * zlen * d_Nz) + dx * (
1690-
xlen * ylen * d_Ny * zlen * d_Nz
1691-
)
1692-
ind_y = yi * (xlen * d_Nx) + dy * (ylen * xlen * d_Nx)
1693-
ind_z = zi + dz * zlen
1694-
buff_idx = ind_x + ind_y + ind_z
1728+
ind_x = xi * ysum * zsum
1729+
ind_y = yi * zsum
1730+
ind_z = zi
1731+
buff_idx = offset + ind_x + ind_y + ind_z
16951732
# place tally value in correct position
16961733
buff[:, buff_idx] = dd_tally[:, tally_idx]
16971734
tally_idx += 1
@@ -1716,11 +1753,11 @@ def dd_mergemesh(mcdc, data):
17161753
MPI.COMM_WORLD.gather(len(mcdc["mesh_tallies"][0]["filter"]["x"]), root=0)
17171754
)
17181755
if mcdc["mpi_master"]:
1719-
x_filter = np.zeros((mcdc["mesh_tallies"].shape, sum(sendcounts)))
1756+
x_filter = np.zeros((mcdc["mesh_tallies"].shape[0], sum(sendcounts)))
17201757
else:
1721-
x_filter = np.empty((mcdc["mesh_tallies"].shape)) # dummy tally
1758+
x_filter = np.empty((mcdc["mesh_tallies"].shape[0])) # dummy tally
17221759
# gather mesh
1723-
for i in range(mcdc["mesh_tallies"].shape):
1760+
for i in range(mcdc["mesh_tallies"].shape[0]):
17241761
MPI.COMM_WORLD.Gatherv(
17251762
sendbuf=mcdc["mesh_tallies"][i]["filter"]["x"],
17261763
recvbuf=(x_filter[i], sendcounts),
@@ -1740,7 +1777,7 @@ def dd_mergemesh(mcdc, data):
17401777
else:
17411778
y_filter = np.empty((mcdc["mesh_tallies"].shape[0])) # dummy tally
17421779
# gather mesh
1743-
for i in range(mcdc["mesh_tallies"].shape):
1780+
for i in range(mcdc["mesh_tallies"].shape[0]):
17441781
MPI.COMM_WORLD.Gatherv(
17451782
sendbuf=mcdc["mesh_tallies"][i]["filter"]["y"],
17461783
recvbuf=(y_filter[i], sendcounts),
@@ -1786,7 +1823,7 @@ def dd_mergemesh(mcdc, data):
17861823
if d_Nz > 1:
17871824
dd_mesh.append(z_final)
17881825
else:
1789-
dd_mesh.append("z", mcdc["mesh_tallies"][:]["filter"]["z"])
1826+
dd_mesh.append(mcdc["mesh_tallies"][:]["filter"]["z"])
17901827
return dd_mesh
17911828

17921829

@@ -1876,9 +1913,9 @@ def generate_hdf5(data, mcdc):
18761913
# Set tally shape
18771914
N_score = tally["N_score"]
18781915
if mcdc["technique"]["domain_decomposition"]:
1879-
Nx *= input_deck.technique["dd_mesh"]["x"].size - 1
1880-
Ny *= input_deck.technique["dd_mesh"]["y"].size - 1
1881-
Nz *= input_deck.technique["dd_mesh"]["z"].size - 1
1916+
Nx = mcdc["technique"]["dd_xsum"]
1917+
Ny = mcdc["technique"]["dd_ysum"]
1918+
Nz = mcdc["technique"]["dd_zsum"]
18821919
if not mcdc["technique"]["uq"]:
18831920
shape = (3, Nmu, N_azi, Ng, Nt, Nx, Ny, Nz, N_score)
18841921
else:

mcdc/type_.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,12 @@ def dd_meshtally(input_deck):
742742
Nx = max(Nx, len(new_x))
743743
Ny = max(Ny, len(new_y))
744744
Nz = max(Nz, len(new_z))
745+
746+
# ensure all subdomains have equivalent tally sizes
747+
# (this is necessary for domain decomp to function on GPUs)
748+
Nx = MPI.COMM_WORLD.allreduce(Nx, MPI.MAX)
749+
Ny = MPI.COMM_WORLD.allreduce(Ny, MPI.MAX)
750+
Nz = MPI.COMM_WORLD.allreduce(Nz, MPI.MAX)
745751
return Nx, Ny, Nz
746752

747753

@@ -1108,6 +1114,12 @@ def make_type_technique(input_deck):
11081114
# Mesh
11091115
mesh, Nx, Ny, Nz, Nt, Nmu, N_azi, Ng = make_type_mesh(card["dd_mesh"])
11101116
struct += [("dd_mesh", mesh)]
1117+
struct += [("dd_xlen", int64)]
1118+
struct += [("dd_ylen", int64)]
1119+
struct += [("dd_zlen", int64)]
1120+
struct += [("dd_xsum", int64)]
1121+
struct += [("dd_ysum", int64)]
1122+
struct += [("dd_zsum", int64)]
11111123
struct += [("dd_idx", int64)]
11121124
struct += [("dd_sent", int64)]
11131125
struct += [("dd_work_ratio", int64, (len(card["dd_work_ratio"]),))]
-235 KB
Binary file not shown.

test/regression/cooper_dd/input.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/regression/run.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@
6363
+ "Note: Skipping %s (require multiple of 16 MPI ranks)" % name
6464
+ Style.RESET_ALL
6565
)
66-
elif name == "cooper_dd" and (
67-
not parallel_run or not (mpiexec % 8 == 0 and srun % 8 == 0)
68-
):
69-
temp.remove(name)
70-
print(
71-
Fore.YELLOW
72-
+ "Note: Skipping %s (require multiple of 8 MPI ranks)" % name
73-
+ Style.RESET_ALL
74-
)
7566

7667
names = temp
7768

41.7 KB
Binary file not shown.

test/regression/slab_reed_dd_3d/input.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060

6161
# Isotropic source in the first half of the outermost medium,
6262
# with 1/100 strength
63-
mcdc.source(x=[0.0, 4.0], y=[0.0, 4.0], z=[4.0, 6.0], isotropic=True, prob=0.5)
64-
mcdc.source(x=[4.0, 8.0], y=[0.0, 4.0], z=[4.0, 6.0], isotropic=True, prob=0.5)
65-
mcdc.source(x=[0.0, 4.0], y=[4.0, 8.0], z=[4.0, 6.0], isotropic=True, prob=0.5)
66-
mcdc.source(x=[4.0, 8.0], y=[4.0, 8.0], z=[4.0, 6.0], isotropic=True, prob=0.5)
63+
mcdc.source(x=[0.0, 4.0], y=[0.0, 4.0], z=[5.0, 6.0], isotropic=True, prob=0.5)
64+
mcdc.source(x=[4.0, 8.0], y=[0.0, 4.0], z=[5.0, 6.0], isotropic=True, prob=0.5)
65+
mcdc.source(x=[0.0, 4.0], y=[4.0, 8.0], z=[5.0, 6.0], isotropic=True, prob=0.5)
66+
mcdc.source(x=[4.0, 8.0], y=[4.0, 8.0], z=[5.0, 6.0], isotropic=True, prob=0.5)
6767

6868
# =============================================================================
6969
# Set tally, setting, and run mcdc

0 commit comments

Comments
 (0)