Skip to content

Commit c0dcdca

Browse files
committed
added tutorial and test
1 parent e7716c7 commit c0dcdca

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Full code: `pySDC/tutorial/step_7/C_pySDC_with_PETSc.py <https://github.com/Parallel-in-Time/pySDC/blob/master/pySDC/tutorial/step_7/C_pySDC_with_PETSc.py>`_
2+
3+
Results:
4+
5+
1 processor in time, 1 processor in space
6+
.. literalinclude:: ../../../step_7_C_out_1x1.txt
7+
8+
1 processor in time, 2 processors in space
9+
.. literalinclude:: ../../../step_7_C_out_1x2.txt
10+
11+
2 processor in time, 2 processors in space
12+
.. literalinclude:: ../../../step_7_C_out_2x2.txt
Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
1+
import subprocess
2+
import os
3+
14
from pySDC.tutorial.step_7.A_visualize_residuals import main as main_A
25
from pySDC.tutorial.step_7.B_multistep_SDC import main as main_B
36

4-
57
def test_A():
68
main_A()
79

810
def test_B():
911
main_B()
1012

13+
def test_C_1x1():
14+
# Set python path once
15+
my_env = os.environ.copy()
16+
my_env['PYTHONPATH'] = '../../..:.'
17+
cwd = '.'
18+
num_procs = 1
19+
num_procs_space = 1
20+
cmd = ('mpirun -np ' + str(num_procs) + ' python pySDC/tutorial/step_7/C_pySDC_with_PETSc.py '
21+
+ str(num_procs_space) + ' ' + 'step_7_C_out_1x1.txt').split()
22+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=my_env, cwd=cwd)
23+
p.wait()
24+
assert p.returncode == 0, 'ERROR: did not get return code 0, got %s with %2i processes' % \
25+
(p.returncode, num_procs)
26+
27+
def test_C_1x2():
28+
# Set python path once
29+
my_env = os.environ.copy()
30+
my_env['PYTHONPATH'] = '../../..:.'
31+
cwd = '.'
32+
num_procs = 2
33+
num_procs_space = 2
34+
cmd = ('mpirun -np ' + str(num_procs) + ' python pySDC/tutorial/step_7/C_pySDC_with_PETSc.py '
35+
+ str(num_procs_space) + ' ' + 'step_7_C_out_1x2.txt').split()
36+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=my_env, cwd=cwd)
37+
p.wait()
38+
assert p.returncode == 0, 'ERROR: did not get return code 0, got %s with %2i processes' % \
39+
(p.returncode, num_procs)
40+
41+
def test_C_2x2():
42+
# Set python path once
43+
my_env = os.environ.copy()
44+
my_env['PYTHONPATH'] = '../../..:.'
45+
cwd = '.'
46+
num_procs = 4
47+
num_procs_space = 2
48+
cmd = ('mpirun -np ' + str(num_procs) + ' python pySDC/tutorial/step_7/C_pySDC_with_PETSc.py '
49+
+ str(num_procs_space) + ' ' + 'step_7_C_out_2x2.txt').split()
50+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=my_env, cwd=cwd)
51+
p.wait()
52+
assert p.returncode == 0, 'ERROR: did not get return code 0, got %s with %2i processes' % \
53+
(p.returncode, num_procs)
54+
1155

pySDC/tutorial/step_7/C_pySDC_with_PETSc.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ def main():
2424
world_size = comm.Get_size()
2525

2626
# split world communicator to create space-communicators
27-
if len(sys.argv) == 2:
27+
if len(sys.argv) >= 2:
2828
color = int(world_rank / int(sys.argv[1]))
2929
else:
3030
color = int(world_rank / 1)
3131
space_comm = comm.Split(color=color)
3232
space_rank = space_comm.Get_rank()
3333

3434
# split world communicator to create time-communicators
35-
if len(sys.argv) == 2:
35+
if len(sys.argv) >= 2:
3636
color = int(world_rank % int(sys.argv[1]))
3737
else:
3838
color = int(world_rank / world_size)
3939
time_comm = comm.Split(color=color)
40+
time_rank = time_comm.Get_rank()
4041

4142
# initialize level parameters
4243
level_params = dict()
@@ -113,9 +114,18 @@ def main():
113114
iter_counts = sort_stats(filtered_stats, sortby='time')
114115

115116
niters = np.array([item[1] for item in iter_counts])
116-
117+
118+
# limit output to space-rank 0 (as before when setting the logger level)
117119
if space_rank == 0:
118-
f = open('step_7_C_out.txt', 'w')
120+
if len(sys.argv) == 3:
121+
fname = str(sys.argv[2])
122+
else:
123+
fname = 'step_7_C_out.txt'
124+
f = open(fname, 'a+')
125+
126+
out = 'This is time-rank %i...' % time_rank
127+
f.write(out + '\n')
128+
print(out)
119129

120130
# compute and print statistics
121131
for item in iter_counts:

pySDC/tutorial/step_7/README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ Important things to note:
3333

3434
.. include:: doc_step_7_B.rst
3535

36+
Part C: Time-parallel pySDC with space-parallel PETSc
37+
-----------------------------------------------------
38+
39+
With rather unfavorable scaling properties, parallel-in-time methods are only really useful when spatial parallelization is maxed out.
40+
To work with spatial parallelization, this part shows how to (1) include and work with an external library and (2) set up space- and time-parallel runs.
41+
We use again the forced heat equation as our testbed and PETSc for the space-parallel data structures and linear solver.
42+
See `implementations/datatype_classes/petsc_dmda_grid.py` and `implementations/problem_classes/HeatEquation_2D_PETSc_forced.py` for details on the PETSc bindings.
43+
44+
Important things to note:
45+
46+
- We need processors in space and time, which can be achieved by `comm.Split` and coloring. The space-communicator is then passed to the problem class.
47+
- Below we run the code 3 times: with 1 and 2 processors in space as well as 4 processors (2 in time and 2 in space). Do not expect scaling due to the CI environment.
48+
49+
.. include:: doc_step_7_C.rst
50+
3651
Part X: To be continued...
3752
--------------------------
3853

0 commit comments

Comments
 (0)