Dense matrix operation using multiple cores
Code: "multi_DenseDoubleMatrix2D.py". Programming language: Python DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/multi_DenseDoubleMatrix2D_6759.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


# In Parallel Colt threads are used automatically when computations are done on a
# machine with multiple CPUs. 
# Here are some benchmarks of DenseDoubleMatrix2Di done by Piotr Wendykier piotr.wendykier@gmail.com
# http://sites.google.com/site/piotrwendykier/files/BenchmarkDenseDoubleMatrix2D.txt
# This example is written by S.Chekanov

###################### benchmarking multi-threaded colt ##############
from cern.colt.matrix        import *
from edu.emory.mathcs.utils  import ConcurrencyUtils
import time

# do some calculations on DenseDoubleMatrix2D
def process(M):
       M.cardinality()
       M.dctColumns(0)
       M.dctRows(0)
       M.dct2(0)  
       M.dht2()
       M.dhtColumns()
       M.dhtRows() 
       M.dst2(0)
       M.dstColumns(0)
       M.dstRows(0)
       M.vectorize()
       M.zSum()
       M.idct2(0)


################### two threads ###################################
Ncores=2
print " benchmarks of DenseDoubleMatrix2D for "+str(Ncores)+"  CPU core. Wait!"
ConcurrencyUtils.setNumberOfThreads(Ncores)
start = time.clock()
M=tdouble.DoubleFactory2D.dense.random(2000, 2000) # random matrix
process(M)
print ' Multiple CPU time (s)=',time.clock()-start


####################### single core #################################
Ncores=1
print " benchmarks of DenseDoubleMatrix2D for "+str(Ncores)+"  CPU core. wait!"
ConcurrencyUtils.setNumberOfThreads(Ncores)
start = time.clock()
M=tdouble.DoubleFactory2D.dense.random(2000, 2000) # random matrix
process(M)
print ' Multiple CPU time (s)=',time.clock()-start

You see the box below because you did not login.