NeoPZ
test.py
Go to the documentation of this file.
1 #! /usr/bin/env python2.7
2 #***************************************************************************
3 #* Copyright (C) 2013 by Edson Borin *
4 #* edson@ic.unicamp.br *
5 #* *
6 #* This program is free software; you can redistribute it and/or modify *
7 #* it under the terms of the GNU General Public License as published by *
8 #* the Free Software Foundation; either version 2 of the License, or *
9 #* (at your option) any later version. *
10 #* *
11 #* This program is distributed in the hope that it will be useful, *
12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 #* GNU General Public License for more details. *
15 #* *
16 #* You should have received a copy of the GNU General Public License *
17 #* along with this program; if not, write to the *
18 #* Free Software Foundation, Inc., *
19 #* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 #**************************************************************************/
21 
22 # ---------------------------------------------
23 # Performance test module
24 
25 # List of rdt files generated by the test
26 rdtfiles_l = [
27  # short_name, option, filename, description
28  ("ass", "-ass_rdt", "ass.rdt", "Assemble: dohrstruct->Assemble(...). Assemble element matrices and decompose matrices."),
29  ("cre", "-cre_rdt", "cre.rdt", "Create: dohrstruct->Create()"),
30  ("sol", "-sol_rdt", "sol.rdt", "Solver: cg.Solve(...)"),
31  ("tot", "-tot_rdt", "tot.rdt", "Total: all the steps"),
32  ("dohrass", "-tpz_dohr_ass", "tpzdohrass.rdt", "Assemble element matrices"),
33  ("dohrdec", "-tpz_dohr_dec", "tpzdohrdec.rdt", "Decompose matrices")
34 ]
35 
36 def short_description() : return "substructure -- 8andares02.txt -- num_it 1000 - p2 - nsub 128 - 64 threads - realloc"
37 
38 def long_description():
39  desc = "Execute the substruct tool collecting statistics for the following steps:"
40  for rdtarg in rdtfiles_l :
41  desc = desc + '\n\t' + rdtarg[0] + ' (' + rdtarg[1] + ' ' + rdtarg [2] + ') : ' + rdtarg[3]
42  return desc
43 # ---------------------------------------------
44 
45 import sys
46 import os.path
47 import shlex, subprocess
48 import resource
49 
50 # Try to import rdt and stats modules, if available.
51 import sys
52 
53 # Variables to be defined by cmake
54 builddir="@PERFTEST_BASE_DIR@"
55 datadir="@PERFTEST_SMALL_DATA_DIR@"
56 
57 def error(message, status):
58  sys.stderr.write('ERROR (test.py): '+message+'\n')
59  sys.exit(status)
60 
61 # Setup the command line
62 def setup_cmd():
63  # Check build directory
64  if not os.path.isdir(builddir) :
65  error(builddir+' is an invalid build directory.', 1)
66  # Check run directory
67  rundir = os.path.join(builddir,'scripts','substruct_tst12')
68  if not os.path.isdir(rundir) :
69  error(rundir+' is an invalid run directory.', 1)
70  if not os.path.isdir(builddir) :
71  error(builddir+' is an invalid build directory.', 1)
72  # Check executable
73  executable=os.path.join(builddir,"progs","substruct", "substruct-perf")
74  if not os.path.isfile(executable) :
75  error(executable+' is an invalid executable file name.', 1)
76  # Check input file
77  inputfn = os.path.join(datadir,"substruct","inputs","8andares02.txt")
78  if not os.path.isfile(inputfn) :
79  error(inputfn+' is an invalid input file name.', 1)
80  # Put the arguments together
81  arguments = ' -mp '+inputfn
82  arguments = arguments + ' -num_it 1000'
83  #NUMA aware Dohrman Assembly List thread work objects re-allocation.
84  arguments = arguments + ' -naDALora'
85  #NUMA aware Dohrman Assembly List thread work objects re-allocation threshold.
86  #arguments = arguments + ' -naDALorat 1835008' # 2/2MB(l2) + 6/8MB(l3)
87  #NUMA aware (node round-robin) Dohrman Assembly List thread work scheduling.
88  arguments = arguments + ' -naDALtws'
89  arguments = arguments + ' -nsub 128'
90  arguments = arguments + ' -nt_a 64'
91  arguments = arguments + ' -nt_d 64'
92  arguments = arguments + ' -nt_m 64'
93  arguments = arguments + ' -nt_sm 64'
94  arguments = arguments + ' -p 2'
95  for rdtarg in rdtfiles_l :
96  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
97  # TODO: Add arguments to enforce output checking!
98  return rundir, executable+arguments
99 
100 # Limits for this test
101 # 38400 = 64 (cores) * (60) * (10) = 10 minutes in 64 cores.
102 limits = { "cpu" : (resource.RLIMIT_CPU, 38400, "Max CPU user time in seconds (not wall clock time)"),
103 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
104 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
105 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
106 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
107 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
108  }
109 
110 # Set the rlimits of the chidren process (see limits above)
111 # TODO: Improve the handling of sandboxing limits
112 def setlimits():
113  print "Setting resource limit in child"
114  for k, v in limits.iteritems() :
115  resource.setrlimit(v[0], (v[1],v[1]))
116  #print k, " : ", v[0], " => ", v[1]
117 
118 # Sumarizes the RDT (Raw data table) files information
119 def sumarize_rdt_files(rundir) :
120  results = {}
121  for f in rdtfiles_l :
122  rdt_id = f[0] # Step name
123  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
124  rdt_dsc = f[3] # Description
125  results[rdt_id] = (rdt_fn, rdt_dsc)
126  return results
127 
128 # Execute the test.
129 def run_test(ntimes):
130  rundir,cmd=setup_cmd()
131  print short_description()
132  print "CMD:",cmd
133  args = shlex.split(cmd)
134  sout = None
135  serr = None
136  for i in range(ntimes) :
137  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
138  p.wait()
139  if (p.returncode != 0) :
140  return p.returncode, {}
141  results = sumarize_rdt_files(rundir)
142  return 0, results
143 
def short_description()
Definition: test.py:36
def error(message, status)
Definition: test.py:57
def sumarize_rdt_files(rundir)
Definition: test.py:119
def run_test(ntimes)
Definition: test.py:129
def setup_cmd()
Definition: test.py:62