Skip to content

Instantly share code, notes, and snippets.

@ivan-krukov
Created November 29, 2013 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-krukov/7701157 to your computer and use it in GitHub Desktop.
Save ivan-krukov/7701157 to your computer and use it in GitHub Desktop.
Simple example for linear system solver in LAPACK
#include "mkl.h"
#include <math.h>
#include <float.h>
#include <stdio.h>
/* Auxiliary routine: printing a matrix */
void print_matrix(float * matrix, int nrow, int ncol) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < ncol; j++) {
printf("%.*e\t",FLT_DIG, matrix[i * ncol + j]);
}
printf("\n");
}
}
int main () {
float *A, *b;
/* Ax = b
* Ax = xT(A) //transpose
* A is m x m //matrix
* b is m x 1 //vector
* x is m x 1 //vector
*/
int m = 4;
int scale = 1;
A = (float*)mkl_malloc(m*m,32);
for (int i = 0; i< m; i++){
for (int j = 0; j < m; j++) {
int p = i*m+j;
A[p] = pow(i,j)+m*j+1;
}
}
b = (float*)mkl_malloc(m,32);
for (int i = 0; i < m; i++) {
b[i]=pow(2,i+1);
//b[i]=0.0;
}
int matrix_order = LAPACK_ROW_MAJOR;
int ipiv[m];
int info;
printf("%s\n","starting");
//transpose
mkl_simatcopy('R','T',m,m,scale,A,m,m);
info = LAPACKE_sgesv(matrix_order,m,1,A,m,ipiv,b,1);
printf("%d\n",info);
print_matrix(b, m, 1 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment