Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
dgemm in 64-bit C++ error

Subject: dgemm in 64-bit C++ error

From: Nick

Date: 25 Sep, 2013 08:08:07

Message: 1 of 2

I am being told that MATLAB has encountered an internal error and needs to close when running this very simple dgemm call in c++ (64-bit windows). Does anyone know why?

// file: blasTest.cpp
#include "matrix.h"
#include "mex.h"
#include "blas.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    int K = 256; int M = 100;
    double* Phi = (double*) mxMalloc(sizeof(double)*K*K);
    for(int i=0; i<K*K; i++)
        Phi[i] = double(i);
    
    double* scratch = (double*) mxMalloc(sizeof(double)*K*M);
    double* scratch2 = (double*) mxMalloc(sizeof(double)*K*M);
    for(int i=0; i<K*M; i++)
        scratch[i] = 1.0;
        
    double zero = 0.0; double one = 1.0;
    // scratch2 = Phi * scratch
    dgemm("N", "N", (ptrdiff_t*)&K, (ptrdiff_t*)&M, (ptrdiff_t*)&K, &one, Phi, (ptrdiff_t*)&K, scratch, (ptrdiff_t*)&K, &zero, scratch2, (ptrdiff_t*)&K);
}

I am compiling it with these commands:
blaslib = fullfile(matlabroot, 'extern', 'lib', 'win64', 'microsoft', 'libmwblas.lib');
mex('blasTest.cpp', blaslib);

Subject: dgemm in 64-bit C++ error

From: Duncan Po

Date: 25 Sep, 2013 12:43:06

Message: 2 of 2

Just casting the address to ptrdiff_t* is not the same actually having ptrdiff_t variables. Your "int" variables are only 32-bit wide, but dgemm will treat them as 64-bit variables.

You need to make your int type variables with ptrdiff_t.

"Nick" wrote in message <l1u5l7$3m9$1@newscl01ah.mathworks.com>...
> I am being told that MATLAB has encountered an internal error and needs to close when running this very simple dgemm call in c++ (64-bit windows). Does anyone know why?
>
> // file: blasTest.cpp
> #include "matrix.h"
> #include "mex.h"
> #include "blas.h"
>
> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
> int K = 256; int M = 100;
> double* Phi = (double*) mxMalloc(sizeof(double)*K*K);
> for(int i=0; i<K*K; i++)
> Phi[i] = double(i);
>
> double* scratch = (double*) mxMalloc(sizeof(double)*K*M);
> double* scratch2 = (double*) mxMalloc(sizeof(double)*K*M);
> for(int i=0; i<K*M; i++)
> scratch[i] = 1.0;
>
> double zero = 0.0; double one = 1.0;
> // scratch2 = Phi * scratch
> dgemm("N", "N", (ptrdiff_t*)&K, (ptrdiff_t*)&M, (ptrdiff_t*)&K, &one, Phi, (ptrdiff_t*)&K, scratch, (ptrdiff_t*)&K, &zero, scratch2, (ptrdiff_t*)&K);
> }
>
> I am compiling it with these commands:
> blaslib = fullfile(matlabroot, 'extern', 'lib', 'win64', 'microsoft', 'libmwblas.lib');
> mex('blasTest.cpp', blaslib);

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us