linear algebra - LAPACK Matrix multiplication with C++ -
i new c++ , trying use lapack libraries matrix multiplication. tried run routine dgemm give below. expecting output a*b. every time answer b*a. way routine works or wrong code.
my code:
#include "stdafx.h" #include<iostream> using namespace std; extern "c" void dgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, double *alpha, double *a, const int *lda, double *b, const int *ldb, double *beta, double *c, const int *ldc); int main(void) { double a[4] = {1,2,3,4}; double b[4] = {5,6,7,8}; char trans = 'n'; int m = 2; int n = 2; int k = 2; double alpha = 1.0; int lda = 2; int ldb = 2; double beta = 0.0; double c[4]; int ldc = 2; dgemm_(&trans, &trans, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc); cout << c[0] << endl; cout << c[1] << endl; cout << c[2] << endl; cout << c[3] << endl; getchar(); return 0; }
any inputs helpful.
i've not studied details of call dgemm, , cannot tell how interpreting result matrix. seems pretty mixing col major , row major interpretations somewhere. calculation uses col major, assuming row major.
Comments
Post a Comment