- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A seemingly trivial question really.
I am trying to calculate the sum of squares or a vector of single precision values whilst maximizing performance and minimizing the accumulated error typically found in summing floats.
Currently I am using a method like the following:
---------8<---------
// Use vspowx to square the values in a vector
vspowx(n, a, 2, y);
// Sum the values in a loop
float sumOfSquares();
for ( int i(); i < n; i++ ){
sumOfSquares += y;
}
---------8<---------
Can anyone think ofa faster and/or more accurate MKL way of summing a vector of floats (in this case absolute values) without casting to doubles ?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In most cases the following example will be faster:
for ( i=0 ; i < n; i++ )
{
sumOfSquares += a*a;
}
If your compiler will not be able to vectorise this code, then the following code might be faster then the previous example (but accuracy will suffer):
sumOfSquares = snrm2(&n, a, &incx );
sumOfSquares *= sumOfSquares;
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page