Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100639964
gcpu
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 1, 10:02
Size
8 KB
Mime Type
text/x-python
Expires
Mon, Feb 3, 10:02 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24005003
Attached To
rGTOOLS Gtools
gcpu
View Options
#!/usr/bin/env python
'''
Extract and plot info contained in cpu.txt files
Yves Revaz
jeu avr 6 15:58:19 CEST 2006
'''
import
Ptools
as
pt
import
os
,
sys
,
string
from
optparse
import
OptionParser
from
Gtools
import
*
from
Gtools
import
io
from
optparse
import
OptionParser
def
parse_options
():
usage
=
"usage: %prog [options] file"
parser
=
OptionParser
(
usage
=
usage
)
parser
=
pt
.
add_postscript_options
(
parser
)
parser
=
pt
.
add_limits_options
(
parser
)
parser
=
pt
.
add_log_options
(
parser
)
parser
=
pt
.
add_cmd_options
(
parser
)
parser
.
add_option
(
"-o"
,
action
=
"store"
,
dest
=
"mode"
,
type
=
"string"
,
default
=
'CPU_Total'
,
help
=
"mode : cpu, cpu/step"
,
metavar
=
" NAME"
)
parser
.
add_option
(
"--legend"
,
action
=
"store_true"
,
dest
=
"legend"
,
default
=
False
,
help
=
"add a legend"
)
parser
.
add_option
(
"--fraction"
,
action
=
"store_true"
,
dest
=
"fraction"
,
default
=
False
,
help
=
"fraction of cpu"
)
parser
.
add_option
(
"--nofraction"
,
action
=
"store_true"
,
dest
=
"nofraction"
,
default
=
False
,
help
=
"force no fraction"
)
parser
.
add_option
(
"--total"
,
action
=
"store"
,
dest
=
"total"
,
type
=
"string"
,
default
=
'CPU_Total'
,
help
=
"toral reference for fraction computation"
)
parser
.
add_option
(
"-t"
,
action
=
"store"
,
dest
=
"time"
,
type
=
"string"
,
default
=
'hour'
,
help
=
"time : day, hour, minute, second"
,
metavar
=
" TYPE"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
len
(
args
)
==
0
:
print
"you must specify a filename"
sys
.
exit
(
0
)
files
=
args
return
files
,
options
#######################################
# MakePlot
#######################################
def
MakePlot
(
dirs
,
opt
):
# observable
if
opt
.
mode
==
'total'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Total"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_Accel"
,
"CPU_Physics"
,
"CPU_Leapfrog"
,
"CPU_Potential"
,
"CPU_Snapshot"
,
"CPU_Domain"
,
"CPU_Peano"
,
"CPU_Residual"
,
"CPU_Begrun"
]
elif
opt
.
mode
==
'budget'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_Gravity"
,
"CPU_Hydro"
,
"CPU_StarFormation"
,
"CPU_Chimie"
,
"CPU_Sticky"
,
"CPU_Domain"
,
"CPU_Potential"
,
"CPU_Predict"
,
"CPU_TimeLine"
,
"CPU_Snapshot"
,
"CPU_Peano"
,
"CPU_PM"
,
"CPU_Begrun"
]
elif
opt
.
mode
==
'accel'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Accel"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_Gravity"
,
"CPU_Hydro"
,
"CPU_PM"
]
elif
opt
.
mode
==
'physics'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Physics"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_StarFormation"
,
"CPU_Sticky"
,
"CPU_Chimie"
]
#"CPU_Cooling",
elif
opt
.
mode
==
'leapfrog'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Leapfrog"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_Predict"
,
"CPU_TimeLine"
]
elif
opt
.
mode
==
'gravity'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Gravity"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_TreeConstruction"
,
"CPU_TreeWalk"
,
"CPU_Imbalance"
,
"CPU_CommSum"
]
elif
opt
.
mode
==
'gravity2'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Gravity"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_TreeConstruction"
,
"CPU_Gravity_TreeWalk1"
,
"CPU_Gravity_Imbalance1"
,
"CPU_Gravity_CommSum1"
,
"CPU_Gravity_TreeWalk2"
,
"CPU_Gravity_Imbalance2"
,
"CPU_Gravity_CommSum2"
]
elif
opt
.
mode
==
'hydro'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Hydro"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_HydCompWalk"
,
"CPU_HydCommSumm"
,
"CPU_HydImbalance"
,
"CPU_EnsureNgb"
]
elif
opt
.
mode
==
'domain'
:
if
not
opt
.
nofraction
:
opt
.
fraction
=
True
opt
.
total
=
"CPU_Domain"
if
opt
.
ymin
==
None
:
opt
.
ymin
=
0
if
opt
.
ymax
==
None
:
opt
.
ymax
=
1
modes
=
[
"CPU_Domain_findExtend"
,
"CPU_Domain_determineTopTree"
,
"CPU_Domain_sumCost"
,
"CPU_Domain_findSplit"
,
"CPU_Domain_shiftSplit"
,
"CPU_Domain_countToGo"
,
"CPU_Domain_exchange"
]
else
:
modes
=
string
.
split
(
opt
.
mode
,
','
)
# some inits
colors
=
pt
.
Colors
(
n
=
len
(
modes
))
linestyles
=
pt
.
LineStyles
(
n
=
len
(
files
))
datas
=
[]
# time factor
if
opt
.
time
==
'day'
:
f
=
1.
/
(
60.
*
60.
*
24.
)
elif
opt
.
time
==
'hour'
:
f
=
1.
/
(
60.
*
60.
)
elif
opt
.
time
==
'minute'
:
f
=
1.
/
(
60.
)
elif
opt
.
time
==
'second'
:
f
=
1.
/
(
1.
)
# read files
for
file
in
files
:
#linestyle = linestyles.get()
try
:
vals
=
pt
.
io
.
read_ascii
(
file
)
except
:
Step
,
Time
,
CPUs
,
CPU_Total
,
CPU_Gravity
,
CPU_Hydro
,
CPU_Domain
,
CPU_Potential
,
CPU_Predict
,
CPU_TimeLine
,
CPU_Snapshot
,
CPU_TreeWalk
,
CPU_TreeConstruction
,
CPU_CommSum
,
CPU_Imbalance
,
CPU_HydCompWalk
,
CPU_HydCommSumm
,
CPU_HydImbalance
,
CPU_EnsureNgb
,
CPU_PM
,
CPU_Peano
=
io
.
read_cpu
(
file
)
vals
=
{}
vals
[
"Step"
]
=
Step
vals
[
"Time"
]
=
Time
vals
[
"nCPUs"
]
=
CPUs
vals
[
"CPU_Total"
]
=
CPU_Total
vals
[
"CPU_Gravity"
]
=
CPU_Gravity
vals
[
"CPU_Hydro"
]
=
CPU_Hydro
vals
[
"CPU_Domain"
]
=
CPU_Domain
vals
[
"CPU_Potential"
]
=
CPU_Potential
vals
[
"CPU_Predict"
]
=
CPU_Predict
vals
[
"CPU_TimeLine"
]
=
CPU_TimeLine
vals
[
"CPU_Snapshot"
]
=
CPU_Snapshot
vals
[
"CPU_TreeWalk"
]
=
CPU_TreeWalk
vals
[
"CPU_TreeConstruction"
]
=
CPU_TreeConstruction
vals
[
"CPU_CommSum"
]
=
CPU_CommSum
vals
[
"CPU_Imbalance"
]
=
CPU_Imbalance
vals
[
"CPU_HydCompWalk"
]
=
CPU_HydCompWalk
vals
[
"CPU_HydCommSumm"
]
=
CPU_HydCommSumm
vals
[
"CPU_HydImbalance"
]
=
CPU_HydImbalance
vals
[
"CPU_EnsureNgb"
]
=
CPU_EnsureNgb
vals
[
"CPU_PM"
]
=
CPU_PM
vals
[
"CPU_Peano"
]
=
CPU_Peano
Time
=
vals
[
"Time"
]
nCPUs
=
vals
[
"nCPUs"
]
for
mode
in
modes
:
if
mode
==
'HydroTot'
:
x
=
Time
y
=
vals
[
"CPU_HydCompWalk"
]
+
vals
[
"CPU_HydCommSumm"
]
+
vals
[
"CPU_HydImbalance"
]
+
vals
[
"CPU_EnsureNgb"
]
y
=
y
*
f
data
=
pt
.
DataPoints
(
x
,
y
)
datas
.
append
(
data
)
elif
mode
==
'cpu/step'
:
x
=
Time
x
=
x
[
1
:]
y
=
y
[
1
:]
-
y
[:
-
1
]
data
=
pt
.
DataPoints
(
x
,
y
)
datas
.
append
(
data
)
else
:
if
vals
.
has_key
(
mode
):
data
=
pt
.
DataPoints
(
vals
[
'Time'
],
vals
[
mode
]
*
f
,
color
=
colors
.
get
(),
linestyle
=
linestyles
.
get
(),
label
=
mode
[
4
:])
datas
.
append
(
data
)
# fraction
if
opt
.
fraction
:
cum
=
zeros
(
len
(
vals
[
'Time'
]))
for
d
in
datas
:
d
.
y
=
d
.
y
/
(
vals
[
opt
.
total
]
*
f
)
+
cum
cum
=
d
.
y
# now, plot
for
d
in
datas
:
x
,
y
=
pt
.
CleanVectors
(
d
.
x
,
d
.
y
)
pt
.
plot
(
x
,
y
,
color
=
d
.
color
,
linestyle
=
d
.
linestyle
)
# set limits and draw axis
xmin
,
xmax
,
ymin
,
ymax
=
pt
.
SetLimitsFromDataPoints
(
opt
.
xmin
,
opt
.
xmax
,
opt
.
ymin
,
opt
.
ymax
,
datas
,
opt
.
log
)
pt
.
SetAxis
(
xmin
,
xmax
,
ymin
,
ymax
,
log
=
opt
.
log
)
if
opt
.
legend
:
pt
.
LegendFromDataPoints
(
datas
,
loc
=
'upper left'
)
if
mode
==
'cpu/step'
:
pt
.
xlabel
(
'Simulation Time'
,
fontsize
=
pt
.
labelfont
)
pt
.
ylabel
(
'CPUs/Step'
,
fontsize
=
pt
.
labelfont
)
else
:
pt
.
xlabel
(
'Simulation Time'
)
#pt.ylabel(r'%s [%s]'%(mode,opt.time))
# info
dt
=
Time
[
-
1
]
-
Time
[
0
]
dcpu
=
vals
[
"CPU_Total"
][
-
1
]
-
vals
[
"CPU_Total"
][
0
]
info
=
"
%6.1f
Sec/Time"
%
(
dcpu
/
dt
)
pt
.
title
(
'Runned on
%d
CPUs :
%s
'
%
(
nCPUs
[
0
],
info
))
del
vals
if
__name__
==
'__main__'
:
files
,
opt
=
parse_options
()
pt
.
InitPlot
(
files
,
opt
)
#pt.figure(figsize=(8*2,6*2))
#pt.figure(dpi=10)
#fig = pt.gcf()
#fig.subplots_adjust(left=0.1)
#fig.subplots_adjust(right=1)
#fig.subplots_adjust(bottom=0.12)
#fig.subplots_adjust(top=0.95)
#fig.subplots_adjust(wspace=0.25)
#fig.subplots_adjust(hspace=0.02)
MakePlot
(
files
,
opt
)
pt
.
EndPlot
(
files
,
opt
)
Event Timeline
Log In to Comment