-2

I'm trying to generate dot product of two matrices using the below compiling command in Linux-GCC:

gcc -L/usr/lib64/atlas -lblas code.c

and here is the code which seems to have compiled without an error:

#include < stdio.h>    

int main()
{
  int n,incx,incy;
  int x[] = {1,2,3};
  int y[] = {2,3,4};
  int z;
  incx =1;
  incy =1;
  n = 3;
  z = sdot_(&n, x, &incx, y, &incy);
  printf("%d", z);
  printf("\n");
  return 0;
}

So I expect to see 1*2 + 2*3 + 3*4 = 20, however when I run the binary the result "3" is printed.

Any ideas?

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114

1 Answers1

5

You use wrong types and implicit declaration of sdot_. You should add the function prototype (or include a header) and use the right types.

#include <stdio.h>    

float sdot_(int* n, float* x, int* incx, float* y, int* incy);

int main()
{
  int n,incx,incy;
  float x[] = {1.f,2.f,3.f};
  float y[] = {2.f,3.f,4.f};
  float z;
  incx =1;
  incy =1;
  n = 3;
  z = sdot_(&n, x, &incx, y, &incy);
  printf("%f", z);
  printf("\n");
  return 0;
}

If you enable warnings, you will get them from your compiler for your version of the code:

cc sdot.c -lblas -Wall
sdot.c: In function ‘main’:
sdot.c:14:3: warning: implicit declaration of function ‘sdot_’ [-Wimplicit-function-declaration]