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

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