Debian Codegraph @

planetary_system_stacker/Test_programs/mkl_test.py

raw symbols SCIP
1 from ctypes import CDLL, byref, c_int
2 from time import time
3
4 from numpy import random, matmul
5
6
7 def mkl_set_num_threads(cores):
8 mkl_rt.mkl_set_num_threads(byref(c_int(cores)))
9
10
11 mkl_rt_path = "C:\Python35\Lib\site-packages\\numpy\core\mkl_rt.dll"
12 # mkl_rt_path = "C:\Python36\Library\\bin\mkl_rt.dll"
13 mkl_rt = CDLL(mkl_rt_path)
14
15 ndim = 20000
16 iterations = 10
17
18 for number_threads in [1, mkl_rt.mkl_get_max_threads()]:
19 mkl_set_num_threads(number_threads)
20 print("\nNumber of threads used by mkl: " + str(number_threads))
21
22 start = time()
23 matrix = random.rand(ndim, ndim)
24 vector = random.rand(ndim)
25 end = time()
26 print("Time for random number generation: " + str(end - start) + " seconds.")
27
28 start = time()
29 for iter in range(iterations):
30 vector = matmul(matrix, vector)
31 end = time()
32 print("Time for " + str(iterations) + " matrix multiplies: " + str(end - start) + " seconds.")