Following is the C version of the Fortran code in section Using BLAS API in Fortran. It uses the standard BLAS API. The following process takes place during the execution of the code:
The matrices are transposed to account for the row-major storage of C and the column-major convention of BLAS (inherited from Fortran).
The function arguments are passed by address again to be in line with Fortran conventions.
There is a trailing underscore in the function name (
dgemm_) as most Fortran compilers add this trailing underscore by default to symbol names.blis.his included as a header. A sample command to compile it and link with the AOCL-BLAS library is also shown in the following code:// File: BLAS_DGEMM_usage.c // Example code to demonstrate BLAS DGEMM usage #include <stdio.h> #include "blis.h" #define DIM 2 int main() { double a[DIM * DIM] = { 1.0, 2.0, 3.0, 4.0 }; double b[DIM * DIM] = { 5.0, 7.0, 6.0, 8.0 }; double c[DIM * DIM]; int I, J, M, N, K, lda, ldb, ldc; double alpha, beta; M = DIM; N = M; K = M; lda = M; ldb = K; ldc = M; alpha = 1.0; beta = 0.0; printf("a = \\n"); for ( I = 0; I < M; I ++ ) { for ( J = 0; J < K; J ++ ) { printf("%f\t", a[J * K + I]); } printf("\n"); } printf("b = \\n"); for ( I = 0; I < K; I ++ ) { for ( J = 0; J < N; J ++ ) { printf("%f\t", b[J * N + I]); } printf("\n"); } dgemm_("N","N",&M,&N,&K,&alpha,a,&lda,b,&ldb,&beta,c,&ldc); printf("c = \\n"); for ( I = 0; I < M; I ++ ) { for ( J = 0; J < N; J ++ ) { printf("%f\t", c[J * N + I]); } printf("\n"); } return 0; }
A sample compilation command with a GCC compiler for the code above:
$ gcc BLAS_DGEMM_usage.c -I/path/to/include/aocl-blas/ \
/path/to/libblis.a -lpthread -lm