daxpy dcopy计算

来源:互联网 发布:首字母大写php 编辑:程序博客网 时间:2024/05/16 04:35

daxpy每秒计算次数:

#include <stdio.h>#include <stdlib.h>#include <time.h>#include "cblas.h"#define ARRAY_LENGTH 1000000void 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 100000void 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
原创粉丝点击