简体   繁体   English

带LAPACK / BLAS的可变大小数组

[英]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. 我正在尝试使用BLAS例程dgemm进行矩阵乘法。 As the size of array that I wish to input to dgemm is not fixed, I am creating a variable size array. 由于我想输入到dgemm的数组大小不固定,我正在创建一个可变大小的数组。 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). 您尝试将数组数组传递给dgemm,即指针数组(指向数组)。 Of course it's not possible, you must pass an array of doubles. 当然不可能,你必须传递一系列双打。

See here for dgemm header, it needs double*, not double**. 在这里看到dgemm标题,它需要double *,而不是double **。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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