Open-Source Internship opportunity by OpenGenus for programmers. Apply now.
Reading time: 20 minutes
FLAME BLIS is an open source portable software framework/ Basic Linear Algebra Subprograms (BLAS) library for instantiating high-performance BLAS-like dense linear algebra libraries.
The framework was designed to isolate essential kernels of computation that, when optimized, immediately enable optimized implementations of most of its commonly used and computationally intensive operations. BLIS is written in ISO C99 and available under a new/modified/3-clause BSD license. While BLIS exports a new BLAS-like API, it also includes a BLAS compatibility layer which gives application developers access to BLIS implementations via traditional BLAS routine calls.
Install/ Build from source
- Step 1: Clone the source
git clone https://github.com/flame/blis.git
cd blis
- Step 2: Build BLIS
./configure auto
make -j4
make install
Usage
Include the library header blis.h in your source code and link while compiling and executing
Example of Matrix Multiplication in BLIS
#include "blis.h"
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <math.h>
void init_matrix(double* A, int dim1 , int dim2 )
{
int mod = 100003, prod = 7 , e = 1 , i = 0, j = 0;
for ( i = 0; i < dim1; ++i )
{
for ( j = 0; j < dim2; ++j )
{
e = (e*prod + 1)%mod; // random
A[i*dim2 + j] = e * .91739210437;
}
}
}
int main(int argc, char** argv)
{
int m , n , k , i , j , u , nrep = 1 , cnt = 0;
double *A , *B , *C;
if ( argc != 5 )
{
puts("Format: ./a.out number_of_iteration dimension_1 dimension_2 dimension_3");
exit(0);
}
if ( argc == 5 )
{
sscanf ( argv[1] , "%d" , &nrep );
sscanf ( argv[2] , "%d" , &m );
sscanf ( argv[3] , "%d" , &k );
sscanf ( argv[4] , "%d" , &n );
}
int lda = m, ldb = k, ldc = m;
double alpha = 1.0, beta = 1.0;
A = (double *) malloc( sizeof(double) * m * k );
B = (double *) malloc( sizeof(double) * k * n );
C = (double *) malloc( sizeof(double) * m * n );
init_matrix ( A , m , k );
init_matrix ( B , k , n );
dgemm_("N","N", &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
return 0;
}
Compile and execute the above code:
gcc matrix_multiplication_blis.c
./a.out 100 100 100