Calling DDOT function in BLAS library

*爱你&永不变心* 提交于 2019-12-11 06:44:09

问题


I am calling a BLAS function in my code by including the BLAS library, and my code apparently is faulty somehow, as the compiler spits out the error: "ddot was not declared in this scope."

#include <stdio.h>
#include <stdlib.h>
#include <blas.h>

int main()
{
        double  m[10],n[10];
        int i;
        int result;

        printf("Enter the elements into first vector.\n");
        for(i=0;i<10;i++)
        scanf("%lf",&m[i]);

        printf("Enter the elements into second vector.\n");
        for(i=0;i<10;i++)
        scanf("%lf",&n[i]);

        result = ddot(m,n);
        printf("The result is %d\n",result);

        return 0;
}

Any ideas on how I can fix this code properly?


回答1:


When calling from C, the function name must either be cblas_ddot() (C calling conventions) or ddot_ (fortran calling conventions; note the trailing underscore.)

You are missing some function arguments. Try

result = cblas_ddot(10, m, 1, n, 1);

or equivalently

int len = 10, incm = 1, incn = 1;
// ...
result = ddot_(&len, m, &incm, n, &incn);

Also, ddot returns a double but you are assigning the result to an int.



来源:https://stackoverflow.com/questions/14470799/calling-ddot-function-in-blas-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!