Skip to content

Commit fa237d8

Browse files
committed
parallel creation of images example
1 parent 800400a commit fa237d8

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

hotwater-grid-stylesheet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ def frame_grid(nrows, ncols):
6060
frame.load_stylesheet('isosurface.sty')
6161

6262
tp.save_png('hotwater-grid-stylesheet.png')
63+

hotwater-isosurface-recorded.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
1.45886)
3030
tp.active_frame().plot().view.width=0.339885
3131
# End Macro.
32+

hotwater-parallel.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import atexit
2+
import glob
3+
import os
4+
import multiprocessing
5+
import sys
6+
7+
import tecplot as tp
8+
9+
def init():
10+
# !!! IMPORTANT !!!
11+
# Must register stop at exit to ensure Tecplot cleans
12+
# up all temporary files and does not create a core dump
13+
atexit.register(tp.session.stop)
14+
15+
def work(datafile):
16+
tp.new_layout()
17+
tp.data.load_tecplot(datafile)
18+
tp.active_frame().load_stylesheet('isosurface.sty')
19+
imgfile = os.path.basename(datafile).replace('.plt', '.png')
20+
tp.save_png(os.path.join('images', imgfile))
21+
22+
if __name__ == '__main__':
23+
# !!! IMPORTANT !!!
24+
# On Linux systems, Python's multiprocessing start method
25+
# defaults to "fork" which is incompatible with PyTecplot
26+
# and must be set to "spawn"
27+
multiprocessing.set_start_method('spawn')
28+
29+
# Get the datafiles
30+
files = glob.glob('hotwatermixing/HotWaterMixing_Y05YT10*.plt')
31+
32+
# Set up the pool with initializing function and associated arguments
33+
num_workers = min(multiprocessing.cpu_count(), len(files))
34+
pool = multiprocessing.Pool(num_workers, initializer=init)
35+
36+
try:
37+
if not os.path.exists('images'):
38+
os.makedirs('images')
39+
40+
# Map the work function to each of the job arguments
41+
pool.map(work, files)
42+
finally:
43+
# !!! IMPORTANT !!!
44+
# Must join the process pool before parent script exits
45+
# to ensure Tecplot cleans up all temporary files
46+
# and does not create a core dump
47+
pool.close()
48+
pool.join()
49+

0 commit comments

Comments
 (0)