daxpy dcopy计算

daxpy每秒计算次数:

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

#define ARRAY_LENGTH 1000000

void 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;

    int warp_count = 0;
    int max_warp = 1000;
    long int count = 0;
    time_t b_second,l_second;

    time_t rawtime;
    struct tm * timeinfo;

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

    srand((unsigned)time(NULL));

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

    while(1){

        b_second = time(NULL);
        l_second = b_second+1;

        while ((b_second=time(NULL))<l_second) {
            cblas_daxpy(n, da, dx,incx, dy, incy);  //运行daxpy程序
            count++;
        }

        time(&rawtime);
        timeinfo = localtime (&rawtime);
        printf("Time: %s ", asctime (timeinfo));
        printf("%ld\n",count);

        count=0;
        warp_count++;
        if(warp_count==max_warp){
            break;
        }
    }
}

dcopy每秒计算次数:

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

#define ARRAY_LENGTH 100000

void main() {


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

    int i;

    int warp_count = 0;
    int max_warp = 1000;
    long int count = 0;
    time_t b_second,l_second;

    time_t rawtime;
    struct tm * timeinfo;

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

    srand((unsigned)time(NULL));

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

    while(1){

        b_second = time(NULL);
        l_second = b_second+1;

        while ((b_second=time(NULL))<l_second) {
            cblas_dcopy(n, dx,incx, dy, incy);      //运行dcopy程序
            count++;
        }

        time(&rawtime);
        timeinfo = localtime (&rawtime);
        printf("Time: %s ", asctime (timeinfo));
        printf("%ld\n",count);

        count=0;
        warp_count++;
        if(warp_count==max_warp){
            break;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值