Any good documentation for the cblas interface? [closed]

吃可爱长大的小学妹 提交于 2019-12-03 02:20:48

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!