-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TL: first revision for the parallel SDC theory paper (#481)
* TL: dump version * TL: added MPI script for pSDC theory paper * TL: adapted script for parallel computation * TL: minor detail for output * TL: mini-fixes and black * TL: update for plots * TL: upload reference data from jusuf runs * TL: minor modifications * TL: prepared PR * TL: fix linting error * TL: added missing dependency for project tests * TL: another detail * TL: eventually <=> finally apparently
- Loading branch information
Showing
14 changed files
with
402 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ dependencies: | |
- matplotlib>=3.0 | ||
- dill>=0.2.6 | ||
- scipy>=0.17.1 | ||
- mpich | ||
- mpi4py>=3.0.0 | ||
- pip | ||
- pip: | ||
- qmat>=0.1.8 |
107 changes: 107 additions & 0 deletions
107
pySDC/projects/parallelSDC_reloaded/scripts/fig06_allenCahnMPI.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Jan 11 11:14:01 2024 | ||
Figures with experiments on the Allen-Cahn problem (MPI runs) | ||
""" | ||
import os | ||
import sys | ||
import json | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
from pySDC.projects.parallelSDC_reloaded.utils import solutionExact, getParamsSDC, solutionSDC, getParamsRK | ||
from pySDC.implementations.sweeper_classes.generic_implicit_MPI import generic_implicit_MPI | ||
|
||
PATH = '/' + os.path.join(*__file__.split('/')[:-1]) | ||
SCRIPT = __file__.split('/')[-1].split('.')[0] | ||
|
||
COMM_WORLD = MPI.COMM_WORLD | ||
|
||
# SDC parameters | ||
nNodes = 4 | ||
quadType = 'RADAU-RIGHT' | ||
nodeType = 'LEGENDRE' | ||
parEfficiency = 0.8 # 1/nNodes | ||
nSweeps = 4 | ||
|
||
# Problem parameters | ||
pName = "ALLEN-CAHN" | ||
tEnd = 50 | ||
pParams = { | ||
"periodic": False, | ||
"nvars": 2**11 - 1, | ||
"epsilon": 0.04, | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
# %% Convergence and error VS cost plots | ||
# ----------------------------------------------------------------------------- | ||
nStepsList = np.array([5, 10, 20, 50, 100, 200, 500]) | ||
dtVals = tEnd / nStepsList | ||
|
||
|
||
def getError(uNum, uRef): | ||
if uNum is None: | ||
return np.inf | ||
return np.linalg.norm(uRef[-1, :] - uNum[-1, :], ord=2) | ||
|
||
|
||
def getCost(counters): | ||
_, _, tComp = counters | ||
return tComp | ||
|
||
|
||
try: | ||
qDelta = sys.argv[1] | ||
if qDelta.startswith("--"): | ||
qDelta = "MIN-SR-FLEX" | ||
except IndexError: | ||
qDelta = "MIN-SR-FLEX" | ||
|
||
try: | ||
params = getParamsRK(qDelta) | ||
except KeyError: | ||
params = getParamsSDC(quadType=quadType, numNodes=nNodes, nodeType=nodeType, qDeltaI=qDelta, nSweeps=nSweeps) | ||
|
||
useMPI = False | ||
if COMM_WORLD.Get_size() == 4 and qDelta in ["MIN-SR-NS", "MIN-SR-S", "MIN-SR-FLEX", "VDHS"]: # pragma: no cover | ||
params['sweeper_class'] = generic_implicit_MPI | ||
useMPI = True | ||
|
||
errors = [] | ||
costs = [] | ||
|
||
root = COMM_WORLD.Get_rank() == 0 | ||
if root: | ||
print(f"Running simulation with {qDelta}") | ||
|
||
for nSteps in nStepsList: | ||
if root: | ||
uRef = solutionExact(tEnd, nSteps, pName, **pParams) | ||
|
||
uSDC, counters, parallel = solutionSDC(tEnd, nSteps, params, pName, verbose=root, noExcept=True, **pParams) | ||
|
||
if root: | ||
err = getError(uSDC, uRef) | ||
errors.append(err) | ||
|
||
cost = getCost(counters) | ||
costs.append(cost) | ||
|
||
if COMM_WORLD.Get_rank() == 0: | ||
errors = [float(e) for e in errors] | ||
|
||
print("errors : ", errors) | ||
print("tComps : ", costs) | ||
fileName = f"{PATH}/fig06_compTime.json" | ||
timings = {} | ||
if os.path.isfile(fileName): | ||
with open(fileName, "r") as f: | ||
timings = json.load(f) | ||
|
||
timings[qDelta + "_MPI" * useMPI] = {"errors": errors, "costs": costs} | ||
|
||
with open(fileName, 'w') as f: | ||
json.dump(timings, f, indent=4) |
89 changes: 89 additions & 0 deletions
89
pySDC/projects/parallelSDC_reloaded/scripts/fig06_allenCahnMPI_plot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Jan 11 11:14:01 2024 | ||
Figures with experiments on the Allen-Cahn problem (MPI runs) | ||
""" | ||
import os | ||
import json | ||
import numpy as np | ||
|
||
from pySDC.projects.parallelSDC_reloaded.utils import plt | ||
|
||
PATH = '/' + os.path.join(*__file__.split('/')[:-1]) | ||
SCRIPT = __file__.split('/')[-1].split('.')[0] | ||
|
||
fileName = f"{PATH}/fig06_compTime.json" | ||
timings = {} | ||
with open(fileName, "r") as f: | ||
timings = json.load(f) | ||
|
||
minPrec = ["MIN-SR-NS", "MIN-SR-S", "MIN-SR-FLEX"] | ||
|
||
symList = ['^', '>', '<', 'o', 's', '*', 'p'] | ||
config = [ | ||
(*minPrec, "VDHS", "ESDIRK43", "LU"), | ||
] | ||
nStepsList = np.array([5, 10, 20, 50, 100, 200, 500]) | ||
tEnd = 50 | ||
dtVals = tEnd / nStepsList | ||
|
||
# ----------------------------------------------------------------------------- | ||
# %% Error VS cost plots | ||
# ----------------------------------------------------------------------------- | ||
for qDeltaList in config: | ||
figNameConv = f"{SCRIPT}_conv_1" | ||
figNameCost = f"{SCRIPT}_cost_1" | ||
|
||
for qDelta, sym in zip(qDeltaList, symList): | ||
if qDelta == "MIN-SR-NS": | ||
res = timings["MIN-SR-S_MPI"].copy() | ||
res["errors"] = [np.nan for _ in res["errors"]] | ||
elif qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]: | ||
res = timings[f"{qDelta}_MPI"] | ||
else: | ||
res = timings[qDelta] | ||
|
||
errors = res["errors"] | ||
costs = res["costs"] | ||
|
||
ls = '-' if qDelta.startswith("MIN-SR-") else "--" | ||
|
||
plt.figure(figNameConv) | ||
plt.loglog(dtVals, errors, sym + ls, label=qDelta) | ||
|
||
plt.figure(figNameCost) | ||
plt.loglog(costs, errors, sym + ls, label=qDelta) | ||
|
||
for figName in [figNameConv, figNameCost]: | ||
plt.figure(figName) | ||
plt.gca().set( | ||
xlabel="Computation Time" if "cost" in figName else r"$\Delta {t}$", | ||
ylabel=r"$L_2$ error at $T$", | ||
) | ||
plt.legend() | ||
plt.grid(True) | ||
plt.tight_layout() | ||
plt.savefig(f"{PATH}/{figName}.pdf") | ||
|
||
# ----------------------------------------------------------------------------- | ||
# %% Speedup tables | ||
# ----------------------------------------------------------------------------- | ||
header = f"{'dt size':12} |" | ||
header += '|'.join(f" {dt:1.1e} " for dt in dtVals) | ||
print(header) | ||
print("-" * len(header)) | ||
meanEff = 0 | ||
for qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]: | ||
seq = timings[f"{qDelta}"] | ||
par = timings[f"{qDelta}_MPI"] | ||
assert np.allclose( | ||
seq["errors"], par["errors"], atol=1e-6 | ||
), f"parallel and sequential errors are not close for {qDelta}" | ||
tComp = seq["costs"] | ||
tCompMPI = par["costs"] | ||
meanEff += np.mean([tS / tP for tP, tS in zip(tCompMPI, tComp)]) | ||
print(f"{qDelta:12} |" + '|'.join(f" {tS/tP:1.1f} ({tS/tP/4*100:1.0f}%) " for tP, tS in zip(tCompMPI, tComp))) | ||
meanEff /= 3 | ||
print("Mean parallel efficiency :", meanEff / 4) |
Oops, something went wrong.