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.

dgesv.py 1.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4. import time
  5. import numpy
  6. from numpy.random import randn
  7. from scipy.linalg.lapack import dgesv
  8. def run_dgesv(N,l):
  9. a = randn(N,N).astype('float64')
  10. b = randn(N,N).astype('float64')
  11. start = time.time();
  12. for i in range(0,l):
  13. dgesv(a,b,1,1)
  14. end = time.time()
  15. timediff = (end -start)
  16. mflops = ( 2.0/3.0 *N*N*N + 2.0*N*N*N) *l / timediff
  17. mflops *= 1e-6
  18. size = "%dx%d" % (N,N)
  19. print("%14s :\t%20f MFlops\t%20f sec" % (size,mflops,timediff))
  20. if __name__ == "__main__":
  21. N=128
  22. NMAX=2048
  23. NINC=128
  24. LOOPS=1
  25. z=0
  26. for arg in sys.argv:
  27. if z == 1:
  28. N = int(arg)
  29. elif z == 2:
  30. NMAX = int(arg)
  31. elif z == 3:
  32. NINC = int(arg)
  33. elif z == 4:
  34. LOOPS = int(arg)
  35. z = z + 1
  36. if 'OPENBLAS_LOOPS' in os.environ:
  37. p = os.environ['OPENBLAS_LOOPS']
  38. if p:
  39. LOOPS = int(p);
  40. print("From: %d To: %d Step=%d Loops=%d" % (N, NMAX, NINC, LOOPS))
  41. print("\tSIZE\t\t\tFlops\t\t\t\t\tTime")
  42. for i in range (N,NMAX+NINC,NINC):
  43. run_dgesv(i,LOOPS)