You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lapack_testing.py 13 kB

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