Coverage for pySDC / projects / parallelSDC_reloaded / scripts / fig06_allenCahnMPI_plot.py: 100%

55 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-12 11:13 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4Created on Thu Jan 11 11:14:01 2024 

5 

6Figures with experiments on the Allen-Cahn problem (MPI runs) 

7""" 

8 

9import os 

10import json 

11import numpy as np 

12 

13from pySDC.projects.parallelSDC_reloaded.utils import plt 

14 

15PATH = '/' + os.path.join(*__file__.split('/')[:-1]) 

16SCRIPT = __file__.split('/')[-1].split('.')[0] 

17 

18fileName = f"{PATH}/fig06_compTime.json" 

19timings = {} 

20with open(fileName, "r") as f: 

21 timings = json.load(f) 

22 

23minPrec = ["MIN-SR-NS", "MIN-SR-S", "MIN-SR-FLEX"] 

24 

25symList = ['^', '>', '<', 'o', 's', '*', 'p'] 

26config = [ 

27 (*minPrec, "VDHS", "ESDIRK43", "LU"), 

28] 

29nStepsList = np.array([5, 10, 20, 50, 100, 200, 500]) 

30tEnd = 50 

31dtVals = tEnd / nStepsList 

32 

33# ----------------------------------------------------------------------------- 

34# %% Error VS cost plots 

35# ----------------------------------------------------------------------------- 

36for qDeltaList in config: 

37 figNameConv = f"{SCRIPT}_conv_1" 

38 figNameCost = f"{SCRIPT}_cost_1" 

39 

40 for qDelta, sym in zip(qDeltaList, symList, strict=False): 

41 if qDelta == "MIN-SR-NS": 

42 res = timings["MIN-SR-S_MPI"].copy() 

43 res["errors"] = [np.nan for _ in res["errors"]] 

44 elif qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]: 

45 res = timings[f"{qDelta}_MPI"] 

46 else: 

47 res = timings[qDelta] 

48 

49 errors = res["errors"] 

50 costs = res["costs"] 

51 

52 ls = '-' if qDelta.startswith("MIN-SR-") else "--" 

53 

54 plt.figure(figNameConv) 

55 plt.loglog(dtVals, errors, sym + ls, label=qDelta) 

56 

57 plt.figure(figNameCost) 

58 plt.loglog(costs, errors, sym + ls, label=qDelta) 

59 

60 for figName in [figNameConv, figNameCost]: 

61 plt.figure(figName) 

62 plt.gca().set( 

63 xlabel="Computation Time [s]" if "cost" in figName else r"$\Delta {t}$", 

64 ylabel=r"$L_2$ error at $T$", 

65 ) 

66 plt.legend() 

67 plt.grid(True) 

68 plt.tight_layout() 

69 plt.savefig(f"{PATH}/{figName}.pdf") 

70 

71# ----------------------------------------------------------------------------- 

72# %% Speedup tables 

73# ----------------------------------------------------------------------------- 

74header = f"{'dt size':12} |" 

75header += '|'.join(f" {dt:1.1e} " for dt in dtVals) 

76print(header) 

77print("-" * len(header)) 

78meanEff = 0 

79for qDelta in ["MIN-SR-S", "MIN-SR-FLEX", "VDHS"]: 

80 seq = timings[f"{qDelta}"] 

81 par = timings[f"{qDelta}_MPI"] 

82 assert np.allclose( 

83 seq["errors"], par["errors"], atol=1e-6 

84 ), f"parallel and sequential errors are not close for {qDelta}" 

85 tComp = seq["costs"] 

86 tCompMPI = par["costs"] 

87 meanEff += np.mean([tS / tP for tP, tS in zip(tCompMPI, tComp, strict=True)]) 

88 print( 

89 f"{qDelta:12} |" 

90 + '|'.join(f" {tS/tP:1.1f} ({tS/tP/4*100:1.0f}%) " for tP, tS in zip(tCompMPI, tComp, strict=True)) 

91 ) 

92meanEff /= 3 

93print("Mean parallel efficiency :", meanEff / 4)