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 
37 def short_description() : return "substructure -- 8andares02.txt -- num_it 1000 - p2 - nsub 64 - serial"
38 
39 def long_description():
40  desc = "Execute the substruct tool collecting statistics for the following steps:"
41  for rdtarg in rdtfiles_l :
42  desc = desc + '\n\t' + rdtarg[0] + ' (' + rdtarg[1] + ' ' + rdtarg [2] + ') : ' + rdtarg[3]
43  return desc
44 # ---------------------------------------------
45 
46 import sys
47 import os.path
48 import shlex, subprocess
49 import resource
50 
51 # Try to import rdt and stats modules, if available.
52 import sys
53 
54 # Variables to be defined by cmake
55 builddir="@PERFTEST_BASE_DIR@"
56 datadir="@PERFTEST_SMALL_DATA_DIR@"
57 
58 def error(message, status):
59  sys.stderr.write('ERROR (test.py): '+message+'\n')
60  sys.exit(status)
61 
62 # Setup the command line
63 def setup_cmd():
64  # Check build directory
65  if not os.path.isdir(builddir) :
66  error(builddir+' is an invalid build directory.', 1)
67  # Check run directory
68  rundir = os.path.join(builddir,'scripts','substruct_tst06')
69  if not os.path.isdir(rundir) :
70  error(rundir+' is an invalid run directory.', 1)
71  if not os.path.isdir(builddir) :
72  error(builddir+' is an invalid build directory.', 1)
73  # Check executable
74  executable=os.path.join(builddir,"progs","substruct", "substruct-perf")
75  if not os.path.isfile(executable) :
76  error(executable+' is an invalid executable file name.', 1)
77  # Check input file
78  inputfn = os.path.join(datadir,"substruct","inputs","8andares02.txt")
79  if not os.path.isfile(inputfn) :
80  error(inputfn+' is an invalid input file name.', 1)
81  # Put the arguments together
82  arguments = ' -mp '+inputfn
83  arguments = arguments + ' -num_it 1000'
84  #NUMA aware Dohrman Assembly List thread work objects re-allocation.
85  #arguments = arguments + ' -naDALora'
86  #NUMA aware Dohrman Assembly List thread work objects re-allocation threshold.
87  #arguments = arguments + ' -naDALorat 1835008' # 2/2MB(l2) + 6/8MB(l3)
88  #NUMA aware (node round-robin) Dohrman Assembly List thread work scheduling.
89  #arguments = arguments + ' -naDALtws'
90  arguments = arguments + ' -nsub 64'
91  arguments = arguments + ' -nt_a 0'
92  arguments = arguments + ' -nt_d 0'
93  arguments = arguments + ' -nt_m 0'
94  arguments = arguments + ' -nt_sm 0'
95  arguments = arguments + ' -p 2'
96  for rdtarg in rdtfiles_l :
97  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
98  # TODO: Add arguments to enforce output checking!
99  return rundir, executable+arguments
100 
101 # Limits for this test
102 # 38400 = 64 (cores) * (60) * (10) = 10 minutes in 64 cores.
103 limits = { "cpu" : (resource.RLIMIT_CPU, 38400, "Max CPU user time in seconds (not wall clock time)"),
104 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
105 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
106 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
107 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
108 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
109  }
110 
111 # Set the rlimits of the chidren process (see limits above)
112 # TODO: Improve the handling of sandboxing limits
113 def setlimits():
114  print "Setting resource limit in child"
115  for k, v in limits.iteritems() :
116  resource.setrlimit(v[0], (v[1],v[1]))
117  #print k, " : ", v[0], " => ", v[1]
118 
119 # Sumarizes the RDT (Raw data table) files information
120 def sumarize_rdt_files(rundir) :
121  results = {}
122  for f in rdtfiles_l :
123  rdt_id = f[0] # Step name
124  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
125  rdt_dsc = f[3] # Description
126  results[rdt_id] = (rdt_fn, rdt_dsc)
127  return results
128 
129 # Execute the test.
130 def run_test(ntimes):
131  rundir,cmd=setup_cmd()
132  print short_description()
133  print "CMD:",cmd
134  args = shlex.split(cmd)
135  sout = None
136  serr = None
137  for i in range(ntimes) :
138  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
139  p.wait()
140  if (p.returncode != 0) :
141  return p.returncode, {}
142  results = sumarize_rdt_files(rundir)
143  return 0, results
def sumarize_rdt_files(rundir)
Definition: test.py:120
def error(message, status)
Definition: test.py:58
def setup_cmd()
Definition: test.py:63
def short_description()
Definition: test.py:37
def run_test(ntimes)
Definition: test.py:130