Problem with mxGetScalar in mex function cuda

5 visualizaciones (últimos 30 días)
davide
davide el 7 de Jun. de 2014
Comentada: davide el 11 de Jun. de 2014
Hi *,
i've three different files: main.m makeOperator.m makeOperator_A.cu
In main.m:
global DICTIONARY
load('data.mat');
A = makeOperator();
x = rand( size(A,2), 1, 'double' );
R = A*x;
In makeOperator.m:
classdef makeOperator
properties
methods
..
function v = mtimes( obj, x )
global DICTIONARY
..
v = makeOperator_A( DICTIONARY);
end
..
end
In makeOperator_A.cu:
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) {
mxArray* tmp;
..
tmp = mxGetField(prhs[0],0,"nV");
nV = mxGetScalar(tmp);
..
}
DICTIONARY is in data.mat. DICTIONARY is a struct and nV is a field of a struct
Whit mxGetScalar(tmp) i obtain nV=0 instead of nV=72 that is the true value of nV saved in DICTIONARY.nV
Why?
Thanks,
Davide

Respuesta aceptada

James Tursa
James Tursa el 10 de Jun. de 2014
Editada: James Tursa el 10 de Jun. de 2014
If MATLAB prints out the value of 72 for nV just prior to the mex call, then that is what it is inside your mex function. So my guess is you are having a formatting issue with printing out the value inside your mex function. Check to make sure that the variable type of nV inside the mex function matches the print format. E.g., If nV is an int, use %d to print it out. If nV is a double, use %f to print it out. What is the code you are using to print out the value of nV inside the mex routine?
  1 comentario
davide
davide el 11 de Jun. de 2014
it was the problem ... I was using %f to print an int
Thank you

Iniciar sesión para comentar.

Más respuestas (2)

James Tursa
James Tursa el 9 de Jun. de 2014
Can you verify the value of DICTIONARY.nV just prior to making the mex call? E.g.,
display(DICTIONARY.nV);
v = makeOperator_A( DICTIONARY);

davide
davide el 10 de Jun. de 2014
Yes and matlab prints the exact Value of DICTIONARY.nV

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) 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!

Translated by