[Numpy-discussion] Adopt Mersenne Twister 64bit?

2013-03-10 Thread Siu Kwan Lam
Hi all,

I am redirecting a discussion on github issue tracker here.  My original post 
(https://github.com/numpy/numpy/issues/3137):

The current implementation of the RNG seems to be MT19937-32. Since 64-bit 
machines are common nowadays, I am suggesting adding or upgrading to 
MT19937-64.  Thoughts?

Let me start by answering to njsmith's comments on the issue tracker:

 Would it be faster?

Although I have not benchmarked the 64-bit implementation, it is likely that it 
will be faster on a 64-bit machine since the number of iteration (controlled by 
NN and MM in the reference implementation 
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c) 
is reduced by half.  In addition, each generation in the 64-bit implementation 
produces a 64-bit random int which can be used to generate double precision 
random number.  Unlike the 32-bit implementation which requires generating a 
pair of 32-bit random int.

But, on a 32-bit machine, a 64-bit instruction is translated into 4 32-bit 
instructions; thus, it is likely to be slower.  (1)

 Use less memory?

The amount of memory use will remain the same.  The size of the RNG state is 
the same.

 Provide higher quality randomness?


My naive answer is that 32-bit and 64-bit implementation have the same 
2^19937-1 period.  Need to do some research and experiments.

 Would it change the output of this program:
   import numpy
   numpy.random.seed(0)
   print numpy.random.random()
 ?

Unfortunately, yes.  The 64-bit implementation generates a different random 
number sequence with the same seed. (2)


My suggestion to overcome (1) and (2) is to allow the user to select between 
the two implementations (and possibly different algorithms in the future).  If 
user does not provide a choice, we use the MT19937-32 by default.

numpy.random.set_state(MT19937_64, …)   # choose the 64-bit 
implementation

Thoughts?

Best,
Siu 

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Numpy 1.7.0 with Intel MKL 11.0.2.146

2013-03-10 Thread QT
Dear all,

I'm at my wits end.  I've followed Intel's own
instructionshttp://software.intel.com/en-us/articles/numpyscipy-with-intel-mklon
how to compile Numpy with Intel MKL.  Everything compiled and linked
fine and I've installed it locally in my user folder...There is one nasty
problem.  When one calls the numpy library to do some computation, it does
not use all of the available threads.  I have 8 cores on my machine and
it only uses 4 of them.  The MKL_NUM_THREADS environmental variable can be
set to tune the number of threads but setting it to 8 does not change
anything.  Indeed, setting it to 3 does limit the threads to 3What is
going on?

As a comparison, the numpy (version 1.4.1, installed from yum, which uses
BLAS+ATLAS) uses all 8 threads.  I do not get this.

You can run this test program

python -mtimeit -s'import numpy as np; a = np.random.randn(1e3,1e3)'
'np.dot(a, a)'

There is one saving grace, the local numpy built with MKL is much faster
than the system's numpy.

I hope someone can help me.  Searching the internet has been fruitless.

Best,
Quyen

My site.cfg for numpy (1.7.0)
[mkl]
library_dirs = /opt/intel/mkl/lib/intel64
include_dirs = /opt/intel/mkl/include
mkl_libs = mkl_rt
lapack_libs =

I've edited line 37 of numpy/distutils/intelcompiler.py
self.cc_exe = 'icc -O3 -fPIC -fp-model strict -fomit-frame-pointer -openmp
-parallel -DMKL_ILP64'

Also line 54 of numpy/distutils/fcompiler/intel.py
return ['-i8 -xhost -openmp -fp-model strict']

My .bash_profile also contains the lines:
source /opt/intel/bin/compilervars.sh intel64
source /opt/intel/mkl/bin/mklvars.sh intel64

The above is needed to set the LD_LIBRARY_PATH so that Python can source
the intel dynamic library when numpy is called.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Numpy 1.7.0 with Intel MKL 11.0.2.146

2013-03-10 Thread Warren Weckesser
On 3/10/13, QT rdirect...@gmail.com wrote:
 Dear all,

 I'm at my wits end.  I've followed Intel's own
 instructionshttp://software.intel.com/en-us/articles/numpyscipy-with-intel-mklon
 how to compile Numpy with Intel MKL.  Everything compiled and linked
 fine and I've installed it locally in my user folder...There is one nasty
 problem.  When one calls the numpy library to do some computation, it does
 not use all of the available threads.  I have 8 cores on my machine and
 it only uses 4 of them.  The MKL_NUM_THREADS environmental variable can be
 set to tune the number of threads but setting it to 8 does not change
 anything.  Indeed, setting it to 3 does limit the threads to 3What is
 going on?


Does your computer have 8 physical cores, or 4 cores that look like 8
because of hyperthreading?

Warren



 As a comparison, the numpy (version 1.4.1, installed from yum, which uses
 BLAS+ATLAS) uses all 8 threads.  I do not get this.

 You can run this test program

 python -mtimeit -s'import numpy as np; a = np.random.randn(1e3,1e3)'
 'np.dot(a, a)'

 There is one saving grace, the local numpy built with MKL is much faster
 than the system's numpy.

 I hope someone can help me.  Searching the internet has been fruitless.

 Best,
 Quyen

 My site.cfg for numpy (1.7.0)
 [mkl]
 library_dirs = /opt/intel/mkl/lib/intel64
 include_dirs = /opt/intel/mkl/include
 mkl_libs = mkl_rt
 lapack_libs =

 I've edited line 37 of numpy/distutils/intelcompiler.py
 self.cc_exe = 'icc -O3 -fPIC -fp-model strict -fomit-frame-pointer -openmp
 -parallel -DMKL_ILP64'

 Also line 54 of numpy/distutils/fcompiler/intel.py
 return ['-i8 -xhost -openmp -fp-model strict']

 My .bash_profile also contains the lines:
 source /opt/intel/bin/compilervars.sh intel64
 source /opt/intel/mkl/bin/mklvars.sh intel64

 The above is needed to set the LD_LIBRARY_PATH so that Python can source
 the intel dynamic library when numpy is called.

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Numpy 1.7.0 with Intel MKL 11.0.2.146

2013-03-10 Thread Warren Weckesser
On 3/10/13, Warren Weckesser warren.weckes...@gmail.com wrote:
 On 3/10/13, QT rdirect...@gmail.com wrote:
 Dear all,

 I'm at my wits end.  I've followed Intel's own
 instructionshttp://software.intel.com/en-us/articles/numpyscipy-with-intel-mklon
 how to compile Numpy with Intel MKL.  Everything compiled and linked
 fine and I've installed it locally in my user folder...There is one nasty
 problem.  When one calls the numpy library to do some computation, it
 does
 not use all of the available threads.  I have 8 cores on my machine and
 it only uses 4 of them.  The MKL_NUM_THREADS environmental variable can
 be
 set to tune the number of threads but setting it to 8 does not change
 anything.  Indeed, setting it to 3 does limit the threads to 3What is
 going on?


 Does your computer have 8 physical cores, or 4 cores that look like 8
 because of hyperthreading?



Here's why I ask this: http://software.intel.com/en-us/forums/topic/294954


 Warren



 As a comparison, the numpy (version 1.4.1, installed from yum, which uses
 BLAS+ATLAS) uses all 8 threads.  I do not get this.

 You can run this test program

 python -mtimeit -s'import numpy as np; a = np.random.randn(1e3,1e3)'
 'np.dot(a, a)'

 There is one saving grace, the local numpy built with MKL is much faster
 than the system's numpy.

 I hope someone can help me.  Searching the internet has been fruitless.

 Best,
 Quyen

 My site.cfg for numpy (1.7.0)
 [mkl]
 library_dirs = /opt/intel/mkl/lib/intel64
 include_dirs = /opt/intel/mkl/include
 mkl_libs = mkl_rt
 lapack_libs =

 I've edited line 37 of numpy/distutils/intelcompiler.py
 self.cc_exe = 'icc -O3 -fPIC -fp-model strict -fomit-frame-pointer
 -openmp
 -parallel -DMKL_ILP64'

 Also line 54 of numpy/distutils/fcompiler/intel.py
 return ['-i8 -xhost -openmp -fp-model strict']

 My .bash_profile also contains the lines:
 source /opt/intel/bin/compilervars.sh intel64
 source /opt/intel/mkl/bin/mklvars.sh intel64

 The above is needed to set the LD_LIBRARY_PATH so that Python can source
 the intel dynamic library when numpy is called.


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Numpy 1.7.0 with Intel MKL 11.0.2.146

2013-03-10 Thread QT
Dear Warren,

It's an Intel i7 950, 4 cores, 8 with hyper-threading.

I used MKL 11.0.2.146, but I will read your link.  It seems spot on.

Best,
Quyen

On Sun, Mar 10, 2013 at 10:31 PM, Warren Weckesser 
warren.weckes...@gmail.com wrote:

 On 3/10/13, Warren Weckesser warren.weckes...@gmail.com wrote:
  On 3/10/13, QT rdirect...@gmail.com wrote:
  Dear all,
 
  I'm at my wits end.  I've followed Intel's own
  instructions
 http://software.intel.com/en-us/articles/numpyscipy-with-intel-mklon
  how to compile Numpy with Intel MKL.  Everything compiled and linked
  fine and I've installed it locally in my user folder...There is one
 nasty
  problem.  When one calls the numpy library to do some computation, it
  does
  not use all of the available threads.  I have 8 cores on my machine
 and
  it only uses 4 of them.  The MKL_NUM_THREADS environmental variable can
  be
  set to tune the number of threads but setting it to 8 does not change
  anything.  Indeed, setting it to 3 does limit the threads to 3What
 is
  going on?
 
 
  Does your computer have 8 physical cores, or 4 cores that look like 8
  because of hyperthreading?
 


 Here's why I ask this: http://software.intel.com/en-us/forums/topic/294954


  Warren
 
 
 
  As a comparison, the numpy (version 1.4.1, installed from yum, which
 uses
  BLAS+ATLAS) uses all 8 threads.  I do not get this.
 
  You can run this test program
 
  python -mtimeit -s'import numpy as np; a = np.random.randn(1e3,1e3)'
  'np.dot(a, a)'
 
  There is one saving grace, the local numpy built with MKL is much faster
  than the system's numpy.
 
  I hope someone can help me.  Searching the internet has been fruitless.
 
  Best,
  Quyen
 
  My site.cfg for numpy (1.7.0)
  [mkl]
  library_dirs = /opt/intel/mkl/lib/intel64
  include_dirs = /opt/intel/mkl/include
  mkl_libs = mkl_rt
  lapack_libs =
 
  I've edited line 37 of numpy/distutils/intelcompiler.py
  self.cc_exe = 'icc -O3 -fPIC -fp-model strict -fomit-frame-pointer
  -openmp
  -parallel -DMKL_ILP64'
 
  Also line 54 of numpy/distutils/fcompiler/intel.py
  return ['-i8 -xhost -openmp -fp-model strict']
 
  My .bash_profile also contains the lines:
  source /opt/intel/bin/compilervars.sh intel64
  source /opt/intel/mkl/bin/mklvars.sh intel64
 
  The above is needed to set the LD_LIBRARY_PATH so that Python can source
  the intel dynamic library when numpy is called.
 
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion