1#!/usr/bin/env python3 2 3# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 4# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 5# All Rights reserved. See files LICENSE and NOTICE for details. 6# 7# This file is part of CEED, a collection of benchmarks, miniapps, software 8# libraries and APIs for efficient high-order finite element and spectral 9# element discretizations for exascale applications. For more information and 10# source code availability see http://github.com/ceed 11# 12# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 13# a collaborative effort of two U.S. Department of Energy organizations (Office 14# of Science and the National Nuclear Security Administration) responsible for 15# the planning and preparation of a capable exascale ecosystem, including 16# software, applications, hardware, advanced system engineering and early 17# testbed platforms, in support of the nation's exascale computing imperative. 18 19from pylab import * 20from matplotlib import use 21from postprocess_base import read_logs 22import pandas as pd 23 24# Adjustable plot parameters 25log_y = 0 # use log scale on the y-axis? 26x_range = (1e1, 4e6) # plot range for the x-axis; comment out for auto 27y_range = (0, 2e9) # plot range for the y-axis; comment out for auto 28draw_iter_lines = 0 # draw the "iter/s" lines? 29ymin_iter_lines = 3e5 # minimal y value for the "iter/s" lines 30ymax_iter_lines = 8e8 # maximal y value for the "iter/s" lines 31legend_ncol = (2 if log_y else 1) # number of columns in the legend 32write_figures = 1 # save the figures to files? 33show_figures = 1 # display the figures on the screen? 34 35# Load the data 36runs = read_logs() 37 38# Sample plot output 39if not show_figures: 40 use('pdf') 41 42rcParams['font.sans-serif'].insert(0, 'Noto Sans') 43rcParams['font.sans-serif'].insert(1, 'Open Sans') 44rcParams['figure.figsize'] = [10, 8] # default: 8 x 6 45 46cm_size = 16 47colors = ['dimgrey', 'black', 'saddlebrown', 'firebrick', 'red', 'orange', 48 'gold', 'lightgreen', 'green', 'cyan', 'teal', 'blue', 'navy', 49 'purple', 'magenta', 'pink'] 50 51# Get test names 52sel_runs = runs 53tests = list(sel_runs.test.unique()) 54test = tests[0] 55 56# Run information 57print('Using test:', test) 58 59if 'CEED Benchmark Problem' in test: 60 test_short = test.strip().split()[0] + ' BP' + test.strip().split()[-1] 61 62# Plot same BP 63sel_runs = sel_runs.loc[sel_runs['test'] == test] 64 65# Plot same case (scalar vs vector) 66cases = list(sel_runs.case.unique()) 67case = cases[0] 68vdim = 1 if case == 'scalar' else 3 69print('Using case:', case) 70sel_runs = sel_runs.loc[sel_runs['case'] == case] 71 72# Plot same 'code' 73codes = list(sel_runs.code.unique()) 74code = codes[0] 75sel_runs = sel_runs.loc[sel_runs['code'] == code] 76 77# Group plots by backend and number of processes 78pl_set = sel_runs[['backend', 79 'backend_memtype', 80 'num_procs', 81 'num_procs_node']] 82pl_set = pl_set.drop_duplicates() 83 84# Plotting 85for index, row in pl_set.iterrows(): 86 backend = row['backend'] 87 backend_memtype = row['backend_memtype'] 88 num_procs = float(row['num_procs']) 89 num_procs_node = float(row['num_procs_node']) 90 num_nodes = num_procs / num_procs_node 91 pl_runs = sel_runs[(sel_runs.backend == backend) | 92 (sel_runs.num_procs == num_procs) | 93 (sel_runs.num_procs_node == num_procs_node)] 94 if len(pl_runs.index) == 0: 95 continue 96 97 print('backend: %s, compute nodes: %i, number of MPI tasks = %i' % ( 98 backend, num_nodes, num_procs)) 99 100 figure() 101 i = 0 102 sol_p_set = sel_runs['degree'].drop_duplicates() 103 sol_p_set = sol_p_set.sort_values() 104 # Iterate over P 105 for sol_p in sol_p_set: 106 qpts = sel_runs['quadrature_pts'].loc[pl_runs['degree'] == sol_p] 107 qpts = qpts.drop_duplicates().sort_values(ascending=False) 108 qpts = qpts.reset_index(drop=True) 109 print('Degree: %i, quadrature points:' % sol_p, qpts[0]) 110 # Generate plot data 111 d = [[run['degree'], run['num_elem'], 1. * run['num_unknowns'] / num_nodes / vdim, 112 run['cg_iteration_dps'] / num_nodes] 113 for index, run in 114 pl_runs.loc[(pl_runs['degree'] == sol_p) | 115 (pl_runs['quadrature_pts'] == qpts[0])].iterrows()] 116 d = [[e[2], e[3]] for e in d if e[0] == sol_p] 117 # (DOFs/[sec/iter]/node)/(DOFs/node) = iter/sec 118 d = [[nun, 119 min([e[1] for e in d if e[0] == nun]), 120 max([e[1] for e in d if e[0] == nun])] 121 for nun in set([e[0] for e in d])] 122 d = asarray(sorted(d)) 123 # Plot 124 plot(d[:, 0], d[:, 2], 'o-', color=colors[i % cm_size], 125 label='p=%i' % sol_p) 126 if list(d[:, 1]) != list(d[:, 2]): 127 plot(d[:, 0], d[:, 1], 'o-', color=colors[i]) 128 fill_between(d[:, 0], d[:, 1], d[:, 2], 129 facecolor=colors[i], alpha=0.2) 130 # Continue if only 1 set of qpts 131 if len(qpts) == 1: 132 i = i + 1 133 continue 134 # Second set of qpts 135 d = [[run['degree'], run['num_elem'], 1. * run['num_unknowns'] / num_nodes / vdim, 136 run['cg_iteration_dps'] / num_nodes] 137 for index, run in 138 pl_runs.loc[(pl_runs['degree'] == sol_p) | 139 (pl_runs['quadrature_pts'] == qpts[1])].iterrows()] 140 d = [[e[2], e[3]] for e in d if e[0] == sol_p] 141 if len(d) == 0: 142 i = i + 1 143 continue 144 d = [[nun, 145 min([e[1] for e in d if e[0] == nun]), 146 max([e[1] for e in d if e[0] == nun])] 147 for nun in set([e[0] for e in d])] 148 d = asarray(sorted(d)) 149 plot(d[:, 0], d[:, 2], 's--', color=colors[i], 150 label='p=%i' % sol_p) 151 if list(d[:, 1]) != list(d[:, 2]): 152 plot(d[:, 0], d[:, 1], 's--', color=colors[i]) 153 ## 154 i = i + 1 155 ## 156 if draw_iter_lines: 157 y0, y1 = ymin_iter_lines, ymax_iter_lines 158 y = asarray([y0, y1]) if log_y else exp(linspace(log(y0), log(y1))) 159 slope1 = 600. 160 slope2 = 6000. 161 plot(y / slope1, y, 'k--', label='%g iter/s' % (slope1 / vdim)) 162 plot(y / slope2, y, 'k-', label='%g iter/s' % (slope2 / vdim)) 163 164 # Plot information 165 title(r'%i node%s $\times$ %i ranks, %s, %s, %s' % ( 166 num_nodes, '' if num_nodes == 1 else 's', 167 num_procs_node, backend, backend_memtype, test_short), fontsize=16) 168 xscale('log') # subsx=[2,4,6,8] 169 if log_y: 170 yscale('log') 171 if 'x_range' in vars() and len(x_range) == 2: 172 xlim(x_range) 173 if 'y_range' in vars() and len(y_range) == 2: 174 ylim(y_range) 175 grid('on', color='gray', ls='dotted') 176 grid('on', axis='both', which='minor', color='gray', ls='dotted') 177 plt.tick_params(labelsize=14) 178 exptext = gca().yaxis.get_offset_text() 179 exptext.set_size(14) 180 gca().set_axisbelow(True) 181 xlabel('Points per compute node', fontsize=14) 182 ylabel('[DOFs x CG iterations] / [compute nodes x seconds]', fontsize=14) 183 legend(ncol=legend_ncol, loc='best', fontsize=13) 184 185 # Write 186 if write_figures: # write .pdf file? 187 short_backend = backend.replace('/', '') 188 test_short_save = test_short.replace(' ', '') 189 pdf_file = 'plot_%s_%s_%s_%s_N%03i_pn%i.pdf' % ( 190 code, test_short_save, short_backend, backend_memtype, num_nodes, num_procs_node) 191 print('\nsaving figure --> %s' % pdf_file) 192 savefig(pdf_file, format='pdf', bbox_inches='tight') 193 194if show_figures: # show the figures? 195 print('\nShowing figures ...') 196 show() 197