mex file update and compile
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rachel Parise
el 3 de Abr. de 2020
Editada: James Tursa
el 11 de Abr. de 2020
When I run this portion of my code I get a fatal crash error, I am trying to update the code the best that I know how but keep getting the crash. First chunk of code calls up the second chunk... Can someone help me update this code?
% Attempt to update Q using the mex file update
try
Q = updateQ(Q, counts(indicesList));
catch exception
% Failed to call updateQ so compile all functions if a compiler
% is installed on the system
% Compiliing is different on Linux and Windows
if(isunix)
mex -largeArrayDims updateQ.c
mex -largeArrayDims calculateE.c
mex -largeArrayDims symmeig.c -lmwlapack
elseif(ispc)
ext = mexext;
arch = ext(end-1:end);
compiler = mex.getCompilerConfigurations().Manufacturer;
if(strcmp(compiler, 'LCC'))
folder = 'lcc';
elseif(strcmp(compiler, 'GNU'))
folder = 'GNU';
else
error('No compiler selected?');
end
%% lapacklib = fullfile(matlabroot, 'extern', 'lib', , 'mingw64', 'libmwlapack.lib');
lapacklib = fullfile(matlabroot,'extern','lib','win64','microsoft','libmwlapack.lib');
mex('-largeArrayDims', 'symmeig.c', lapacklib)
mex('-largeArrayDims', 'updateQ.c')
mex('-largeArrayDims', 'calculateE.c')
end
% Update Q now the compilation has succeeded
Q = updateQ(Q, counts(indicesList));
end
#include "mex.h"
/* Update summarisation matrix Q stored in upper packed format with the
* next spectrum
*
* Arguments:
* Q - current iteration of Q in upper packed format
* x - spectrum update Q with
*/
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
double *Q, *x;
int i, j, index;
int xSize = mxGetNumberOfElements(prhs[1]);
/* Output the updated Q */
plhs[0] = mxDuplicateArray(prhs[0]);
Q = mxGetDoubles(prhs[0]);
x = mxGetDoubles(prhs[1]);
for(j = 0; j < xSize; j++) {
for(i = 0; i <= j; i++) {
index = (i+j*(j+1)/2);
Q[index] += x[i] * x[j];
}
}
}
0 comentarios
Respuesta aceptada
James Tursa
el 11 de Abr. de 2020
Editada: James Tursa
el 11 de Abr. de 2020
The use of mxGetDoubles( ) requires that the code is compiled with R2018a or later, and that you use the '-R2018a' option instead of the '-largeArrayDims' option when you compile. E.g.,
mex('-R2018a', 'symmeig.c', lapacklib)
mex('-R2018a', 'updateQ.c')
mex('-R2018a', 'calculateE.c')
What version of MATLAB are you using?
Also, that mex routine can easily bomb if you don't pass in the correct arguments (easy to run off the end of valid memory) since there are no checks in the code for valid size and type of inputs. How are you calling it? (variable types and sizes)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Compiler SDK en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!