Coverage for pySDC/projects/parallelSDC_reloaded/scripts/fig06_allenCahnMPI_plot.py: 100%
55 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 14:51 +0000
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Created on Thu Jan 11 11:14:01 2024
6Figures with experiments on the Allen-Cahn problem (MPI runs)
7"""
8import os
9import json
10import numpy as np
12from pySDC.projects.parallelSDC_reloaded.utils import plt
14PATH = '/' + os.path.join(*__file__.split('/')[:-1])
15SCRIPT = __file__.split('/')[-1].split('.')[0]
17fileName = f"{PATH}/fig06_compTime.json"
18timings = {}
19with open(fileName, "r") as f:
20 timings = json.load(f)
22minPrec = ["MIN-SR-NS", "MIN-SR-S", "MIN-SR-FLEX"]
24symList = ['^', '>', '<', 'o', 's', '*', 'p']
25config = [
26 (*minPrec, "VDHS", "ESDIRK43", "LU"),
27]
28nStepsList = np.array([5, 10, 20, 50, 100, 200, 500])
29tEnd = 50
30dtVals = tEnd / nStepsList
32# -----------------------------------------------------------------------------
33# %% Error VS cost plots
34# -----------------------------------------------------------------------------
35for qDeltaList in config:
36 figNameConv = f"{SCRIPT}_conv_1"
37 figNameCost = f"{SCRIPT}_cost_1"
39 for qDelta, sym in zip(qDeltaList, symList):
40 if qDelta == "MIN-SR-NS":
41 res = timings["MIN-SR-S_MPI"].copy()
42 res["errors"] = [np.nan for _ in res["errors"]]
43 elif qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]:
44 res = timings[f"{qDelta}_MPI"]
45 else:
46 res = timings[qDelta]
48 errors = res["errors"]
49 costs = res["costs"]
51 ls = '-' if qDelta.startswith("MIN-SR-") else "--"
53 plt.figure(figNameConv)
54 plt.loglog(dtVals, errors, sym + ls, label=qDelta)
56 plt.figure(figNameCost)
57 plt.loglog(costs, errors, sym + ls, label=qDelta)
59 for figName in [figNameConv, figNameCost]:
60 plt.figure(figName)
61 plt.gca().set(
62 xlabel="Computation Time [s]" if "cost" in figName else r"$\Delta {t}$",
63 ylabel=r"$L_2$ error at $T$",
64 )
65 plt.legend()
66 plt.grid(True)
67 plt.tight_layout()
68 plt.savefig(f"{PATH}/{figName}.pdf")
70# -----------------------------------------------------------------------------
71# %% Speedup tables
72# -----------------------------------------------------------------------------
73header = f"{'dt size':12} |"
74header += '|'.join(f" {dt:1.1e} " for dt in dtVals)
75print(header)
76print("-" * len(header))
77meanEff = 0
78for qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]:
79 seq = timings[f"{qDelta}"]
80 par = timings[f"{qDelta}_MPI"]
81 assert np.allclose(
82 seq["errors"], par["errors"], atol=1e-6
83 ), f"parallel and sequential errors are not close for {qDelta}"
84 tComp = seq["costs"]
85 tCompMPI = par["costs"]
86 meanEff += np.mean([tS / tP for tP, tS in zip(tCompMPI, tComp)])
87 print(f"{qDelta:12} |" + '|'.join(f" {tS/tP:1.1f} ({tS/tP/4*100:1.0f}%) " for tP, tS in zip(tCompMPI, tComp)))
88meanEff /= 3
89print("Mean parallel efficiency :", meanEff / 4)