Community
cancel
Showing results for
Did you mean:
Beginner
78 Views

## 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
MultiplyVectorValues(mklVector,iVectorLen,dXFactor);

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
3 Replies
Moderator
78 Views
Please see at thedaxpy routine. You can try to use them.
Beginner
78 Views
Thanks,

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,
Pasi
Black Belt
78 Views
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)

s=sum(dPointX)/size(dPointX)
write(*,*)t1-t0,s

end program scale
[/fortran]
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