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

Hello,

I am trying to get the sum of a vector using MKL's cblas_dasum function in C using Intel C++ compiler but the negative numbers are not subtracted. I would expect 40.0 + 2.0 - 42.0 == 0.0 but I am getting 40.0 + 2.0 - 42.0 == 84.0. Here is the code:

/* compiled with icc -mkl blastest.c -o blastest */ #include <stdio.h> #include <stdlib.h> #include "mkl.h" #define N 3 int main() { double *v; v = (double *) mkl_malloc(N * sizeof( double ), 64); v[0] = (double) 40.0; v[1] = (double) 2.0; v[2] = (double) -42.0; printf("Sum = %lf\n", cblas_dasum(N, v, 1)); return 0; }

Can anybody tell me what's wrong in the code as I am getting 84.0 as the answer.

Thanks,

Auvi

Link Copied

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

Please read the manual page containing the specification of ?asum. The routines sasum, dasum return the sum of the **absolute **values of the input vector array elements. The casum and zasum routines return the sum of the **absolute **values of the real plus the **absolute **values of the imaginary parts of the input vector array elements.

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

Thanks for opening my eyes! This was an oversight on my part as I did download the documentation and tried to quickly locate a "sum" function. I don't see just a "dsum" function though that will work for my purpose. What is the best way to achieve this? A dot product of two vectors where one of them is just "1"s? summing up vectors is something I do all the time in other environments (numpy, MATLAB) and I'm looking for a straightforward way to achieve that in MKL.

Thanks in advance,

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

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

Auvi,

mkl doesn't provide such functionality. In the case if this is "hot spot" into your application - you can use Tim's suggestion to use Cilk Plus option or try to use another performance libraries 0 Intel(R) IPP which provides computing the sum of the elements of vectors: ippsSum_32f and etc... . In the case if this is not "hot spot" -- the plain code compiled by Intel Compiler would give you good results from performance point of view.

--Gennady

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

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

Thanks everyone for the comments. For the time being I'm keeping a vector called ones with sufficiently large number of 1.0's and using it with cblas_ddot whenever I need to sum. As the ones vector is created only once, I am okay with it.

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