Search code examples
cblas

how to make scalar product with blas in c


I'm new to BLAS and I've tried reading the documentation concerning said subject. So far I'm trying to implement a simple scalar product.

double x[] = {1.0, 2.0, 3.0};
double coeff = 4.323;
int one = 1;
int n = 3;
cblas_dscal(n, coeff, x, one);
printf("pass");
for (int i = 0; i < n; i++) {
    printf("%lf" ,x[i]);
}

I used the header cblas.h. Upon compiling with the command gcc -o exec code.c -lblas I receive no errors. When I launch the executable nothing appears not even the "pass" which is problematic. Could anyone give any tips on how to save me? ;-;

ps: I'm really sorry if the question isn't well formulated this is my first question on stackoverflow so if you have any tips on how to formulate my questions better I would be grateful :)


Solution

  • When I launch the executable nothing appears not even the "pass" which is problematic.

    Use fflush(stdout) after a printf call (or use fprintf(stdout, ...) instead of printf.)

    Sometimes, programs can crash before they are able to flush the print buffer to STDOUT. Using fflush or fprintf will force a flush directly after printing, which is useful for debugging issues like this (when you don't want to use a full debugger).