Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any good documentation for the cblas interface? [closed]

Tags:

reference

blas

Can someone recommend a good reference or tutorial for the cblas interface? Nothing comes up on google, all of the man pages I've found are for the fortran blas interface, and the pdf that came with MKL literally took ten seconds to search and wasn't helpful.

In particular, I'm curious why there is an extra parameter for row vs. column-major; can't the same operations already be achieved with the transpose flags? It seems like the extra parameter only adds complexity to already an already error-prone interface.

like image 210
Andrew Wagner Avatar asked Oct 11 '10 06:10

Andrew Wagner


2 Answers

This article shows how to use cblas (and others) in C with a simple example: http://www.seehuhn.de/pages/linear

I have quoted the relevant part below in case the site goes down.

Using BLAS

To test the BLAS routines we want to perform a simple matrix-vector multiplication. Reading the file blas2-paper.ps.gz we find that the name of the corresponding Fortran function is DGEMV. The text blas2-paper.ps.gz also explains the meaning of the arguments to this function. In cblas.ps.gz we find that the corresponding C function name is cblas_dgemv. The following example uses this function to calculate the matrix-vector product

/ 3 1 3 \   / -1 \
| 1 5 9 | * | -1 |.
\ 2 6 5 /   \  1 /

Example file testblas.c:

#include <stdio.h>
#include <cblas.h>

double m[] = {
  3, 1, 3,
  1, 5, 9,
  2, 6, 5
};

double x[] = {
  -1, -1, 1
};

double y[] = {
  0, 0, 0
};

int
main()
{
  int i, j;

  for (i=0; i<3; ++i) {
    for (j=0; j<3; ++j) printf("%5.1f", m[i*3+j]);
    putchar('\n');
  }

  cblas_dgemv(CblasRowMajor, CblasNoTrans, 3, 3, 1.0, m, 3,
          x, 1, 0.0, y, 1);

  for (i=0; i<3; ++i)  printf("%5.1f\n", y[i]);

  return 0;
}

To compile this program we use the following command.

cc testblas.c -o testblas -lblas -lm

The output of this test program is

 3.0  1.0  3.0
 1.0  5.0  9.0
 2.0  6.0  5.0
-1.0
 3.0
-3.0

which shows that everything worked fine and that we did not even use the transposed matrix by mistake.

like image 184
andreasw Avatar answered Oct 08 '22 08:10

andreasw


The irix man page for intro_cblas is pretty good:

http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?cmd=getdoc&coll=0650&db=man&fname=3%20INTRO_CBLAS

like image 41
Andrew Wagner Avatar answered Oct 08 '22 10:10

Andrew Wagner