- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is there a betterway to add a value to all elements in a vector than this:
cblas_saxpy(arrSize, &m_anyvalue, m_pU, 1, m_pX, 1 );
where
m_pU = a vector of ones
m_pX = the vector I want to add m_anyvalue to
Thanks
Link Copied
13 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
cblas_saxpydoesn't lookright routine to use. My recommendation will be:
vsLinearFrac( n, a, b, scalea, shifta, scaleb, shiftb, y )
Description
The v?LinearFrac function performs linear fraction transformation of vectors a by vector b with scalar parameters: scaling multipliers scalea, scaleb and shifting addends shifta, shiftb:
y=(scaleaa+shifta)/(scalebb+shiftb), i=1,2 n
Just set scalea=1.0f, scaleb=0.0f, shiftb=1.0f
I hope that helps,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! I'll try that instead!
Is the function smart enough to avoid performing the unnecessary computations?
Is the function smart enough to avoid performing the unnecessary computations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello again,
Yes, the function should be able to effectively handlesuch subtle cases. Let me know if it works fine.
With one more note. y=x+scale stresses the ADD unit only. It means in particular that, for example, MUL unit is iddle while performaing vector ADD. (Please remember all modern Intel CPUs can issue add and mul operations simultaneously). If you use Intel C++ compiler (which has quite good vectorizer) you might get better overall performance if you can mix this computation (y=x+scale) with other stuff so that all CPU compute units are busy.
Regards,
Sergey
Yes, the function should be able to effectively handlesuch subtle cases. Let me know if it works fine.
With one more note. y=x+scale stresses the ADD unit only. It means in particular that, for example, MUL unit is iddle while performaing vector ADD. (Please remember all modern Intel CPUs can issue add and mul operations simultaneously). If you use Intel C++ compiler (which has quite good vectorizer) you might get better overall performance if you can mix this computation (y=x+scale) with other stuff so that all CPU compute units are busy.
Regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh no, it seems there is no overload for complex input...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Correct. Only real single and double precision variant for v?LinearFrac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So you may be better off using your compiler (such as Intel or recent gcc).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How? (I am not really a programmer so it is not obvious to me) Do you mean I should just write a for loop and trust the compiler to optimize it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How? (I am not really a programmer so it is not obvious to me)
In that case, you may want to use mathematical reasoning to see if you can avoid a redundant calculation altogether.
For example, if z is a complex-valued n-vector, and the desired result is, say, w = z = u + i v, and you wish to add the real number c to the real parts of the components of z, you can compute w1 = (u + n c) + i v as the modified result.
In that case, you may want to use mathematical reasoning to see if you can avoid a redundant calculation altogether.
For example, if z is a complex-valued n-vector, and the desired result is, say, w = z = u + i v, and you wish to add the real number c to the real parts of the components of z, you can compute w1 = (u + n c) + i v as the modified result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure, but how do I optimize it? The re/im parts of the complex numbers are interleaved in the array. I cant use the functions mentioned above and writing a for-loop with a step increment of 2 doesn't seem so tempting.
Wouldn't it be nice to add a function to VML that does addition with a constant?
Wouldn't it be nice to add a function to VML that does addition with a constant?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't think that you understood the thrust of my remarks. There is nothing to optimize in a calculation that is not even performed!
So far, you have stated that you want a routine to add a constant to a vector, and you did not like the ones that were suggested.
If you state details of how the added constant plays a role in subsequent calculations, further suggestions may become possible.
So far, you have stated that you want a routine to add a constant to a vector, and you did not like the ones that were suggested.
If you state details of how the added constant plays a role in subsequent calculations, further suggestions may become possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Exactly.
for (i=0; i {
x += c;
}
Intel C++ compiler should nicely vectorize the loop
Thanks,
Sergey
for (i=0; i
x += c;
}
Intel C++ compiler should nicely vectorize the loop
Thanks,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4:
Yup, nothing like a calculation that never needs to be done:) I don't have any particular problem, but I can imagine that in some cases one can get away with an initialization to a contant instead of an addition. Example:
a = zeros
a = a + b*c
a = a + d
can be changed to
a = d
a = a + b*c
Is there something like a "vector-memset" in MKL?
Yup, nothing like a calculation that never needs to be done:) I don't have any particular problem, but I can imagine that in some cases one can get away with an initialization to a contant instead of an addition. Example:
a = zeros
a = a + b*c
a = a + d
can be changed to
a = d
a = a + b*c
Is there something like a "vector-memset" in MKL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah - nice! Thanks Sergey!
Reply
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