Hi everyone!
I'm running the following numpy benchmark inside of Sage, and comparing it with the results I get by just running Python.
import numpy as np
import time
n = int(10000)
A = np.random.randn(n,n).astype('float64')
B = np.random.randn(n,n).astype('float64')
start_time = time.time()
nrm = np.linalg.norm(np.matmul(A,B))
print(" took {} seconds ".format(time.time() - start_time))
print(" norm = ",nrm)
It turns out that the script above runs almost 10x faster when run inside of a standard Python environment, rather than, e.g. inside of a Sage environment in a Jupyter notebook.
I checked the version of numpy installed, especially the BLAS info, and got identical results for both the Sage and standard Python notebook environments. I then checked htop
and found the issue: the Python notebook fully utilizes all of the threads on my CPU (all 32 of them) whereas the Sage notebook only uses a single core. This is enough to explain the massive speed difference on my machine.
Is there a way to enable the Sage notebook to give Numpy access to all of the CPU cores? I tried adjusting the SAGE_NUM_THREADS environment variable but this had no effect on the benchmark.