ug4
Statistics Utility

Functions

function util adjuststring (str, len, type)
 
function util fill (N, c)
 
function util flattenTable (tab, name, resTable)
 
function util getStats (stats, bHeader, seperator, bStats, seperator2)
 
function util printFormattedTable (tab, bNumbers, type, header)
 
function util printFormattedTableSideways (tab, bNumbers, header)
 
function util printStats (stats)
 
function util statsUtilGetHeader (header, tab)
 
function util StringTableFromTable (tab, header, s)
 
function util writeFileStats (stats, filename, seperator)
 

Detailed Description

Author
Martin Rupp

This file and the comments are intended to make your life easier when you want to do several runs of a script and you need to evaluate data from the runs, like compare solution times for different number of refinements. First you need to know, what statistics you want to output and compare. Imagine you want to run laplace.lua for several different numRefs or even num procs, and results should be saved in a file "stats.txt", so that you can use in a spreadsheet. The stats format is as follows: it is an array, consisting of entries {description, content} So we need to add to our laplace.lua file the following lines:

stats = { {"procs", GetNumProcesses()}, {"numRefs", numRefs}, {"steps", convCheck:step()}, {"SVN Revision", GetSVNRevision()} }
util.writeFileStats(stats, "stats.txt")
parameterNumber numRefs
string GetSVNRevision()
Definition: misc_bridge.cpp:416

after 2 runs, the file stats.txt looks as follows

procs   numRefs   steps   SVN Revision
4   8   6   4459M
16  9   6   4459M

Note that a heading "procs numRefs..." is added to the file if it is empty. All items are seperated by default by " \t", but you can choose different seperators. You can copy and paste the data in most spreadsheet applications like OpenOffice Calc, Excel and Apple Numbers. If you wish a brief table result description of the current task, you can use

util.printStats(stats)

which prints

  procs: 4
  numRefs: 16
  steps: 6
  SVN Revision: 4459M
  to the console

For boolean values, use tostring(bExternalCoarsening) -> "true" / "false". You can seperate your runs by date with the following example bash script:

mydate=`date +%Y-%m-%d-%H.%M.%S`
mkdir $mydate
for i in {3..6}
do
./ugshell -ex mycheck.lua -outdir $mydate/ -logtofile $mydate/mycheck${i} -numRefs $i
done
parameterString ex
Executes the specified script.
Definition: command_line_util.lua:350
parameterString logtofile
Output will be written to the specified file.
Definition: command_line_util.lua:351

and in you lua-file, you could use util.writeFileStats(stats, util.GetParam("-outdir", "").."stats.txt"). Instead of defining -logtofile from the shell, you could also make something like GetLogAssistant():enable_file_output(true, util.GetParam("-outdir". "").."check_numRefs"..numRefs.."_procs"..procs..".txt")

Function Documentation

◆ adjuststring()

function util adjuststring ( str  ,
len  ,
type   
)

util.adjuststring returns a string with whitespace left and right so that total string length is len

Parameters
strstring used
lentotal length of resulting string
typepadding type: "l" = string is on left, "c" = centered, "r" = right. default "l"

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :99-111

function util.adjuststring(str, len, type)
if type == nil then
type = "l"
end
local l=string.len(str)
local m=0
if type == "c" then
m=math.ceil((len-l)/2)
elseif type == "r" then
m=len-l
end
return util.fill(m)..str..util.fill(len-m-l)
end
int local(bglp_vertex_descriptor p)
Definition: parallel_matrix.h:57

◆ fill()

function util fill ( ,
 
)

util.fill returns a string consisting of N times the character c

Parameters
Nnumber of times c is to be repeated
ccharacter to repeat (if omitted, " ")

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :84-91

function util.fill(N, c)
local s=""
if c == nil then c = " " end
for i=1,N do
s=s..c
end
return s
end
parameterString s

Referenced by ug::SparseMatrix< TValueType >::clear_retain_structure(), ug::CreatePlane(), and ug::VecCopy().

◆ flattenTable()

function util flattenTable ( tab  ,
name  ,
resTable   
)

inserts the table tab into resTable in a "flat" way that means, subtables are getting indices so that the resulting table has no subtables example: tab = {a=2, b="hi", c={word=3, nose=4} } res = {} flattenTable(tab, "tab", res) res = { {"tab.a", 2}, {"tab.b", "hi"}, {"tab.c.word", 3}, {"tab.c.nose", 4} } especially usefull for util.writeFileStats note: syntax {name, value} used instead of name=value because this way the order is stable

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :361-374

function util.flattenTable(tab, name, resTable)
local tName = ""
if name ~= nil then
tName = name.."."
end
if type(tab) == "table" then
for i, v in pairs(tab) do
util.flattenTable(v, tName..i, resTable)
end
elseif type(tab) ~= "userdata" then
table.insert(resTable, {name, tab})
end
return resTable
end
location name
Definition: checkpoint_util.lua:128

◆ getStats()

function util getStats ( stats  ,
bHeader  ,
seperator  ,
bStats  ,
seperator2   
)

util.getStats internal method

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :39-54

function util.getStats(stats, bHeader, seperator, bStats, seperator2)
local output=""
for i,v in ipairs(stats) do
if bHeader then output = output..v[1]..seperator end
if bStats then
if v[2] == nil then
print("value for item "..v[1].." is nil!")
output = output.." "..seperator2
else
output = output..tostring(v[2])..seperator2
end
end
end
output = output.."\n"
return output
end
function table print(data, style)

References ug::detail::local(), and print().

◆ printFormattedTable()

function util printFormattedTable ( tab  ,
bNumbers  ,
type  ,
header   
)

util.printFormattedTable prints stats to the console

Parameters
tabtable in the form t={{["colA"
bNumbersif true, print a colum with the key of the table (default false)
typetype of column padding ("r", "l" or "c", default "l")
headercolums to be printed, like {"colA", "colB"}. if nil, all. location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :170-231

◆ printFormattedTableSideways()

function util printFormattedTableSideways ( tab  ,
bNumbers  ,
header   
)

util.printFormattedTableSideways prints stats to the console, sideways

Parameters
tabtable in the form t={{["colA"
typetype of row padding ("r", "l" or "c", default "l")
bNumbersif true, print a colum with the number of the table (default false)
headercolums to be printed, like {"colA", "colB"}, if nil: all

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :254-304

◆ printStats()

function util printStats ( stats  )

util.printStats prints stats to the console

Parameters
statslocation: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :116-125
function util.printStats(stats)
local maxlen=2
for i,v in ipairs(stats) do
maxlen = math.max(maxlen, string.len(v[1]))
end
for i,v in ipairs(stats) do
print(util.adjuststring(v[1], maxlen)..": "..tostring(v[2]))
end
end

◆ statsUtilGetHeader()

function util statsUtilGetHeader ( header  ,
tab   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :128-142

function util.statsUtilGetHeader(header, tab)
if header == nil then
local h = {}
header = {}
for i, v in pairs(tab) do
for j, col in pairs(v) do
if h[j] == nil then
h[j] = j
table.insert(header, j)
end
end
end
end
return header
end

◆ StringTableFromTable()

function util StringTableFromTable ( tab  ,
header  ,
s   
)

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :307-341

◆ writeFileStats()

function util writeFileStats ( stats  ,
filename  ,
seperator   
)

util.writeFileStats writes stats to a file

Parameters
stats
filename
seperator(default " \t")

location: /home/runner/work/docs/docs/ug4/ugcore/scripts/util / stats_util.lua :62-77

function util.writeFileStats(stats, filename, seperator)
if seperator == nil then
seperator = " \t"
end
local output = io.open(filename, "a")
if output == null then
print("Could not open"..filename)
else
if fsize(output) == 0 then
output:write("#"..util.getStats(stats, true, seperator, false, seperator))
end
output:write(util.getStats(stats, false, seperator, true, seperator))
end
end
function util FileDummy write(...) end