Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-14 09:13:42

0001 #!/usr/bin/env python3
0002 #
0003 # Copyright 2020, Jefferson Science Associates, LLC.
0004 # Subject to the terms in the LICENSE file found in the top-level directory.
0005 
0006 import os
0007 import sys
0008 import toml
0009 import numpy as np
0010 import matplotlib
0011 import seaborn as sns
0012 
0013 
0014 # In order to run with latex typesetting, you need:
0015 # sudo dnf install texlive texlive-type1cm dvipng
0016 
0017 def make_plot(plot_spec, input_dir):
0018 
0019     matplotlib.use('Agg')
0020     # matplotlib.pyplot must be imported AFTER matplotlib.use(...) is called
0021     import matplotlib.pyplot as plt
0022 
0023     if 'use_latex' in plot_spec:
0024         if plot_spec['use_latex']:
0025             plt.rcParams['text.usetex'] = True
0026 
0027     plt.title(plot_spec['title'])
0028     plt.xlabel('Nthreads')
0029     plt.ylabel('Rate (Hz)')
0030     plt.grid(True)
0031     colors = sns.color_palette("deep")
0032     colors_dark = sns.color_palette("dark")
0033 
0034     legend = []
0035     color_idx = 0
0036     for subplot in plot_spec["test"]:
0037 
0038         color = colors[color_idx]
0039         dark_color = colors_dark[color_idx]
0040         color_idx += 1
0041 
0042         subdatafile = subplot['datafile']
0043         if not os.path.isabs(subdatafile):
0044             subdatafile = os.path.join(input_dir, subdatafile)
0045 
0046         nthreads,avg_rate,rms_rate = np.loadtxt(subdatafile, skiprows=1, usecols=(0,1,2), unpack=True)
0047         minnthreads = nthreads.min()
0048         maxnthreads = nthreads.max()
0049 
0050         tpar = subplot['t_par']
0051         tseq = subplot['t_seq']
0052         nthreads = np.arange(minnthreads, maxnthreads+1, 1)
0053         seq_bottleneck = 1000 / tseq
0054         par_bottleneck = 1000 * nthreads / tpar
0055         amdahl_ys = 1000 / (tseq + (tpar/nthreads))
0056         tputs = np.minimum(par_bottleneck, seq_bottleneck)
0057 
0058         # Create plot using matplotlib
0059         plt.plot(nthreads, tputs, linestyle="-", linewidth=1, color=color)
0060         plt.errorbar(nthreads, avg_rate, rms_rate, 
0061                      linestyle='',
0062                      marker='o',
0063                      ecolor=dark_color, elinewidth=1, capsize=0, capthick=0,
0064                      markersize=2, markeredgewidth=1,
0065                      markeredgecolor=dark_color, markerfacecolor=color, label=subplot['key'])
0066 
0067     plt.legend()
0068     return plt
0069 
0070 
0071 if __name__ == "__main__":
0072 
0073     input_filename = 'plot.toml'
0074     if len(sys.argv) > 1:
0075         input_filename = sys.argv[1]
0076 
0077     # Make sure the rates.dat file exists and print usage statement otherwise
0078     if not os.path.exists(input_filename):
0079         print()
0080         print('Cannot find file: ' + input_filename)
0081         print('''
0082     Usage:
0083         jana-plot-scaletests.py TOMLFILE
0084 
0085     This script plots multiple JANA scaling tests on the same axes. It assumes you
0086     use JANA2's built-in performance benchmarking tool to generate the scaling
0087     curves. The input argument is a TOML file with the following contents:
0088 
0089         - title: string
0090         - output_filename: string
0091         - use_latex: bool
0092         - test: list of dicts containing:
0093             - key: string              # Text used for the legend
0094             - datafile: string         # Relative path to a `rates.dat` file
0095             - t_seq: int               # Largest avg latency among sequential arrows
0096             - t_par: int               # Largest avg latency among parallel arrows
0097 
0098     Note: The output file format can be controlled by changing the extension on the
0099           output file name. The most useful outputs are `pdf` and `png`.
0100 
0101     Note: If you enable use_latex, you'll need to install texlive and a couple extra things.
0102           On my RPM-based distro, I needed `sudo dnf install texlive texlive-type1cm dvipng`
0103 
0104         ''')
0105         sys.exit(0)
0106 
0107     spec = toml.load(input_filename)
0108     input_dir = os.path.abspath(os.path.dirname(input_filename))
0109     plt = make_plot(spec, input_dir)
0110     output_filename = 'rate_vs_nthreads.pdf'
0111     if 'output_filename' in spec:
0112         output_filename = spec['output_filename']
0113     plt.savefig(output_filename)
0114     print('Saved plot to: ' + output_filename)
0115 
0116 
0117