サンプルプログラム

密行列積を求めるためのサンプルプログラム( test/ABCLibTestBLAS.c )は、以下のとおりです。MATRIXSIZEを変更することで計算する行列の次元を変更することができます。

/******************************************/
/* */
/* Posix Pthread version */
/* Recursive BLAS Matrix Mutmal */
/* */
/* Yasuo Kinoshita */
/* */
/******************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>

#define MATRIXSIZE 4000

int main(int argc、char **argv)
{
int M, N, K;
double *C, *A, *B;
char TransA='n', TransB='n';
double a=1.0, b=0.0;
int lda, ldb, ldc;
int i, j, x;
struct timeval t1, t2;
double soltime, sec, usec;

 time_t seed;
 time(&seed);
 srand(seed);
 M=MATRIXSIZE;
 N=M;
 K=M;
 lda = K;
 ldb = N;
 ldc = M;

 printf("MatrixC:%d*%d ", M, N);
 printf("MatrixA:%d*%d ", M, K);
 printf("MatrixB:%d*%d\n", K, N);

 C = (double *)malloc(sizeof(double)*(M*N));
 A = (double *)malloc(sizeof(double)*(M*K));
 B = (double *)malloc(sizeof(double)*(K*N));

 x=10;

 for(i=0 ;i<M ;i++ ){
  for(j=0 ;j<N ;j++ ){
   *(C+j+i*N) = 0.0;
  }
 }

 for(i=0 ;i<M ;i++ ){
  for(j=0 ;j<K ;j++ ){
   *(A+j+i*K) =(double)(rand()%x);
  }
 }

 for(i=0 ;i<K ;i++ ){
  for(j=0 ;j<N ;j++ ){
   *(B+j+i*N) =(double)(rand()%x);
  }
 }

 gettimeofday(&t1, NULL);
 RB_DGEMM(TransA, TransB, M, N, K, a, A, lda, B, ldb, b, C, ldc);
 gettimeofday(&t2, NULL);

 sec = t2.tv_sec - t1.tv_sec;
 usec = t2.tv_usec - t1.tv_usec;
 soltime = (sec + usec/1000000.0);
 printf("Solve time = %0.3lf\n", soltime);
 printf(" flops = %0.3lf\n", 2*M*M*(M/soltime)/1000000);

 free(C);
 free(A);
 free(B);


 return 0;

}
#####################################################################