Created
May 6, 2015 20:26
-
-
Save xianyi/65aef3c2e5bc32049806 to your computer and use it in GitHub Desktop.
performance test for dgemv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
//#define ITERS 1000000 | |
void dgemv_(char *, int*, int *, double*, double*, int*, double*, int*, double*, double*, int*); | |
int main(int argc, char * argv[]) | |
{ | |
int m, n; | |
double alpha=1.1; | |
double beta=1.0; | |
double * a, *x, *y; | |
int inc=1; | |
int i; | |
int iters; | |
char trans='N'; | |
struct timeval start,finish; | |
double duration; | |
if(argc<4){printf("input error\n"); return 0;} | |
m=atoi(argv[1]); | |
n=atoi(argv[2]); | |
iters=atoi(argv[3]); | |
a=(double*)malloc(m*n*sizeof(double)); | |
x=(double*)malloc(n*sizeof(double)); | |
y=(double*)malloc(m*sizeof(double)); | |
for(i=0; i<m*n; i++){ | |
a[i]=1.1; | |
} | |
for(i=0; i<n; i++){ | |
x[i]=1.0; | |
} | |
for(i=0; i<m; i++){ | |
y[i]=1.0; | |
} | |
gettimeofday(&start, NULL); | |
for(i=0; i<iters;i++){ | |
dgemv_(&trans, &m, &n, &alpha, a, &m, x, &inc, &beta, y, &inc); | |
} | |
gettimeofday(&finish, NULL); | |
duration = ((double)(finish.tv_sec-start.tv_sec)*1000000 + (double)(finish.tv_usec-start.tv_usec)) / 1000000; | |
double gflops = 2.0 * m *n*iters; | |
gflops = gflops/duration*1.0e-6; | |
printf("%dx%d\t%d loops\t%lf s\t%lf MGFLOPS\n",m, n, iters, duration, gflops); | |
free(a); | |
free(x); | |
free(y); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I follow this https://gist.github.com/xianyi/65aef3c2e5bc32049806 to come here.
I don't know how could get higher performance than 6.9 GFLOPS.
My CPU is i7-4790 and I tested dgemv with m=6400, n=64 but the highest performance was only 6.9GFLOPS when using 4 or 8 threads.