简体   繁体   中英

Variable Size array with LAPACK/BLAS

MY Last question was not very clear . So posting it again. I am trying to do matrix multiplication using BLAS routine dgemm. As the size of array that I wish to input to dgemm is not fixed, I am creating a variable size array. But this does not seem to work as I keep getting exception errors. My code is as below:

#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)
{
    int MatSize = 2;
    double **A= new double *[MatSize];
    double **B= new double *[MatSize]; 
    double **C= new double *[MatSize];
    for (int i=0; i<MatSize; i++)
    {
        A[i] = new double[MatSize];
        B[i] = new double[MatSize];
        C[i] = new double[MatSize];
    }
    A[0][0] =  1;
    A[0][1]= 2;
    A[1][0] = 1;
    A[1][1]=2;
    B[0][0] = -2;
    B[0][1]= 3;
    B[1][0]= 2;
    B[1][1]= 2;
    char TRANS = 'N';
    char TRANS2 = 'N';
    double ALPHA = 1;
    double BETA = 0;
    dgemm_(&TRANS, &TRANS, &MatSize, &MatSize, &MatSize, &ALPHA, A, &MatSize, B, &MatSize, &BETA, C, &MatSize);
    cout << C[0][0] << C[0][1] << endl;
    cout << C[1][0] << C[1][1] << endl;
    getchar();
    return 0;
}

Any inputs will be greatly helpful.

You try to pass an array of arrays to dgemm, that is, an array of pointers (to arrays). Of course it's not possible, you must pass an array of doubles.

See here for dgemm header, it needs double*, not double**.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM