Skip to content

Commit

Permalink
add a new func
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuang-jedi committed Jul 21, 2022
1 parent 4719cb2 commit f1d23e3
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 143 deletions.
131 changes: 4 additions & 127 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,129 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
regrid/
*.png
*.txt
*.csv
112 changes: 96 additions & 16 deletions profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,97 @@ def __init__(self, debug=0, corelist=[], casename=None, output=0,
'GETKF_computeHofX',
'changeVar',
'computeWeights',
'State',
'Local_computeHofX']
'measurementUpdate',
'State']
# 'Local_computeHofX']
self.fullfunction_list = ['util::Timers::Total',
'oops::GETKFSolver::computeHofX',
'oops::VariableChange::changeVar',
'oops::GETKFSolver::computeWeights',
'oops::State::State',
'oops::LocalEnsembleSolver::computeHofX']
self.pmin = 999999999999.0
self.gmin = 999999999999.0
'oops::GETKFSolver::measurementUpdate',
'oops::State::State']
# 'oops::LocalEnsembleSolver::computeHofX']
self.pmin = 1.0e10
self.gmin = 1.0e10
self.pmax = 0.0
self.gmax = 0.0

self.max_selected_functions = 6
self.num_selected_functions = 0
self.selected_functions_time = []
self.selected_functions_name = []

self.get_top_functions()
#self.generate_top_function_list()

def set_linear(self, linear=1):
self.linear = linear

def set_output(self, output=1):
self.output = output

def add2selected_functions(self, name, avgt):
n = self.num_selected_functions - 1
if(self.num_selected_functions < self.max_selected_functions):
self.selected_functions_time.append(avgt)
self.selected_functions_name.append(name)
self.num_selected_functions += 1
else:
if(avgt < self.selected_functions_time[n]):
return
self.selected_functions_time[n] = avgt
self.selected_functions_name[n] = name

while(n > 0):
if(self.selected_functions_time[n] > self.selected_functions_time[n-1]):
otime = self.selected_functions_time[n-1]
oname = self.selected_functions_name[n-1]
self.selected_functions_time[n-1] = self.selected_functions_time[n]
self.selected_functions_name[n-1] = self.selected_functions_name[n]
self.selected_functions_time[n] = otime
self.selected_functions_name[n] = oname
n -= 1

def get_top_functions(self):
self.selected_function_list = []
#par_stats = self.parstatslist[0]

rundir = '%s/%s/run_80.40t%dn_%dp' %(self.workdir, self.casename,
self.nodelist[0], self.corelist[0])
flnm = '%s/stdoutNerr/stdout.00000000' %(rundir)

if(os.path.exists(flnm)):
if(self.debug):
print('Processing file: %s' %(flnm))
#pstats, gstats = self.stats(flnm)
ptime, par_stats = self.stats(flnm)
else:
print('file: ' + flnm + ' does not exist.')
sys.exit(-1)

nf = len(par_stats)
for n in range(nf):
name = par_stats[n]['name']
avgt = par_stats[n]['avg']
self.add2selected_functions(name, avgt)

for n in range(self.num_selected_functions):
pinfo = 'No. %3.3d name: %40s' %(n, self.selected_functions_name[n])
pinfo = '%s, time: %8.2f' %(pinfo, self.selected_functions_time[n])
print(pinfo)

def generate_top_function_list(self):
self.function_list = []
self.fullfunction_list = []

for n in range(self.num_selected_functions):
self.fullfunction_list.append(self.selected_functions_name[n])
item = self.selected_functions_name[n].split('::')
self.function_list.append(item[-1])

def process(self):
self.pstatslist = []
self.parstatslist = []
self.paravgtimelist = []
self.gstatslist = []

self.filelist = []
Expand All @@ -88,9 +158,10 @@ def process(self):
if(self.debug):
print('Processing node: %d, as file: %s' %(self.nodelist[n], flnm))
#pstats, gstats = self.stats(flnm)
ptime = self.stats(flnm)
ptime, par_stats = self.stats(flnm)
self.filelist.append(flnm)
self.pstatslist.append(ptime)
self.paravgtimelist.append(ptime)
self.parstatslist.append(par_stats)
#self.gstatslist.append(glist)
else:
print('Filename ' + flnm + ' does not exit. Stop')
Expand All @@ -103,8 +174,7 @@ def stats(self, flnm):
print('Filename ' + flnm + ' does not exit. Stop')
sys.exit(-1)

prof = {}

par_stats = {}
with open(flnm) as fp:
lines = fp.readlines()
#line = fp.readline()
Expand Down Expand Up @@ -138,7 +208,7 @@ def stats(self, flnm):

avgtime.append(avgt)

return avgtime
return avgtime, par_stats

def get_index(self, stats, varname):
idx = -1
Expand Down Expand Up @@ -271,21 +341,29 @@ def plot(self):
pmin = 1.0e20
pmax = 0.0

txtname = 'timing_%s.csv' %(self.casename)
OPF = open(txtname, 'w')
header = '%40s, %12s\n' %('Function Name', 'Avg Time (seconds)')
OPF.write(header)

for i in range(len(self.fullfunction_list)):
for k in range(nl):
y[k] = 0.001*self.pstatslist[k][i]
y[k] = 0.001*self.paravgtimelist[k][i]
if(pmin > y[k]):
pmin = y[k]
if(pmax < y[k]):
pmax = y[k]
#print('y = ', y)
ax.plot(x, y, color=self.colorlist[i], linewidth=2, alpha=0.9)
txtinfo = '%40s, %12.2f\n' %(self.fullfunction_list[i], y[0])
OPF.write(txtinfo)
OPF.close()

if(self.linear == 0):
for i in range(len(self.fullfunction_list)):
for k in range(nl):
fact = 1.0/np.log2(2*self.nodelist[k])
z[k] = 0.001*self.pstatslist[0][i]*fact
z[k] = 0.001*self.paravgtimelist[0][i]*fact
#https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html
ax.plot(x, z, color='black', linewidth=1, alpha=0.5, linestyle='dotted')

Expand All @@ -297,7 +375,7 @@ def plot(self):
plt.ylim(pmin, pmax)

#general title
title = '%s Timing (in seconds), min: %f8.2, max: %f8.2' %(self.casename, pmin, pmax)
title = '%s Timing (in seconds), min: %8.2f, max: %8.2f' %(self.casename, pmin, pmax)
#plt.suptitle(title, fontsize=13, fontweight=0, color='black', style='italic', y=1.02)
plt.suptitle(title, fontsize=16, fontweight=1, color='black')

Expand Down Expand Up @@ -339,6 +417,7 @@ def plot(self):
casename = 'sondes'
workdir = '/work2/noaa/gsienkf/weihuang/jedi/case_study'
corelist = [36, 78, 156, 312]
#corelist = [36, 72, 144, 288]
nodelist = [1, 2, 4, 8]
output = 0
linear = 1
Expand Down Expand Up @@ -369,7 +448,8 @@ def plot(self):
pr.process()
for linear in [0, 1]:
pr.set_linear(linear=linear)
for output in [0, 1]:
#for output in [0, 1]:
for output in [1]:
pr.set_output(output=output)
pr.plot()

1 change: 1 addition & 0 deletions runit
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -x

case_dir=/work2/noaa/gsienkf/weihuang/jedi/case_study
run_dir=run_80.40t1n_36p

output=1

Expand Down
11 changes: 11 additions & 0 deletions timingit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -x

caselist=(amsua iasi aircraft sfcship sondes surf satwind scatwind vadwind windprof)

for i in ${!caselist[@]}
do
python profiling.py --casename=${caselist[$i]}
done

3 changes: 3 additions & 0 deletions use-eva/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ sfcship/
sondes/
vadwind/
windprof/
sfc_ps/
sfcship_ps/
sondes_ps/
*.yaml
*.png

0 comments on commit f1d23e3

Please sign in to comment.