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 12 kB

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