Blas Library

Example

{syntaxhighlighter brush:cpp}

#include
#include
#include "usable.h"
#include "stand.h"

static void sum(float (*firstArr)[SIZE_OF_ARR], float (*secondArr)[SIZE_OF_ARR])
{
register int i,j;
for(i=0; i for(j=0; j secondArr[i][j]+= firstArr[i][j];
return;
}
void draw_blas(float (*arr)[SIZE_OF_ARR], int iter)
{
//R = I - BA
//B = A^T/(ab)
static float R[SIZE_OF_ARR][SIZE_OF_ARR];
static float I[SIZE_OF_ARR][SIZE_OF_ARR];
static float tmp[SIZE_OF_ARR][SIZE_OF_ARR];
static float tmp2[SIZE_OF_ARR][SIZE_OF_ARR];
static float result[SIZE_OF_ARR][SIZE_OF_ARR];
int i;
float magic = 1/(max1(arr)*max2(arr));
makeI(I);
makeI(R);
makeI(result);

cblas_sgemm(
CblasRowMajor, CblasTrans, CblasNoTrans,
SIZE_OF_ARR, SIZE_OF_ARR, SIZE_OF_ARR,
-magic, &arr[0][0], SIZE_OF_ARR,
&arr[0][0], SIZE_OF_ARR, 1,
&R[0][0], SIZE_OF_ARR); //R ready!

makeI(result);
makeI(tmp);
makeI(tmp2);

for(i=1; i {
cblas_sgemm(
CblasRowMajor, CblasNoTrans, CblasNoTrans,
SIZE_OF_ARR, SIZE_OF_ARR, SIZE_OF_ARR,
1, &tmp[0][0], SIZE_OF_ARR,
&R[0][0], SIZE_OF_ARR,
0, &tmp2[0][0], SIZE_OF_ARR);

copy(tmp2, tmp);
sum(tmp,result);
}

cblas_sgemm(
CblasRowMajor, CblasNoTrans, CblasTrans,
SIZE_OF_ARR, SIZE_OF_ARR, SIZE_OF_ARR,
magic, &result[0][0], SIZE_OF_ARR,
&arr[0][0], SIZE_OF_ARR,
0, &tmp[0][0], SIZE_OF_ARR); //tmp = result*B

cblas_sgemm(
CblasRowMajor, CblasNoTrans, CblasNoTrans,
SIZE_OF_ARR, SIZE_OF_ARR, SIZE_OF_ARR,
1, &I[0][0], SIZE_OF_ARR,
&tmp[0][0], SIZE_OF_ARR,
0, &arr[0][0], SIZE_OF_ARR);
return;
}
{/syntaxhighlighter}