topic Adding a value to all double-vector items in IntelĀ® oneAPI Math Kernel Library
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832878#M5774
Thanks, <BR /><BR />however, this doesn't seem to give any performance gain. I have to create a separate vector for dLeft values, and initialize it with dLeft valueswith a for loop... Or do you know a MKL routine for initializing a vector with same double-value for each item? <BR /><BR />Best regards,<BR />PasiMon, 30 Aug 2010 08:54:26 GMTPasi_Tuomainen2010-08-30T08:54:26ZAdding a value to all double-vector items
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832876#M5772
Hi all, <BR /><BR />I'd like to convert hundreds ofmillions of data points as coordinates on screen, so I'll need to optimize the calculation. The formula is simple, for X coordinate transform:<BR /><BR />dPointX = dLeft + (dXValue - xAxisMin) * dXFactor, where dXValue is a series point X value. dLeft, xAxisMin and dXFactor are the same for all items. <BR /><BR />By using C#, <BR />int iVectorLen = 500000; <BR />double[] mklVector = new double[iVectorLen]; <BR />for(int i=iVectorLen-1;i>=0;--i)<BR /> mklVector<I> = xSeriesPoints<I>;<BR /><BR /><BR />Then, I would like to do <BR />AddToVectorValues(mklVector, iVectorLen, -xAxisMin);<BR />MultiplyVectorValues(mklVector,iVectorLen,dXFactor); <BR />AddToVectorValues(mklVector, iVectorLen, dLeft);<BR /><BR />Now, I found <STRONG>dscal</STRONG>function, which works for MultiplyVectorValues purposejust fine. But, is there any function toapply the sum operation, for AddToVectorValues purpose? I really couldn't find one, and neither my more MKL-experienced associate. <BR /><BR />ByimplementingAddToVectorValues with a for-loop, it will take about ten times more CPU time than a dscal function call. <BR /><BR />Any suggestions? <BR /><BR />Best regards,<BR />Pasi Tuomainen</I></I>Mon, 30 Aug 2010 07:33:36 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832876#M5772Pasi_Tuomainen2010-08-30T07:33:36ZAdding a value to all double-vector items
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832877#M5773
Please see at thedaxpy routine. You can try to use them.<DIV>--Gennady</DIV>Mon, 30 Aug 2010 08:04:29 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832877#M5773Gennady_F_Intel2010-08-30T08:04:29ZAdding a value to all double-vector items
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832878#M5774
Thanks, <BR /><BR />however, this doesn't seem to give any performance gain. I have to create a separate vector for dLeft values, and initialize it with dLeft valueswith a for loop... Or do you know a MKL routine for initializing a vector with same double-value for each item? <BR /><BR />Best regards,<BR />PasiMon, 30 Aug 2010 08:54:26 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832878#M5774Pasi_Tuomainen2010-08-30T08:54:26ZAdding a value to all double-vector items
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832879#M5775
Please take a look at the IPP Library function ippiScale.<BR /><BR />For something so simple as performing a linear transformation, there is no need to call functions. In fact, the calculation that you described (or, taking for example the generation of a set of temperatures in Kelvin between the freezing and boiling points of water) can be performed in Fortran with the code<BR /><PRE>[fortran]program scale<BR />integer, parameter :: iVLen = 5000000<BR />real, dimension (iVLen) :: dXValue, dPointX<BR />real,volatile :: t0,t1,s<BR /><BR />call random_number(dXValue)<BR /><BR />call cpu_time(t0)<BR />dPointX = 273.15 + 100.0*dXValue ! linear transformation<BR />call cpu_time(t1)<BR /><BR />s=sum(dPointX)/size(dPointX)<BR />write(*,*)t1-t0,s<BR /><BR />end program scale<BR />[/fortran]</PRE> I put in the calculation of the mean of dPointX to prevent the optimizer from eliminating the entire calculation.<BR /><BR />An optimizing compiler can perform the core operation inline and with great efficiency. With the -xSSSE3 -O3 options, the Intel Fortran compiler converts the linear transformation into a loop with iVLen/8 repetitions, with each iteration of the loop producing 8 elements of the array.<PRE>[plain]..B1.7: # Preds ..B1.7 ..B1.6<BR /> movaps scale_$DXVALUE.0.1(,%rax,4), %xmm2 #8.1<BR /> movaps 16+scale_$DXVALUE.0.1(,%rax,4), %xmm3 #8.1<BR /> mulps %xmm1, %xmm2 #8.25<BR /> addps %xmm0, %xmm2 #8.1<BR /> movaps %xmm2, scale_$DPOINTX.0.1(,%rax,4) #8.1<BR /> mulps %xmm1, %xmm3 #8.25<BR /> addps %xmm0, %xmm3 #8.1<BR /> movaps %xmm3, 16+scale_$DPOINTX.0.1(,%rax,4) #8.1<BR /> addq $8, %rax #8.1<BR /> cmpq $500000, %rax #8.1<BR /> jb ..B1.7 # Prob 99% #8.1<BR />[/plain]</PRE> You may attempt to do the equivalent in C++, or you may use the C interoperability features of Fortran 2003.Mon, 30 Aug 2010 14:16:54 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Adding-a-value-to-all-double-vector-items/m-p/832879#M5775mecej42010-08-30T14:16:54Z