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: Making C++ objects persistent between mex calls, and robust.
Replies: 37   Last Post: Sep 27, 2013 6:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: Making C++ objects persistent between mex calls, and robust.
Posted: Jan 30, 2013 5:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"Gabri Gwala" <djgwla-aux@yahoo.it> wrote in message
news:kebmas$kjs$1@newscl01ah.mathworks.com...
> Many thanks to Oliver Woodford and all the other contributors of this
> effective strategy. Anyway I would like to submit a potential issue when
> using Matlab Parallel Computation Toolbox. In particular i'm trying to use
> this scheme inside a parfor, obtaining a segmentation fault while trying
> to convert a matlab handle in C++ pointer.
> Since this is not a pure Matlab topic, I posted the detailed question on
> stackoverflow.
>
> http://stackoverflow.com/questions/14607109/matlab-c-segmentation-fault-on-parallel-computing-with-c-mex-persistent-obj


I'm not an expert in Parallel Computing Toolbox and referring to C++ objects
in MATLAB, but I'm doubtful this will work without significant modification.

Remember that in Parallel Computing Toolbox, workers are separate instances
of MATLAB from the client. There's a reason they have the same icon as the
MATLAB client session in step 3 of the description of a PARFOR loop:

http://www.mathworks.com/help/distcomp/introduction-to-parallel-solutions.html#brjw1fx-1

This means that the value representing a pointer to the C++ object in your
client session probably won't point to your C++ object on the workers, and
even if it did (for local workers on the same machine) that memory would
probably belong to the MATLAB client session (possibly leading to the
segmentation violation given in your Stack Overflow posting.)

Think of this like the handle to a figure on the client. When that handle
gets passed to the workers, the workers can't use that handle to affect the
client's figure window -- it's the client's handle!

If your C++ object had a small amount of state, returning a struct array or
cell array from the MEX-file containing the state necessary to reconstitute
the object might be an option (since MATLAB knows how to pass structs
between the client and the workers) but that kind of defeats the purpose of
having a C++ object.

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



Date Subject Author
4/1/10
Read Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
6/7/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Anthony Halley
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Walter Roberson
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Anthony Halley
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
1/22/11
Read Re: Making C++ objects persistent between mex calls, and robust.
newuser asdf
1/22/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Bruno Luong
1/23/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Rune Allnor
1/23/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Bruno Luong
1/23/11
Read Re: Making C++ objects persistent between mex calls, and robust.
newuser asdf
1/24/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
2/3/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Pierre
2/3/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
2/3/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Pierre
2/3/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
2/15/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Pierre
7/6/11
Read Re: Making C++ objects persistent between mex calls, and robust.
mathias
7/6/11
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
5/24/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Ajay
5/25/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Pierre
10/2/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
11/7/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Francesco Montorsi
11/8/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
11/9/12
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
1/21/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
1/22/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
1/30/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Gabri Gwala
1/30/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Steven Lord
1/31/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
9/22/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Gabri Gwala
9/22/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Gabri Gwala
9/27/13
Read Re: Making C++ objects persistent between mex calls, and robust.
Oliver Woodford
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Anthony Halley
6/8/10
Read Re: Making C++ objects persistent between mex calls, and robust.
Anthony Halley

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.