OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
lapack_testing.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3
4
7
8from subprocess import Popen, STDOUT, PIPE
9import os, sys, math
10import getopt
11# Arguments
12try:
13 opts, args = getopt.getopt(sys.argv[1:], "hd:b:srep:t:n",
14 ["help", "dir=", "bin=", "short", "run", "error","prec=","test=","number"])
15
16except getopt.error as msg:
17 print(msg)
18 print("for help use --help")
19 sys.exit(2)
20
21short_summary = False
22with_file = True
23just_errors = False
24prec='x'
25test='all'
26only_numbers = False
27test_dir='TESTING'
28bin_dir='bin/Release'
29
30for o, a in opts:
31 if o in ("-h", "--help"):
32 print(sys.argv[0]+" [-h|--help] [-d dir |--dir dir] [-s |--short] [-r |--run] [-e |--error] [-p p |--prec p] [-t test |--test test] [-n | --number]")
33 print(" - h is to print this message")
34 print(" - r is to use to run the LAPACK tests then analyse the output (.out files). By default, the script will not run all the LAPACK tests")
35 print(" - d [dir] indicates the location of the LAPACK testing directory (.out files). By default, the script will use {:s}.".format(test_dir))
36 print(" - b [bin] indicates the location of the LAPACK binary files. By default, the script will use {:s}.".format(bin_dir))
37 print(" LEVEL OF OUTPUT")
38 print(" - e is to print only the error summary")
39 print(" - s is to print a short summary")
40 print(" - n is to print the numbers of failing tests (turn on summary mode)")
41 print(" SECLECTION OF TESTS:")
42 print(" - p [s/c/d/z/x] is to indicate the PRECISION to run:")
43 print(" s=single")
44 print(" d=double")
45 print(" sd=single/double")
46 print(" c=complex")
47 print(" z=double complex")
48 print(" cz=complex/double complex")
49 print(" x=all [DEFAULT]")
50 print(" - t [lin/eig/mixed/rfp/all] is to indicate which TEST FAMILY to run:")
51 print(" lin=Linear Equation")
52 print(" eig=Eigen Problems")
53 print(" mixed=mixed-precision")
54 print(" rfp=rfp format")
55 print(" all=all tests [DEFAULT]")
56 print(" EXAMPLES:")
57 print(" ./lapack_testing.py -n")
58 print(" Will return the numbers of failed tests by analyzing the LAPACK output")
59 print(" ./lapack_testing.py -n -r -p s")
60 print(" Will return the numbers of failed tests in REAL precision by running the LAPACK Tests then analyzing the output")
61 print(" ./lapack_testing.py -n -p s -t eig ")
62 print(" Will return the numbers of failed tests in REAL precision by analyzing only the LAPACK output of EIGEN testings")
63 sys.exit(0)
64 else:
65 if o in ("-s", "--short"):
66 short_summary = True
67 if o in ("-r", "--run"):
68 with_file = False
69 if o in ("-e", "--error"):
70 just_errors = True
71 if o in ( '-p', '--prec' ):
72 prec = a
73 if o in ( '-b', '--bin' ):
74 bin_dir = a
75 if o in ( '-d', '--dir' ):
76 test_dir = a
77 if o in ( '-t', '--test' ):
78 test = a
79 if o in ( '-n', '--number' ):
80 only_numbers = True
81 short_summary = True
82
83# process options
84
85abs_bin_dir=os.path.abspath(bin_dir)
86
87os.chdir(test_dir)
88
89execution=1
90summary="\n\t\t\t--> LAPACK TESTING SUMMARY <--\n";
91if with_file: summary+= "\t\tProcessing LAPACK Testing output found in the "+test_dir+" directory\n";
92summary+="SUMMARY \tnb test run \tnumerical error \tother error \n";
93summary+="================ \t===========\t=================\t================ \n";
94nb_of_test=0
95
96# Add current directory to the path for subshells of this shell
97# Allows the popen to find local files in both windows and unixes
98os.environ["PATH"] = os.environ["PATH"]+":."
99
100# Define a function to open the executable (different filenames on unix and Windows)
101def run_summary_test( f, cmdline, short_summary):
102 nb_test_run=0
103 nb_test_fail=0
104 nb_test_illegal=0
105 nb_test_info=0
106
107 if with_file:
108 if not os.path.exists(cmdline):
109 error_message=cmdline+" file not found"
110 r=1
111 if short_summary: return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
112 else:
113 pipe = open(cmdline,'r')
114 r=0
115 else:
116 cmdline = os.path.join(abs_bin_dir, cmdline)
117
118 outfile=cmdline.split()[4]
119 #pipe = open(outfile,'w')
120 p = Popen(cmdline, shell=True)#, stdout=pipe)
121 p.wait()
122 #pipe.close()
123 r=p.returncode
124 pipe = open(outfile,'r')
125 error_message=cmdline+" did not work"
126
127 if r != 0 and not with_file:
128 print("---- TESTING " + cmdline.split()[0] + "... FAILED(" + error_message +") !")
129 for line in pipe.readlines():
130 f.write(str(line))
131 elif r != 0 and with_file and not short_summary:
132 print("---- WARNING: please check that you have the LAPACK output : "+cmdline+"!")
133 print("---- WARNING: with the option -r, we can run the LAPACK testing for you")
134 # print "---- "+error_message
135 else:
136 for line in pipe.readlines():
137 f.write(str(line))
138 words_in_line=line.split()
139 if (line.find("run")!=-1):
140# print line
141 whereisrun=words_in_line.index("run)")
142 nb_test_run+=int(words_in_line[whereisrun-2])
143 if (line.find("out of")!=-1):
144 if not short_summary: print(line, end=' ')
145 whereisout= words_in_line.index("out")
146 nb_test_fail+=int(words_in_line[whereisout-1])
147 if ((line.find("illegal")!=-1) or (line.find("Illegal")!=-1)):
148 if not short_summary: print(line, end=' ')
149 nb_test_illegal+=1
150 if (line.find(" INFO")!=-1):
151 if not short_summary: print(line, end=' ')
152 nb_test_info+=1
153 if with_file:
154 pipe.close()
155
156 f.flush();
157
158 return [nb_test_run,nb_test_fail,nb_test_illegal,nb_test_info]
159
160
161# If filename cannot be opened, send output to sys.stderr
162filename = "testing_results.txt"
163try:
164 f = open(filename, 'w')
165except IOError:
166 f = sys.stdout
167
168if not short_summary:
169 print(" ")
170 print("---------------- Testing LAPACK Routines ----------------")
171 print(" ")
172 print("-- Detailed results are stored in", filename)
173
174dtypes = (
175("s", "d", "c", "z"),
176("REAL ", "DOUBLE PRECISION", "COMPLEX ", "COMPLEX16 "),
177)
178
179if prec=='s':
180 range_prec=[0]
181elif prec=='d':
182 range_prec=[1]
183elif prec=='sd':
184 range_prec=[0,1]
185elif prec=='c':
186 range_prec=[2]
187elif prec=='z':
188 range_prec=[3]
189elif prec=='cz':
190 range_prec=[2,3]
191else:
192 prec='x';
193 range_prec=list(range(4))
194
195if test=='lin':
196 range_test=[16]
197elif test=='mixed':
198 range_test=[17]
199 range_prec=[1,3]
200elif test=='rfp':
201 range_test=[18]
202elif test=='eig':
203 range_test=list(range(16))
204else:
205 range_test=list(range(19))
206
207list_results = [
208[0, 0, 0, 0, 0],
209[0, 0, 0, 0, 0],
210[0, 0, 0, 0, 0],
211[0, 0, 0, 0, 0],
212]
213
214for dtype in range_prec:
215 letter = dtypes[0][dtype]
216 name = dtypes[1][dtype]
217
218 if not short_summary:
219 print(" ")
220 print("------------------------- %s ------------------------" % name)
221 print(" ")
222 sys.stdout.flush()
223
224 dtests = (
225 ("nep", "sep", "se2", "svd",
226 letter+"ec",letter+"ed",letter+"gg",
227 letter+"gd",letter+"sb",letter+"sg",
228 letter+"bb","glm","gqr",
229 "gsv","csd","lse",
230 letter+"test", letter+dtypes[0][dtype-1]+"test",letter+"test_rfp"),
231 ("Nonsymmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Problem-2-stage", "Singular-Value-Decomposition",
232 "Eigen-Condition","Nonsymmetric-Eigenvalue","Nonsymmetric-Generalized-Eigenvalue-Problem",
233 "Nonsymmetric-Generalized-Eigenvalue-Problem-driver", "Symmetric-Eigenvalue-Problem", "Symmetric-Eigenvalue-Generalized-Problem",
234 "Banded-Singular-Value-Decomposition-routines", "Generalized-Linear-Regression-Model-routines", "Generalized-QR-and-RQ-factorization-routines",
235 "Generalized-Singular-Value-Decomposition-routines", "CS-Decomposition-routines", "Constrained-Linear-Least-Squares-routines",
236 "Linear-Equation-routines", "Mixed-Precision-linear-equation-routines","RFP-linear-equation-routines"),
237 (letter+"nep", letter+"sep", letter+"se2", letter+"svd",
238 letter+"ec",letter+"ed",letter+"gg",
239 letter+"gd",letter+"sb",letter+"sg",
240 letter+"bb",letter+"glm",letter+"gqr",
241 letter+"gsv",letter+"csd",letter+"lse",
242 letter+"test", letter+dtypes[0][dtype-1]+"test",letter+"test_rfp"),
243 )
244
245
246 for dtest in range_test:
247 nb_of_test=0
248 # NEED TO SKIP SOME PRECISION (namely s and c) FOR PROTO MIXED PRECISION TESTING
249 if dtest==17 and (letter=="s" or letter=="c"):
250 continue
251 if with_file:
252 cmdbase=dtests[2][dtest]+".out"
253 else:
254 if dtest==16:
255 # LIN TESTS
256 cmdbase="xlintst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
257 elif dtest==17:
258 # PROTO LIN TESTS
259 cmdbase="xlintst"+letter+dtypes[0][dtype-1]+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
260 elif dtest==18:
261 # PROTO LIN TESTS
262 cmdbase="xlintstrf"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
263 else:
264 # EIG TESTS
265 cmdbase="xeigtst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
266 if not just_errors and not short_summary:
267 print("Testing "+name+" "+dtests[1][dtest]+"-"+cmdbase, end=' ')
268 # Run the process: either to read the file or run the LAPACK testing
269 nb_test = run_summary_test(f, cmdbase, short_summary)
270 list_results[0][dtype]+=nb_test[0]
271 list_results[1][dtype]+=nb_test[1]
272 list_results[2][dtype]+=nb_test[2]
273 list_results[3][dtype]+=nb_test[3]
274 got_error=nb_test[1]+nb_test[2]+nb_test[3]
275
276 if not short_summary:
277 if nb_test[0] > 0 and not just_errors:
278 print("passed: "+str(nb_test[0]))
279 if nb_test[1] > 0:
280 print("failing to pass the threshold: "+str(nb_test[1]))
281 if nb_test[2] > 0:
282 print("Illegal Error: "+str(nb_test[2]))
283 if nb_test[3] > 0:
284 print("Info Error: "+str(nb_test[3]))
285 if got_error > 0 and just_errors:
286 print("ERROR IS LOCATED IN "+name+" "+dtests[1][dtest]+" [ "+cmdbase+" ]")
287 print("")
288 if not just_errors:
289 print("")
290# elif (got_error>0):
291# print dtests[2][dtest]+".out \t"+str(nb_test[1])+"\t"+str(nb_test[2])+"\t"+str(nb_test[3])
292
293 sys.stdout.flush()
294 if (list_results[0][dtype] > 0 ):
295 percent_num_error=float(list_results[1][dtype])/float(list_results[0][dtype])*100
296 percent_error=float(list_results[2][dtype]+list_results[3][dtype])/float(list_results[0][dtype])*100
297 else:
298 percent_num_error=0
299 percent_error=0
300 summary+=name+"\t"+str(list_results[0][dtype])+"\t\t"+str(list_results[1][dtype])+"\t("+"%.3f" % percent_num_error+"%)\t"+str(list_results[2][dtype]+list_results[3][dtype])+"\t("+"%.3f" % percent_error+"%)\t""\n"
301 list_results[0][4]+=list_results[0][dtype]
302 list_results[1][4]+=list_results[1][dtype]
303 list_results[2][4]+=list_results[2][dtype]
304 list_results[3][4]+=list_results[3][dtype]
305
306if only_numbers:
307 print(str(list_results[1][4])+"\n"+str(list_results[2][4]+list_results[3][4]))
308else:
309 print(summary)
310 if (list_results[0][4] > 0 ):
311 percent_num_error=float(list_results[1][4])/float(list_results[0][4])*100
312 percent_error=float(list_results[2][4]+list_results[3][4])/float(list_results[0][4])*100
313 else:
314 percent_num_error=0
315 percent_error=0
316 if (prec=='x'):
317 print("--> ALL PRECISIONS\t"+str(list_results[0][4])+"\t\t"+str(list_results[1][4])+"\t("+"%.3f" % percent_num_error+"%)\t"+str(list_results[2][4]+list_results[3][4])+"\t("+"%.3f" % percent_error+"%)\t""\n")
318 if list_results[0][4] == 0:
319 print("NO TESTS WERE ANALYZED, please use the -r option to run the LAPACK TESTING")
320
321# This may close the sys.stdout stream, so make it the last statement
322f.close()
run_summary_test(f, cmdline, short_summary)