Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- Adding a value to all double-vector items

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Pasi_Tuomainen

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2010
12:33 AM

64 Views

Adding a value to all double-vector items

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

Then, I would like to do

AddToVectorValues(mklVector, iVectorLen, -xAxisMin);

MultiplyVectorValues(mklVector,iVectorLen,dXFactor);

AddToVectorValues(mklVector, iVectorLen, dLeft);

Now, I found

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

Link Copied

3 Replies

Gennady_F_Intel

Moderator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2010
01:04 AM

64 Views

Please see at thedaxpy routine. You can try to use them.

--Gennady

Pasi_Tuomainen

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2010
01:54 AM

64 Views

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

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2010
07:16 AM

64 Views

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 scaleI put in the calculation of the mean of dPointX to prevent the optimizer from eliminating the entire calculation.

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]

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.6You may attempt to do the equivalent in C++, or you may use the C interoperability features of Fortran 2003.

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

[/plain]

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.