Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
6565 Discussions

Adding a value to all double-vector items

Hi all,

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:

dPointX = dLeft + (dXValue - xAxisMin) * dXFactor, where dXValue is a series point X value. dLeft, xAxisMin and dXFactor are the same for all items.

By using C#,
int iVectorLen = 500000;
double[] mklVector = new double[iVectorLen];
for(int i=iVectorLen-1;i>=0;--i)
mklVector = xSeriesPoints;

Then, I would like to do
AddToVectorValues(mklVector, iVectorLen, -xAxisMin);
AddToVectorValues(mklVector, iVectorLen, dLeft);

Now, I found dscalfunction, 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.

ByimplementingAddToVectorValues with a for-loop, it will take about ten times more CPU time than a dscal function call.

Any suggestions?

Best regards,
Pasi Tuomainen
0 Kudos
3 Replies
Please see at thedaxpy routine. You can try to use them.

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?

Best regards,
Black Belt
Please take a look at the IPP Library function ippiScale.

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
[fortran]program scale
integer, parameter :: iVLen = 5000000
real, dimension (iVLen) :: dXValue, dPointX
real,volatile :: t0,t1,s

call random_number(dXValue)

call cpu_time(t0)
dPointX = 273.15 + 100.0*dXValue ! linear transformation
call cpu_time(t1)


end program scale
I put in the calculation of the mean of dPointX to prevent the optimizer from eliminating the entire calculation.

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.
[plain]..B1.7:                         # Preds ..B1.7 ..B1.6
movaps scale_$DXVALUE.0.1(,%rax,4), %xmm2 #8.1
movaps 16+scale_$DXVALUE.0.1(,%rax,4), %xmm3 #8.1
mulps %xmm1, %xmm2 #8.25
addps %xmm0, %xmm2 #8.1
movaps %xmm2, scale_$DPOINTX.0.1(,%rax,4) #8.1
mulps %xmm1, %xmm3 #8.25
addps %xmm0, %xmm3 #8.1
movaps %xmm3, 16+scale_$DPOINTX.0.1(,%rax,4) #8.1
addq $8, %rax #8.1
cmpq $500000, %rax #8.1
jb ..B1.7 # Prob 99% #8.1
You may attempt to do the equivalent in C++, or you may use the C interoperability features of Fortran 2003.