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

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