chameleon_testing.py 6.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#! /usr/bin/env python
# -*- coding: utf-8 -*-


###############################################################################
# morse_testing.py  [nbcores]
#  nbcores is a optional argument to give the number of cores to run the testing
# Example:
#     ./morse_testing.py
#                 No argument, so will run on half of the core if the machine has more than 2 cores
#     ./morse_testing.py nbcores
#                 Will run on nbcores
###############################################################################

from subprocess import Popen, STDOUT, PIPE
import os, sys, math
import getopt

# Linux Unix and MacOS:
if hasattr(os, "sysconf"):
   if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
           ncpus_av = os.sysconf("SC_NPROCESSORS_ONLN")
# Windows:
if os.environ.has_key("NUMBER_OF_PROCESSORS"):
   ncpus_av = int(os.environ["NUMBER_OF_PROCESSORS"]);

# we are going to run on half of the cores by default if we have more than 2 cores
if (ncpus_av > 2):
   ncpus=int(math.floor(ncpus_av/2))
else:
   ncpus=ncpus_av

try:
   opts, args = getopt.getopt(sys.argv[1:], "hnc:g:",
                              ["help", "cores=", "ngpus="])

except getopt.error, msg:
   print msg
   print "for help use --help"
   sys.exit(2)

# process options
ngpus=0;
execution=1;

for o, a in opts:
   if o in ("-h", "--help"):
48
      print sys.argv[0]+" [-h|--help] [-c n|--cores=n] [-g m|--ngpus=m]"
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      print "  -c Fix the number of cores"
      print "  -g Fix the number of gpus"
      print "  -n Print the commands only"
      sys.exit(0)
   else:
      if o in ( '-c', '--ncores' ):
         ncpus = a
      elif o in ( '-g' , '--ngpus' ):
         ngpus = a
      elif o in ( '-n' , '--noexec' ):
         execution=0

# Add current directory to the path for subshells of this shell
# Allows the popen to find local files in both windows and unixes
os.environ["PATH"] = os.environ["PATH"]+":."

# Define a function to open the executable (different filenames on unix and Windows)
def local_popen( f, cmdline ):
   if os.name != 'nt':
      cmdline="./" + cmdline

   if execution==0:
      print cmdline
   else:
      p=Popen( cmdline, shell=True, stdout=PIPE, stderr=STDOUT )

      r=p.poll()
      while r == None:
         r=p.poll()
      pipe=p.stdout

      if r != 0:
         print "---- TESTING " + cmdline.split()[3] + "... FAILED(" + str(p.returncode) +") !"
         for line in pipe.readlines():
            f.write(str(line))
      else:
         found=0
         for line in pipe.readlines():
            f.write(str(line))
            if "TESTING" in line :
               found = 1
               print line,
         if found == 0:
            print cmdline.split()[0] + " " + cmdline.split()[3] + ": FAILED(Unexpected error)"

   f.flush();
   return 0


# If filename cannot be opened, send output to sys.stderr
filename = "testing_results.txt"
try:
     f = open(filename, 'w')
except IOError:
     f = sys.stdout

print " "
Mathieu Faverge's avatar
Mathieu Faverge committed
106
print "---------------- Testing CHAMELEON Routines ----------------"
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
print " "
print "-- Number of cores available =", ncpus_av
print "-- Number of cores used for testing =", ncpus
print "-- Number of  gpus used for testing =", ngpus
print "-- Detailed results are stored in", filename

dtypes = (
("s", "d", "c", "z"),
("Single", "Double", "Complex", "Double Complex"),
)

for dtype in range(4):
  letter = dtypes[0][dtype]
  name = dtypes[1][dtype]

#  print " "
#  print "--------------------- In Place Transformation -------------------"
#  print " "
  sys.stdout.flush()

  cmdbase="%stesting " % letter + str(ncpus) + " " + str(ngpus)

#  test01=local_popen(f, cmdbase + " GECFI" + " 623 531 123 145 136 134")
#  test02=local_popen(f, cmdbase + " GETMI" + " 623 531 123 145")

  print " "
  print "------------------------- %s ------------------------" % name
  print " "
  sys.stdout.flush()

137 138 139 140 141 142 143
  test0 = local_popen(f, cmdbase + " LANGE" + " 914 510 950")
  test1 = local_popen(f, cmdbase + " GEMM"  + " 1.0 -2.0 623 531 550 650 625 700")
  test2 = local_popen(f, cmdbase + " TRSM"  + " -2.0 623 531 650 625")
  test3 = local_popen(f, cmdbase + " TRMM"  + " -2.0 623 531 650 625")
  test4 = local_popen(f, cmdbase + " SYMM"  + " 1.0 -2.0 623 531 650 625 700")
  test5 = local_popen(f, cmdbase + " SYRK"  + " 1.0 -2.0 623 531 650 625")
  test6 = local_popen(f, cmdbase + " SYR2K" + " 1.0 -2.0 623 531 650 625 700")
144 145

  if letter in ( "c", "z" ) :
146 147 148
     test101 = local_popen(f, "%stesting " % letter + str(ncpus) + " " + str(ngpus) + " HEMM" + " 1.0 -2.0 623 531 650 625 623")
     test102 = local_popen(f, "%stesting " % letter + str(ncpus) + " " + str(ngpus) + " HERK" + " 1.0 -2.0 623 531 650 625")
     test102 = local_popen(f, "%stesting " % letter + str(ncpus) + " " + str(ngpus) + " HER2K"+ " 1.0 -2.0 623 531 650 625 700")
149

150 151
  test20 = local_popen(f, cmdbase + " POSV"  + " 531 623 25 700")
  test21 = local_popen(f, cmdbase + " POTRI" + " 531 623")
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  test22 = local_popen(f, cmdbase + " GELS"  + " 0 800 400 825 25 810")
  test23 = local_popen(f, cmdbase + " GELS"  + " 1 800 400 825 25 810 4")
  test24 = local_popen(f, cmdbase + " GELS"  + " 0 400 800 825 25 810")
  test25 = local_popen(f, cmdbase + " GELS"  + " 1 400 800 825 25 810 4")
  test26 = local_popen(f, cmdbase + " GESV_INCPIV"  + " 800 825 25 810")
#  test26 = local_popen(f, cmdbase + " GESV"  + " 800 825 25 810")
#  test27 = local_popen(f, cmdbase + " GETRI" + " 800 825")
#  test28 = local_popen(f, cmdbase + " GESVD" + " 0 825 800 855")
#  test29 = local_popen(f, cmdbase + " GESVD" + " 0 800 825 810")
#  test30 = local_popen(f, cmdbase + " HEGV"  + " 800 825 810")
#  test31 = local_popen(f, cmdbase + " HEEV"  + " 800 825")
#  test32 = local_popen(f, cmdbase + " HEGST" + " 800 825 810")
  sys.stdout.flush()

#print " "
#print "--------------------- Mixed Precision -------------------"
#print " "

#for substr in ( ("z", "C"), ("d", "S") ):
#  cmdbase="%stesting " % substr[0] + str(ncpus) + " " + str(ngpus)

#  test201 = local_popen(f, cmdbase + " %sGESV"   % substr[1] + " 800 825 25 810")
#  test202 = local_popen(f, cmdbase + " %sUNGESV" % substr[1] + " 800 825 25 810")
#  test203 = local_popen(f, cmdbase + " %sPOSV"   % substr[1] + " 800 825 25 810")
#  sys.stdout.flush()



# This may close the sys.stdout stream, so make it the last statement
f.close()