Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Segmentation violation in fortran source MEX file
Replies: 1   Last Post: Mar 26, 2013 10:21 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: Segmentation violation in fortran source MEX file
Posted: Mar 26, 2013 10:21 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Sudarshan " <r.sudarshan1990@gmail.com> wrote in message
news:kir9pi$dhr$1@newscl01ah.mathworks.com...
>> Are you running 32-bit or 64-bit?
>> What version of MATLAB are you using?
>>
>> I see potential problems with your use of "integer" as a pointer (will
>> need to be integer*8 on 64-bit systems ... i.e. should use mwPointer
>> instead).
>>
>> Also the mxCreateFull function is deprecated, and has been for quite some
>> time, so this must be very old code.
>>
>> Is it your intent to simply call the pr_equil function with MATLAB inputs
>> & outputs? If so, this can probably be done much simpler.
>>
>> James Tursa

>
> Hi James,
>
> Thanks a lot for such a quick turnaround :) I am using Windows 7 32 bit,
> MATLAB R2011b 32 bit, Visual Studio 2010 Professional and Intel Visual
> Fortran Composer XE 2011. Yes the code is pretty old, written in 2001 and
> modified in 2006.
>
> I have replaced mxCreateFull function with mxCreateDoubleMatrix. Also i
> used mwPointer wherever appropriate. However, MATLAB still crashes.
> I guess i should learn about MEX files properly to get out of this.
> Anyway, if you think minor corrections could make the code work, would you
> please let me know?


*snip*

It might be a "minor correction" but that's a good chunk of code to dig
through to locate it. This reminds me of an old joke:

http://www.jokesplace.com/joke/retiredengineer.html

I recommend that you follow the suggestions in the Debugging MEX-files
section of the documentation:

http://www.mathworks.com/help/releases/R2011b/techdoc/matlab_external/f28378.html

If you don't have access to this online documentation, search the
documentation in your installation of MATLAB for "debug Fortran MEX" and it
should be one of the first few hits.

Alternately you could always go for the quick & dirty debugging method,
which involves doing divide and conquer in your file with mexPrintf
statements to isolate the line that's causing the crash. Write a mexPrintf
statement roughly in the middle of your file, run. If it crashes before the
message is printed, the line on which the crash occurs is in the first half
of your code; repeat by putting a mexPrintf in the middle of that first
half. Otherwise put a mexPrintf in the middle of the second half of your
code. Repeat this process until you know where the crash happens. Then you
get to work your way backwards and figure out why the crash occurs on that
line.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.