Advertisement
Appendko

demo_mkl_num.py

Apr 29th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import os,sys
  2. import numpy as np
  3. import time
  4.  
  5. #example for multithread numpy/scipy using Intel MKL:
  6. #acture it's amazingly easy by setting the following:
  7. #os.environ['MKL_NUM_THREADS']="8"
  8.  
  9. def demo_eig(n):
  10.     a=np.random.rand(n,n)
  11.     a=a+a.transpose()-np.diag(np.diag(a))
  12.     w,v=np.linalg.eigh(a)
  13.     return
  14.  
  15. def demo_num_thread():
  16.     res=0.0
  17.     for i in range(10):
  18.         t=time.time()
  19.         demo_eig(2000)
  20.         res+=time.time()-t
  21.     print("%s core: %f"%(os.environ['MKL_NUM_THREADS'],res))
  22.     return
  23.  
  24. os.environ['MKL_NUM_THREADS']=sys.argv[1]
  25. demo_num_thread()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement