File indexing completed on 2025-01-18 10:17:18
0001
0002
0003
0004
0005
0006
0007 import os
0008 import sys
0009
0010 fname = 'rates.dat'
0011 NO_GRAPHICS_WINDOW = False
0012 MAKE_PNG = False
0013
0014 if '-nowin' in sys.argv[1:] : NO_GRAPHICS_WINDOW = True
0015 if '-png' in sys.argv[1:] : MAKE_PNG = True
0016
0017
0018 if not os.path.exists(fname):
0019 print()
0020 print('Cannot find file: ' + fname + '!')
0021 print('''
0022
0023 Usage:
0024 jana-plot-scaletest.py [-png] [-nowin]
0025
0026 This script can be used to plot the results of running the
0027 built in JANA scaling test. This test will automatically
0028 record the event processing rate as it cycles through changing
0029 the number of processing threads JANA is using. This can be
0030 done if using the "jana" executable by just giving it the
0031 -b argument. If using a custom executable you will need to
0032 replace the call to JApplication::Run() with:
0033
0034 JBenchmarker benchmarker(app);
0035 benchmarker.RunUntilFinished();
0036
0037 You can control several parameters of the test using these
0038 JANA configuration parameters:
0039
0040 benchmark:nsamples # Number of samples for each benchmark test
0041 benchmark:minthreads # Minimum number of threads for benchmark test
0042 benchmark:maxthreads # Maximum number of threads for benchmark test
0043 benchmark:resultsdir # Output directory name for benchmark test results
0044 benchmark:threadstep # Delta number of threads between each benchmark test
0045
0046 Run "jana -c -b" to see the default values for each of these.
0047
0048 To use this just go into the benchmark:resultsdir where the
0049 rates.dat file is and run it. Note that you must have python
0050 installed as well as the numpy and matplotlib python packages.
0051
0052 If you wish to just create the plot as a PNG file without opening
0053 a window (convenient for machines where a graphical environment
0054 isn't present), then give it the -nowin argument like this:
0055
0056 jana-plot-scaletest.py -nowin
0057 ''')
0058 sys.exit(0)
0059
0060 import numpy as np
0061 import matplotlib
0062 from datetime import datetime
0063
0064
0065 if NO_GRAPHICS_WINDOW:
0066 matplotlib.use('Agg')
0067 MAKE_PNG = True
0068
0069
0070 import matplotlib.pyplot as plt
0071
0072
0073
0074 nthreads,avg_rate,rms_rate = np.loadtxt(fname, skiprows=1,usecols=(0,1,2), unpack=True)
0075 minnthreads = nthreads.min()
0076 maxnthreads = nthreads.max()
0077
0078
0079 plt.errorbar(nthreads, avg_rate, rms_rate, linestyle='', ecolor='red', elinewidth=3, capthick=3, marker='o', ms=8, markerfacecolor='green')
0080
0081 creation_time = int(os.path.getctime(fname))
0082 plt.title('JANA JTest Scaling Test : ' + str(datetime.fromtimestamp(creation_time)))
0083 plt.xlabel('Nthreads')
0084 plt.ylabel('Rate (Hz)')
0085
0086 plt.xlim(minnthreads-1.0, maxnthreads+1.0)
0087 plt.grid(True)
0088
0089
0090 if MAKE_PNG:
0091 png_filename = 'rate_vs_nthreads.png'
0092 print('Saving plot to: ' + png_filename)
0093 plt.savefig(png_filename)
0094
0095 if not NO_GRAPHICS_WINDOW:
0096 plt.show()
0097