# Comparison of MatrixOP and Multithread

Hi,

I have tested a wave assignment of a 1000x1000 2D wave using MatrixOP and Multithread, respectively.

Both operations required similar process time. ~0.13 sec.

I got a bit confused by this result. Is there any difference between these two operations in wave assignment?

Hello Maru,

The only similarity of the two approaches is that you end up with a large output wave...

You are not telling us how you measured the performance time so please include your code.

A multithread assignment splits the execution of the assignment (which you have not actually specified) into as many threads as can be supported by your hardware.  MatrixOP wave assignment (I am assuming you used const()) is not multithreaded but it runs efficiently in one thread.  Depending on the size of the wave performance may be limited by the time it takes to allocate the wave.

A.G.

Igor wrote:

Hello Maru,

The only similarity of the two approaches is that you end up with a large output wave...

You are not telling us how you measured the performance time so please include your code.

A multithread assignment splits the execution of the assignment (which you have not actually specified) into as many threads as can be supported by your hardware.  MatrixOP wave assignment (I am assuming you used const()) is not multithreaded but it runs efficiently in one thread.  Depending on the size of the wave performance may be limited by the time it takes to allocate the wave.

A.G.

Thanks! Now, I understand. My code was very complicated and I extracted a part of that. The process time is a bit different now.

For Multithread, it takes ~0.030 sec. For MatrixOP, it takes   ~0.017  sec.

Function test()

Make/O/D/N=(1000,1000,3) vecMap
Make/O/D/N=(1000,1000) scalarMap
Make/O/N=3, avec, bvec, cvec
avec = {1,0,0}
bvec = {0,1,0}
cvec = {0,0,1}

Multithread vecMap = (p-500)*avec[r] + (q-500)*bvec[r] + 1e-3*cvec[r]

variable t0 = StartMSTimer
Multithread scalarMap = sqrt(vecMap[p][q][0]*vecMap[p][q][0] + vecMap[p][q][1]*vecMap[p][q][1] + vecMap[p][q][2]*vecMap[p][q][2])
Print StopMSTimer(t0)*1e-6, "sec"

variable t1 = StartMSTimer
MatrixOP/O scalarMap1 = sqrt(vecMap[][][0]*vecMap[][][0] + vecMap[][][1]*vecMap[][][1] + vecMap[][][2]*vecMap[][][2])
Print StopMSTimer(t1)*1e-6, "sec"

End

FWIW: in IP9 the following should be more efficient:

FASTOP vecMap=vecMap*vecMap
MatrixOP/O scalarMap1 = sqrt(sumBeams(vecMap))