Skip to content

Commit 049c240

Browse files
committed
Allow the python script to run in MPMD mode.
Added a plotting script that does not write BP output.
1 parent 37f20db commit 049c240

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

Tutorial/heat2d/python/decomp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(self, args):
2929

3030
from mpi4py import MPI
3131

32-
self.comm_world = MPI.COMM_WORLD
32+
color = 3
33+
self.comm_world = MPI.COMM_WORLD.Split(color, MPI.COMM_WORLD.Get_rank())
3334
self.size = self.comm_world.Get_size()
3435
self.rank['world'] = self.comm_world.Get_rank()
3536
if self.size != (self.nx * self.ny):

Tutorial/heat2d/python/heat_all.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ def SetupArgs():
3636

3737

3838

39-
def Plot2D(args, fullshape, step, fontsize, displaysec):
39+
def Plot2D(args, fr, fullshape, step, fontsize, displaysec):
4040
data = fr.read(args.varname, [0, 0], fullshape, step, 1)
4141
gs = gridspec.GridSpec(1, 1)
4242
fig = plt.figure(1, figsize=(8,10))
4343
ax = fig.add_subplot(gs[0, 0])
4444

45-
ax.imshow(data, origin='lower', extent=[0, fullshape[1], 0, fullshape[0]] )
45+
print ("data size:", fullshape[0],"x",fullshape[1])
46+
print (data.shape)
47+
ax.imshow(data[0, :, :], origin='lower', extent=[0, fullshape[1], 0, fullshape[0]] )
4648

4749
for i in range(args.ny):
4850
y = fullshape[0] / args.ny * i
@@ -69,7 +71,7 @@ def Plot2D(args, fullshape, step, fontsize, displaysec):
6971

7072
# fontsize on plot
7173
fontsize = 22
72-
displaysec = 3
74+
displaysec = 0.5
7375

7476
# Parse command line arguments
7577
args = SetupArgs()
@@ -79,10 +81,10 @@ def Plot2D(args, fullshape, step, fontsize, displaysec):
7981

8082

8183
# Read the data from this object
82-
fr = adios2.open(args.infile, "r", *mpi.readargs)
84+
fr = adios2.open(args.infile, "r", mpi.comm_world, "adios2.xml", "VizInput")
8385

8486
# Calculate difference between steps, and write to this object
85-
fw = adios2.open(args.outfile, "w", *mpi.readargs)
87+
fw = adios2.open(args.outfile, "w", mpi.comm_world)
8688

8789

8890
# Get the ADIOS selections -- equally partition the data if parallelization is requested
@@ -106,7 +108,7 @@ def Plot2D(args, fullshape, step, fontsize, displaysec):
106108

107109

108110
if (mpi.rank['world'] == 0) and (args.plot):
109-
Plot2D(args, fullshape, step, fontsize, displaysec)
111+
Plot2D(args, fr, fullshape, step, fontsize, displaysec)
110112

111113

112114
if (step > 0):

Tutorial/heat2d/python/heat_plot.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python
2+
from __future__ import absolute_import, division, print_function, unicode_literals
3+
4+
"""
5+
Example:
6+
7+
$ mpirun -n 1 python ./heat_transfer.py -f inputstream -o outputstream -v varname
8+
"""
9+
10+
import adios2
11+
import argparse
12+
13+
import numpy as np
14+
import matplotlib.pyplot as plt
15+
import matplotlib.gridspec as gridspec
16+
import decomp
17+
18+
19+
def SetupArgs():
20+
parser = argparse.ArgumentParser()
21+
22+
parser.add_argument("--instream", "-i", help="Name of the input stream", required=True)
23+
parser.add_argument("--outfile", "-o", help="Name of the output file", default="screen")
24+
parser.add_argument("--varname", "-v", help="Name of variable read", default="T")
25+
parser.add_argument("--nompi", "-nompi", help="ADIOS was installed without MPI", action="store_true")
26+
27+
args = parser.parse_args()
28+
args.nx = 1
29+
args.ny = 1
30+
return args
31+
32+
33+
34+
def Plot2D(args, fr, data, fullshape, step, fontsize, displaysec):
35+
gs = gridspec.GridSpec(1, 1)
36+
fig = plt.figure(1, figsize=(8,10))
37+
ax = fig.add_subplot(gs[0, 0])
38+
ax.imshow(data, origin='lower', extent=[0, fullshape[1], 0, fullshape[0]] )
39+
40+
for i in range(args.ny):
41+
y = fullshape[0] / args.ny * i
42+
ax.plot([0, fullshape[1]], [y, y], color='black')
43+
44+
for i in range(args.nx):
45+
x = fullshape[1] / args.nx * i
46+
ax.plot([x, x], [0, fullshape[0]], color='black')
47+
48+
ax.set_title("Timestep = {0}".format(step), fontsize=fontsize)
49+
ax.set_xlabel("x")
50+
ax.set_ylabel("y")
51+
52+
plt.ion()
53+
if (args.outfile == "screen"):
54+
plt.show()
55+
plt.pause(displaysec)
56+
else:
57+
imgfile = args.outfile+str(step)+".png"
58+
fig.savefig(imgfile)
59+
60+
plt.clf()
61+
62+
63+
if __name__ == "__main__":
64+
65+
# fontsize on plot
66+
fontsize = 22
67+
displaysec = 0.01
68+
69+
# Parse command line arguments
70+
args = SetupArgs()
71+
72+
# Setup up 2D communicators if MPI is installed
73+
mpi = decomp.MPISetup(args)
74+
75+
76+
# Read the data from this object
77+
fr = adios2.open(args.instream, "r", mpi.comm_world, "adios2.xml", "VizInput")
78+
79+
# Get the ADIOS selections -- equally partition the data if parallelization is requested
80+
start, size, fullshape = mpi.Partition(fr, args)
81+
82+
# Read through the steps, one at a time
83+
step = 0
84+
while (not fr.eof()):
85+
data = fr.read(args.varname, start, size, endl=True)
86+
87+
# Print a couple simple diagnostics
88+
avg = np.average(data)
89+
std = np.std(data)
90+
print("step:{0}, rank: {1}, avg: {2:.3f}, std: {3:.3f}".format(step, mpi.rank['world'], avg, std))
91+
Plot2D(args, fr, data, fullshape, step, fontsize, displaysec)
92+
93+
step += 1
94+
95+
fr.close()
96+

0 commit comments

Comments
 (0)