# 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
Ads help maintain this website.