Hi all,
I am trying to implement the code give in Nvidia white paperclick for white paper.I have written following code:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
int i, j, m, n;
double *data1, *data2;
/* Error checking */
if (nrhs != nlhs) mexErrMsgTxt
("The number of input and output arguments must be the same.");
for (i = 0; i < nrhs; i++)
/* Find the dimensions of the data */
m = mxGetM(prhs[i]);
n = mxGetN(prhs[i]);
/* Create an mxArray for the output data */
plhs[i] = mxCreateDoubleMatrix(m, n, mxREAL);
/* Retrieve the input data */
data1 = mxGetPr(prhs[i]);
/* Create a pointer to the output data */
data2 = mxGetPr(plhs[i]);
/* Put data in the output array after squaring them */
for (j = 0; j < m*n; j++)
{
data2[j] = data1[j] * data1[j];
}
}
But It is given the error(------------------------------------------------------------------------
Segmentation violation detected at Fri Apr 09 17:41:21 2010
Configuration:
MATLAB Version: 7.1.0.246 (R14) Service Pack 3
MATLAB License: 161051
Operating System: Microsoft Windows XP
Window System: Version 6.1 (Build 7600)
Processor ID: x86 Family 6 Model 15 Stepping 13, GenuineIntel
Virtual Machine: Java 1.5.0 with Sun Microsystems Inc. Java HotSpot™ Client VM mixed mode
Default Charset: windows-1252
Register State:
EAX = 00000001 EBX = 047177f0
ECX = 04764b20 EDX = 00000001
ESI = 0000003c EDI = 00000001
EBP = 00cdde80 ESP = 00cdde7c
EIP = 78503387 FLG = 00010246
Stack Trace:
[0] libmx.dll:_mxGetN(60, 0x00cde628, 0, 0x047177f0) + 7 bytes
[1] Square.mexw32:0x04a113b5(1, 0x00cde628, 1, 0x00cde688)
[2] libmex.dll:_mexRunMexFile(1, 0x00cde628, 1, 0x00cde688) + 103 bytes
[3] libmex.dll:private: void __thiscall Mfh_mex::runMexFileWithSignalProtection(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(1, 0x00cde628, 1, 0x00cde688) + 73 bytes
[4] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(1, 0x00cde628, 1, 0x00cde688) + 169 bytes
[5] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(1, 0x00cde628, 1, 0x00cde688) + 271 bytes
[6] m_interpreter.dll:int __cdecl mdDispatch(int,char const *,int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn * *)(537, 0x049f6c40 “Square”, 1, 0x00cde628) + 88 bytes
[7] m_interpreter.dll:_inDispatchFromStack(537, 0x049f6c40 “Square”, 1, 1) + 800 bytes
[8] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x049f6c40 “Square”, 537, 1, 1) + 145 bytes
[9] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(2, 0, 0, 0) + 2534 bytes
[10] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 282 bytes
[11] m_interpreter.dll:_inInterPcode(2, 0x784d6e7c, 0, 0) + 81 bytes
[12] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck)(0x00cdf240, 0x00cdf338, 2, 1) + 153 bytes
[13] m_interpreter.dll:$L74683(0x784d6e7c, 0x046dbb20 “b=Square(a);\n”, 0, 0) + 184 bytes
[14] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck)(0x046dbb20 “b=Square(a);\n”, 0, 2, 0x00cdf384) + 69 bytes
[15] m_interpreter.dll:_inEvalCmdNoEnd(0x046dbb20 “b=Square(a);\n”, 1, 255, 0) + 16 bytes
[16] bridge.dll:enum inExecutionStatus __cdecl ThrowSignal(char const *)(0x046dbb20 “b=Square(a);\n”, 0x76961225, 0x00e31e20, 0x00e31e20) + 60 bytes
[17] bridge.dll:$L86781(0, 0, 0x784d6e58, 0x7c36b71f) + 432 bytes
[18] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(2895959, 0x795c3a44, 0x76616461 "¯°ÿzrrÿzrrÿ½¸¹ÿØÖÕÿåÙØÿåÙØÿåÙØÃ
¿Ã¥…", 0x74616d20) + 93 bytes
[19] MATLAB.exe:0x00401ca9(4194304, 0, 2895959, 0x00e31e20)
[20] MATLAB.exe:0x00403d9f(0xfffde000, 0x00cdffd4 “ìÿÔ, 0x77239d72, 0xfffde000)
[21] kernel32.dll:0x76963677(0xfffde000, 0x77ec80a3, 0, 0)
[22] ntdll.dll:0x77239d72(0x00403c1a, 0xfffde000, 0, 0)
[23] ntdll.dll:0x77239d45(0x00403c1a, 0xfffde000, 0, 0)
This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
If it is an official MathWorks function, please
follow these steps in reporting this problem to The MathWorks so
that we have the best chance of correcting it:
-
Send this crash report to segv@mathworks.com for automated analysis.
For your convenience, this information has been recorded in:
C:\Users\HBEONG~1\AppData\Local\Temp\matlab_crash_dump.1236
-
Also, if the problem is reproducible, send the crash report to
support@mathworks.com along with:
- A specific list of steps that will reproduce the problem - Any M, MEX, MDL or other files required to reproduce the problem - Any error messages displayed to the command window
A technical support engineer will contact you with further information.
Thank you for your assistance. Please save your workspace and restart
MATLAB before continuing your work.).Can you tell me what is wrong in this code and how can I solve this problem.
Thanks in advance