You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cblas_example1.c 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* cblas_example.c */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "cblas.h"
  5. int main ( )
  6. {
  7. CBLAS_LAYOUT Layout;
  8. CBLAS_TRANSPOSE transa;
  9. double *a, *x, *y;
  10. double alpha, beta;
  11. int m, n, lda, incx, incy, i;
  12. Layout = CblasColMajor;
  13. transa = CblasNoTrans;
  14. m = 4; /* Size of Column ( the number of rows ) */
  15. n = 4; /* Size of Row ( the number of columns ) */
  16. lda = 4; /* Leading dimension of 5 * 4 matrix is 5 */
  17. incx = 1;
  18. incy = 1;
  19. alpha = 1;
  20. beta = 0;
  21. a = (double *)malloc(sizeof(double)*m*n);
  22. x = (double *)malloc(sizeof(double)*n);
  23. y = (double *)malloc(sizeof(double)*n);
  24. /* The elements of the first column */
  25. a[0] = 1;
  26. a[1] = 2;
  27. a[2] = 3;
  28. a[3] = 4;
  29. /* The elements of the second column */
  30. a[m] = 1;
  31. a[m+1] = 1;
  32. a[m+2] = 1;
  33. a[m+3] = 1;
  34. /* The elements of the third column */
  35. a[m*2] = 3;
  36. a[m*2+1] = 4;
  37. a[m*2+2] = 5;
  38. a[m*2+3] = 6;
  39. /* The elements of the fourth column */
  40. a[m*3] = 5;
  41. a[m*3+1] = 6;
  42. a[m*3+2] = 7;
  43. a[m*3+3] = 8;
  44. /* The elements of x and y */
  45. x[0] = 1;
  46. x[1] = 2;
  47. x[2] = 1;
  48. x[3] = 1;
  49. y[0] = 0;
  50. y[1] = 0;
  51. y[2] = 0;
  52. y[3] = 0;
  53. cblas_dgemv( Layout, transa, m, n, alpha, a, lda, x, incx, beta,
  54. y, incy );
  55. /* Print y */
  56. for( i = 0; i < n; i++ )
  57. printf(" y%d = %f\n", i, y[i]);
  58. free(a);
  59. free(x);
  60. free(y);
  61. return 0;
  62. }