Coverage for pySDC/tutorial/step_6/B_odd_temporal_distribution.py: 100%

10 statements  

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

1# --- 

2# jupyter: 

3# jupytext: 

4# formats: py:percent 

5# kernelspec: 

6# display_name: Python 3 

7# name: python3 

8# --- 

9 

10# %% [markdown] 

11# # Part B: Odd temporal distribution 

12# 

13# Accidentally, the numbers of parallel processes used in [Part A](A_run_non_MPI_controller) are always divisors of 

14# the number of steps. Yet, this does not need to be the case. All controllers can handle odd distributions, e.g. too 

15# few or too many processes for the steps, or for the last block. We run the multi-level setup of Part A again, with 

16# 3, 5, 7 and 9 processes for the 8 time steps. 

17 

18# %% 

19import matplotlib.pyplot as plt 

20 

21from pySDC.tutorial.step_6.pfasst_setup import run_pfasst 

22 

23iterations = run_pfasst(num_proc_list=[3, 5, 7, 9], fname='step_6_B_out.txt', multi_level=True) 

24 

25# %% tags=["hide-input"] 

26fig, ax = plt.subplots(figsize=(8, 2.2), constrained_layout=True) 

27image = ax.imshow(list(iterations.values()), cmap='viridis', aspect='auto', vmin=0) 

28ax.set_yticks(range(len(iterations))) 

29ax.set_yticklabels(list(iterations)) 

30ax.set_ylabel('processes') 

31ax.set_xlabel('time step') 

32fig.colorbar(image, label='iterations') 

33 

34# %% [markdown] 

35# With 3 processes, the 8 steps come in blocks of 3, 3 and 2, and with 9 processes, one process has nothing to do. 

36# The controllers check which steps are currently active, and only those compute the next block. 

37# 

38# :::{admonition} Important things to note 

39# - This capability becomes useful with adaptive time stepping, where the number of steps is not known in advance. 

40# - It also works for SDC and MLSDC, where with varying time-step sizes the overall number of steps is not given at 

41# the beginning either. 

42# ::: 

43# 

44# The check the tests run is inside `run_pfasst`: no step needs more than 8 iterations.