blas daxpy dcopy函数的使用

关于blas和cblas的安装见CBLAS的安装使用

daxpy函数的作用是将一个向量加上另一个向量的值,即:dy[i]=da*dx[i],其中da为常数,
函数的完整声明可以在cblas.h中看到,如下:
void cblas_daxpy(const int N, const double alpha, const double *X, const int incX, double *Y, const int incY);

各个参数含义为:

    int n;                           // array size 
    double da;                      // double constant 
    double *dx;                     // input double array 
    int incx;                        // input stride 
    double *dy;                      // output double array 
    int incy;                       // output stride 

dcopy函数的作为将一个向量赋值给另一个向量即:dy[i]=dx[i];函数的声明跟daxpy一致,只是少了常量da。

下面一个程序是这两个函数的一个举例:

#include <stdio.h>
#include <stdlib.h>
#include "cblas.h"

int main(){

        int n;                          /*! array size */
        double da;                      /*! double constant */
        double *dx;                     /*! input double array */
        int incx;                        /*! input stride */
        double *dy;                      /*! output double array */
        int incy;                       /*! output stride */

        int i;

        n = 10;
        da = 10;
        dx = (double*)malloc(sizeof(double)*n);
        incx = 1;
        dy = (double*)malloc(sizeof(double)*n);
        incy = 1;

        for(i=0;i<n;i++){
                dx[i] = 9-i;
                dy[i] = i;
                printf("%f ",dy[i]);    //输出原来的dy
        }
        printf("\n");

        cblas_daxpy(n, da, dx,incx, dy, incy);  //运行daxpy程序
    //    cblas_dcopy(n, dx,incx, dy, incy);      //运行dcopy程序

        for(i=0;i<n;i++){
            printf("%f ",dy[i]);   //输出计算后的dy
        }
        printf("\n");

        return 0;   
}  

参考:
http://www.netlib.org/blas/
http://www.netlib.org/blas/cblas.h
http://www.noao.edu/staff/mighell/mx/mx/src/sbin/mxsl_na/docs/html/daxpy_8c-source.html

注:
The benchmarks allowed us to vary the size of the vector used during execution, the number of iterations, and allowed us to control the throughput by sleeping between iterations.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值