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
- cblas_dasum is not adding up negative numbers

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

Auvi_R_

Beginner

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

04-27-2014
09:31 AM

134 Views

cblas_dasum is not adding up negative numbers

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

6 Replies

mecej4

Black Belt

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

04-27-2014
10:49 AM

134 Views

**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.

Auvi_R_

Beginner

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

04-27-2014
01:12 PM

134 Views

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,

TimP

Black Belt

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

04-27-2014
02:56 PM

134 Views

Gennady_F_Intel

Moderator

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

04-28-2014
03:16 AM

134 Views

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

TimP

Black Belt

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

04-28-2014
03:33 AM

134 Views

Auvi_R_

Beginner

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

04-28-2014
09:34 AM

134 Views

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.