I got segfault when trying to call "new" to create a pointer and push it into a vector. The code that I push the element in the vector is:
queue->push_back(new Box(gen_id, Interval(x_mid, x_end), Interval(y_mid-y_halfwidth, y_mid+y_halfwidth)));
Basically Box is a Class and the constructor just take 3 arguments, generation_id, and 2 Intervals. I printed out the content in vector before and after this "push",
before:
[ -0.30908203125, -0.3087158203125 ] , [ -0.951416015625, -0.9510498046875 ]
[ -0.3087158203125, -0.308349609375 ] , [ -0.951416015625, -0.9510498046875 ]
[ -0.30908203125, -0.3087158203125 ] , [ -0.9510498046875, -0.95068359375 ]
[ -0.3087158203125, -0.308349609375 ] , [ -0.9510498046875, -0.95068359375 ]
after:
[ -0.30908203125, -0.3087158203125 ] , [ -0.951416015625, -0.9510498046875 ]
[ -0.3087158203125, -0.308349609375 ] , [ -0.951416015625, -0.9510498046875 ]
[ 8.9039208750109844342e-243, 6.7903818933216500424e-173 ] , [ -0.9510498046875, -0.95068359375 ]
[ -0.3087158203125, -0.308349609375 ] , [ -0.9510498046875, -0.95068359375 ]
[ -0.3087158203125, -0.308349609375 ] , [ -0.95123291015625, -0.95086669921875 ]
I have no clue why does this happen, but apparently, there's one element got corrupted. There's no other codes between these two sets of output except that "push", and I used gdb to confirm that. Also, I checked those 2 Intervals variables, both give me a result that make sense.
My questions is: in what situation does "new" get segfault? Or is my problem caused because of other stuff? Thanks.
Assuming it really is new generating the segfault, the most common cause would be a corrupted heap, typically a result of overwriting memory you don't own and/or a double delete.
Valgrind will be your friend if you can run on a Linux system.
I doubt that new itself is giving you the segfault; the problem is probably in one of the constructors. Try splitting up that giant line, and put in some print statements to see exactly where the problem is.
printf("Creating the first interval...\n");
Interval a(x_mid, x_end);
printf("Creating the second interval...\n");
Interval b(y_mid-y_halfwidth, y_mid + y_halfwidth);
printf("Creating the box...\n");
Box* box_to_enqueue = new Box(gen_id, a, b);
printf("Enqueueing the box...\n");
// Do you really want to enqueue a pointer instead of a Box?
queue->push_back(box_to_enqueue);
Related
I am working in Netlogo on a series of models making heavy use matrices. Briefly, the models include a number of state-variables for different breeds, where the state-variables are often stock-like items. As a simple example, consider the model:
extensions [ matrix ]
globals
[
]
turtles-own
[
n-items
stock-list
]
to setup
clear-all
reset-ticks
create-turtles 2
ask turtles
[
setxy random-xcor random-ycor
set n-items 10
let n-vars 3
set stock-list matrix:make-constant n-items n-vars [0] ; empty matrix
let stock-item n-values n-items [i -> i]
let stock-cost n-values n-items [ random-normal 10 2 ]
let stock-age n-values n-items [ random 50 ]
matrix:set-column stock-list 0 stock-item
matrix:set-column stock-list 1 stock-cost
matrix:set-column stock-list 2 stock-age
]
end
Here, each turtle's matrix stock-list is initialised as an empty matrix and then its columns filled in depending on the variables stock-item (id for stock), stock-cost and stock-age.
Imagine a go procedure that increments the stock age by one each time-step:
to go
ask turtles
[
let current-age matrix:get-column stock-list 1
let new-age map [x -> x + 1] current-age
matrix:set-column stock-list 2 new-age
]
tick
end
What I would like to do is an operation on stock-cost only if the age is greater than some value, e.g. 10
;; pseudo-code
for( i = 1 to I = number of items )
{
if ( stock-age[i] > 10 )
{
stock-cost[i] - 1
}
}
I know how to change the list of stock-cost conditional on its own values, using the map primitive, e.g.:
to decrease-stock-value
ask turtles
[
let current-cost matrix:get-column stock-list 1
set current-cost map [[?] -> ifelse-value (? > 10) [? - 1][?]] current-cost
matrix:set-column stock-list 1 current-cost
]
But my efforts to generalise this to using values in a different list to condition upon have failed.
Thanks for your help! Also, any insight onto whether this is a good approach to modelling state variables such as stocks would be useful.
I think I sorted it out using:
to decrease-stock-value
ask turtles
[
let current-cost matrix:get-column stock-list 1
let current-age matrix:get-column stock-list 2
let new-cost ( map [ [ a b ] ->
ifelse-value ( a > 10 ) [ b - 1 ] [ b ] ]
current-age current-cost
)
matrix:set-column stock-list 1 new-cost
]
end
Could some one please help me out!
I have a dictionary with key and values.Each key is a cluster label, and the values associated with the keys are the data points in that cluster.Each data point is a list with 60 columns(ie, a time series data with length 60).I want to assemble these time series row wise for supervised classification such that the each time series data point has the key(say 0) as its last value in the row as its class.(eg: 0.1,0.3,0.5, 0)where the last value zero is the class value. Here is part of my real data.
{0: array([[ 28.7812, 34.4632, 31.3381, ..., 33.3759, 25.4652, 25.8717],
[ 24.8923, 25.741 , 27.5532, ..., 34.2484, 32.1005, 26.691 ],
[ 31.3987, 30.6316, 26.3983, ..., 33.9002, 29.5446, 29.343 ],
...,
[ 24.4293, 39.7616, 40.1207, ..., 42.3223, 31.9421, 32.8973],
[ 32.3175, 39.9719, 40.6855, ..., 28.8281, 41.7112, 35.3453],
[ 25.7836, 34.1285, 42.6593, ..., 34.4315, 32.155 , 34.8388]]),
{1: array([[ 35.7709, 34.396 , 35.2249, ..., 32.4859, 30.7772, 24.5854],
[ 24.9706, 33.8315, 46.9423, ..., 24.1889, 11.4137, 13.1961],
[ 35.5351, 41.7067, 39.1705, ..., 37.7721, 37.2248, 32.9494],
...,
[ 28.0747, 41.7835, 42.1198, ..., 38.0344, 46.4582, 44.4323],
[ 33.6696, 38.6754, 39.7419, ..., 34.9395, 36.9095, 39.7494],
[ 30.5729, 41.0741, 44.9793, ..., 24.353 , 19.7201, 12.7513]])}
In simpler terms, I am only interested in having the values for each row without the brackets and then append it to the row with its key as the last number in the row.
I'm not sure I got your input format right...
input = {0: [['0', '0']], 1: [['0', '0']]}
output = []
for key in input.keys():
input[key].append(key)
output.append(input[key])
old_cluster = []
for i in range (0,len(toy_data)):
d_cluster =np.append(toy_data[i], int(labels[i]))
f_cluster= d_cluster.tolist()
old_cluster.append(f_cluster)
data_cluster=np.asarray(old_cluster)
Writes Data to a text file without the bracket each point on a line with
its cluster label as the last point.
with open('mytest.txt','w') as outfile:
for item in data_cluster:
outfile.write("%s\n" % ','.join(map(str,item)))
I spent the morning trying to find an easy function (x,y) -> n that would number the patches like this
I was not successful. Do any of Y'all have any experience or suggestions?
Here is my take on it:
patches-own [ n ]
to setup
clear-all
resize-world -4 4 -4 4 ; so it looks better, but use any size you like...
create-turtles 1 [
set heading 180
foreach n-values count patches [ ? + 1 ] [
set n ?
if [ n = 0 ] of patch-left-and-ahead 90 1 [ left 90 ]
fd 1
]
die
]
ask patches [ set plabel n ]
end
Funny you should ask I also spent the morning doing the same thing. There is a function that uses the floor function but I remembered that this is netlogo
so I made a turtle do it for me.
with this procedure
to spin
let k 1
set t t + 1
repeat 2
[
lt 90
repeat t [fd 1 ask patch-here [set n k set k k + 1]]
]
end
and this code in the start up.
crt 1 [
set heading 0
repeat 41 [spin]
die
]
and of course
patches-own [n]
to call them in n order use
foreach sort-on [n] patches ask ? [ "the stuff you want them to do" ]
I have variables in system dynamic in NetLogo and I am trying a nested if else as follows
Md * (( ifelse n_porg = 0 [ 0 ] [ ifelse ( ( SDIa * Total_norg ) / n_porg ) > 1
[ 1 ] [ ( SDIa * Total_norg ) / n_porg ] ] ) / delay )
I am getting an error "Expected reporter" please help
ifelse is a command; you can't drop a command into the middle of a reporter expression, because a command doesn't report a value.
Instead of ifelse, use ifelse-value, which is a reporter.
You may find you need to add parentheses, e.g. ifelse (n_porg = 0) ...
References for this post:
[1] http://www.mathworks.com/matlabcentral/newsreader/view_thread/278243 " Making C++ objects persistent between mex calls, and robust."
[2] MATLAB parfor and C++ class mex wrappers (copy constructor required?) "MATLAB parfor and C++ class mex wrappers (copy constructor required?)"
I successfully implemented a Matlab/C++ interface, based on method proposed on [1].
Anyway, i'm having troubles when trying to use the system with Matlab Parallel Computing.
What happens to me is a segmentation fault, when trying a conversion between matlab handle and C++ pointer, in the MEX interface.
To be more clear, I will recap the structure proposed in [1].
There are three files in the system, with this communication scheme:
[myInterface.m] <--> [myMexInterface.cpp] <--> [myClass.cpp]
where
myInterface.m is a matlab class
myMexInterface.cpp is a C++ (mex) function
myClass.cpp is a C++ (mex) class
The use of this system is divided in 2 phases:
Construction:
a matlab object myInterface is created. This causes a call to myMexInterface.mexa64, that invokes the creation of a C++ myClass object. The C++ pointer of myClass is sent back thru myMexInterface.mexa64 to myInterface, that stores it for further use. In particular, myMexInterface.mexa64 operates a conversion of the C++ pointer of myClass to a matlab handle.
Use of the C++ class from matlab:
myInterface offers methods to clients that, passing thru myMexInterface.mexa64, invokes functions on the object myClass. In this phase, the handle stored from myInterface during construction phase is necessary to myMexInterface.mexa64 in order to invokes the functions on the correct C++ object. Of course, in this phase myMexInterface.mexa64 operates a reverse conversion, from Matlab handle to C++ pointer.
In my implementation, that works in single-thread, a segmentation fault error occours during the conversion from handle to pointer.
In particular, I would like to focus on myMexInterface.cpp.
The command to be executed is passed thru a string, as first argument, while possibly (for the second phase operations) the second argument is a matlab handle relative to the C++ object associated to that interface.
#include "mex.h"
#include "class_handle.hpp"
CLASS void myMexInterface(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (!strcmp("new", cmd)) {
// ...
plhs[0] = convertPtr2Mat<myClass>(new myClass());
}
if (!strcmp("delete", cmd)) {
// ...
destroyObject<myClass>(prhs[1]);
}
// Get the class instance pointer from the second input
cout << " trying to convert handle...";
myClass *myClass_instanceAddress = convertMat2Ptr<myClass>(prhs[1]); // SEGMENTATION FAULT ON MULTI CORE!!!
cout << " success in handle conversion. \n";
if (!strcmp("aFunction", cmd)) {
myClass_instanceAddress->aFunction();
}
// .. other functions
}
The function convertMat2Pt, generating the segfault, comes from the inclusion of class_handle.hpp, that is part of the solution proposed in [1].
In particular the function inside that class_handle.hpp in which the segfault is convertMat2HandlePtr:
template<class base> class class_handle
// ...
template<class base> inline class_handle<base> *convertMat2HandlePtr(const mxArray *in)
{
if (mxGetNumberOfElements(in) != 1 || mxGetClassID(in) != mxUINT64_CLASS || mxIsComplex(in))
mexErrMsgTxt("Input must be a real uint64 scalar.");
std::cout << "class_handle: trying to cast \n";
class_handle<base> *ptr = reinterpret_cast<class_handle<base> *>(*((uint64_t *)mxGetData(in))); // SEGMENTATION FAULT ON MULTI CORE!!!
if (!ptr->isValid())
mexErrMsgTxt("Handle not valid.");
return ptr;
}
template<class base> inline base *convertMat2Ptr(const mxArray *in)
{
return convertMat2HandlePtr<base>(in)->ptr();
}
// ...
Actually is not clear to me what really happen in that cast, so I cannot go in deeper analysis.
What I can imagine is that for some reason, the Matlab Parallel Computing generates an inconsistence with the C++ object, previously created.
The matlab client function that generate the segfault is the following:
myInterface = myMexInterface();
matlabpool open local 1
out = myModelInterf.aFunction()
disp(' Now starting parfor ***');
parfor i = 1:1
out = myModelInterf.aFunction()
end
Note that in order to simplify the situation, I open only one worker in matlabpool, and the parfor execute only one loop: anyway I still have the error. Of course without parfor block there is no error, even with multiple calls of aFunction().
What I obtain in Command window is:
Create interface with CPP handle: 139698584223104
Starting matlabpool using the 'local' profile ... connected to 1 workers.
trying to convert handle...class_handle: trying to cast
success in handle conversion.
out =
3
Now starting parfor ***
Save interface with CPP handle: 139698584223104
Save interface with CPP handle: 139698584223104
Create interface with CPP handle: 0
Load interface with CPP handle: 139698584223104
trying to convert handle...class_handle: trying to cast
------------------------------------------------------------------------
Segmentation violation detected at Wed Jan 30 15:00:47 2013
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Current Visual : None
Default Encoding: UTF-8
GNU C Library : 2.15 stable
MATLAB Root : /usr/local/MATLAB/R2012b
MATLAB Version : 8.0.0.783 (R2012b)
Operating System: Linux 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7 16:16:45 UTC 2012 x86_64
Processor ID : x86 Family 6 Model 42 Stepping 7, GenuineIntel
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : No active display
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00007fedbcba74a0 RBX = 00007fee2afa0fe0
RCX = 0000000000000006 RDX = 0000000000000060
RSP = 00007fee2afa0520 RBP = 00007fee2afa09f0
RSI = 0000000000000000 RDI = 00007fee2b817a50
R8 = 00007fee2afa09af R9 = 00007fedbcdb9208
R10 = 00007fee2afa0200 R11 = 00007fee3d57ba00
R12 = 0000000000000002 R13 = 00007f0e1c7cfd80
R14 = 00007fee2afa0dd0 R15 = 00007fee2afa0f20
RIP = 00007fedfc00a8e4 EFL = 0000000000010206
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007fee3f5e31de /usr/local/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00516574 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEm+000158
[ 1] 0x00007fee3f5e44b2 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00521394
[ 2] 0x00007fee3f5e5ffe /usr/local/MATLAB/R2012b/bin/glnxa64/libmwfl.so+00528382 _ZN2fl4diag13terminate_logEPKcRKNS0_14thread_contextE+000174
[ 3] 0x00007fee3e8d2093 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00557203 _ZN2fl4diag13terminate_logEPKcPK8ucontext+000067
[ 4] 0x00007fee3e8ceb9d /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00543645
[ 5] 0x00007fee3e8d0835 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00550965
[ 6] 0x00007fee3e8d0a55 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00551509
[ 7] 0x00007fee3e8d10fe /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00553214
[ 8] 0x00007fee3e8d1295 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00553621
[ 9] 0x00007fee3cdc8cb0 /lib/x86_64-linux-gnu/libpthread.so.0+00064688
[ 10] 0x00007fedfc00a8e4 /home/gwala/Documents/mexInitConfig/mex_torque_profile.mexa64+00010468 mexFunction+002116
[ 11] 0x00007fee355b269a /usr/local/MATLAB/R2012b/bin/glnxa64/libmex.so+00112282 mexRunMexFile+000090
[ 12] 0x00007fee355ae4e9 /usr/local/MATLAB/R2012b/bin/glnxa64/libmex.so+00095465
[ 13] 0x00007fee355af33c /usr/local/MATLAB/R2012b/bin/glnxa64/libmex.so+00099132
[ 14] 0x00007fee3e620a4b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00596555 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000539
[ 15] 0x00007fee3deb4e56 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02264662
[ 16] 0x00007fee3de651c6 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01937862
[ 17] 0x00007fee3de69ab4 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01956532
[ 18] 0x00007fee3de660d3 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01941715
[ 19] 0x00007fee3de66ed7 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01945303
[ 20] 0x00007fee3ded2760 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02385760
[ 21] 0x00007fee3e620a4b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00596555 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000539
[ 22] 0x00007fee35b73538 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcos.so+01574200
[ 23] 0x00007fee35b15232 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcos.so+01188402
[ 24] 0x00007fee35b154ce /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcos.so+01189070
[ 25] 0x00007fee35b1723c /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcos.so+01196604
[ 26] 0x00007fee35bfc9c7 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcos.so+02136519
[ 27] 0x00007fee3e5d6431 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00291889 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+000529
[ 28] 0x00007fee3deb4933 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02263347
[ 29] 0x00007fee3dec40d8 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02326744
[ 30] 0x00007fee3dec7038 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02338872
[ 31] 0x00007fee3de6ab18 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01960728
[ 32] 0x00007fee3de660d3 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01941715
[ 33] 0x00007fee3de66ed7 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01945303
[ 34] 0x00007fee3ded2760 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02385760
[ 35] 0x00007fee3e62053b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00595259 _ZN8Mfh_file11dispatch_fhEP20_mdUnknown_workspaceiPP11mxArray_tagiS4_+000555
[ 36] 0x00007fee3e5e3057 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00344151 _Z30callViamdMxarrayFunctionHandlePviPP11mxArray_tagiS2_+000039
[ 37] 0x00007fee3de3e143 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01777987
[ 38] 0x00007fee3de3f07d /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01781885
[ 39] 0x00007fee3de3f78b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01783691
[ 40] 0x00007fee3de42759 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01795929
[ 41] 0x00007fee3de6922b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01954347
[ 42] 0x00007fee3de660d3 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01941715
[ 43] 0x00007fee3de66ed7 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01945303
[ 44] 0x00007fee3ded2760 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02385760
[ 45] 0x00007fee3e62053b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00595259 _ZN8Mfh_file11dispatch_fhEP20_mdUnknown_workspaceiPP11mxArray_tagiS4_+000555
[ 46] 0x00007fee3e5e3057 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00344151 _Z30callViamdMxarrayFunctionHandlePviPP11mxArray_tagiS2_+000039
[ 47] 0x00007fee3ddf38b5 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01472693 inFullFevalFcn+001045
[ 48] 0x00007fee3e5e66ba /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00358074 _ZN11Mfh_builtin11dispatch_mfEiPP11mxArray_tagiS2_+000074
[ 49] 0x00007fee3e5d6431 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00291889 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+000529
[ 50] 0x00007fee3e0a1140 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+04280640
[ 51] 0x00007fee3e0a197a /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+04282746
[ 52] 0x00007fee3e0a24ea /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+04285674
[ 53] 0x00007fee3df054cd /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02593997
[ 54] 0x00007fee3df30d22 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02772258
[ 55] 0x00007fee3df30e4f /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02772559
[ 56] 0x00007fee3e04db30 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+03939120
[ 57] 0x00007fee3de69fec /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01957868
[ 58] 0x00007fee3de660d3 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01941715
[ 59] 0x00007fee3de66ed7 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01945303
[ 60] 0x00007fee3ded2760 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02385760
[ 61] 0x00007fee3e620a4b /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_dispatcher.so+00596555 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000539
[ 62] 0x00007fee3de9388f /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02128015
[ 63] 0x00007fee3de92c69 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+02124905
[ 64] 0x00007fee3ddf129c /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01462940 inCallFcnWithTrap+000092
[ 65] 0x00007fee3de57bfb /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01883131
[ 66] 0x00007fee3ddf0168 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwm_interpreter.so+01458536 _Z28inCallFcnWithTrapInDesiredWSiPP11mxArray_tagiS1_PKcbP15inWorkSpace_tag+000104
[ 67] 0x00007fee36365b09 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwiqm.so+02878217 _ZN3iqm15BaseFEvalPlugin7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000457
[ 68] 0x00007fedff8a992d /usr/local/MATLAB/R2012b/bin/glnxa64/libnativejmi.so+00674093 _ZN9nativejmi14JmiFEvalPlugin7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000173
[ 69] 0x00007fedff8d6c45 /usr/local/MATLAB/R2012b/bin/glnxa64/libnativejmi.so+00859205 _ZN3mcr3mvm27McrSwappingIqmPluginAdapterIN9nativejmi14JmiFEvalPluginEE7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000629
[ 70] 0x00007fee3633bbfa /usr/local/MATLAB/R2012b/bin/glnxa64/libmwiqm.so+02706426
[ 71] 0x00007fee3632d594 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwiqm.so+02647444
[ 72] 0x00007fee357d7ccd /usr/local/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00122061 _Z10ioReadLinebP8_IO_FILERKN5boost8optionalIKP15inWorkSpace_tagEEb+000429
[ 73] 0x00007fee357d8354 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00123732
[ 74] 0x00007fee357dd71d /usr/local/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00145181
[ 75] 0x00007fee357dd81e /usr/local/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00145438
[ 76] 0x00007fee357ddf07 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwbridge.so+00147207 _Z8mnParserv+000631
[ 77] 0x00007fee3e8b7472 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00447602 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+000034
[ 78] 0x00007fee3e895b69 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00310121
[ 79] 0x00007fee3e895d48 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00310600
[ 80] 0x00007fee3eeabf73 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+00999283 _ZN10eventqueue18UserEventQueueImpl5flushEv+000371
[ 81] 0x00007fee3eeac695 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01001109 _ZN10eventqueue8ReadPipeEib+000053
[ 82] 0x00007fee3eeab321 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+00996129 _ZN10eventqueue18UserEventQueueImpl9selectFcnEb+000353
[ 83] 0x00007fee3284fa65 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwuix.so+00518757
[ 84] 0x00007fee3ef45a11 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01628689 _ZSt8for_eachIN9__gnu_cxx17__normal_iteratorIPN5boost8weak_ptrIN4sysq10ws_ppeHookEEESt6vectorIS6_SaIS6_EEEENS4_8during_FIS6_NS2_10shared_ptrIS5_EEEEET0_T_SH_SG_+000081
[ 85] 0x00007fee3ef46aeb /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01633003 _ZN4sysq12ppe_for_eachINS_8during_FIN5boost8weak_ptrINS_10ws_ppeHookEEENS2_10shared_ptrIS4_EEEEEET_RKS9_+000251
[ 86] 0x00007fee3ef445a2 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01623458 _ZN4sysq19ppePollingDuringFcnEb+000114
[ 87] 0x00007fee3ef44969 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01624425 _ZN4sysq11ppeMainLoopEiib+000121
[ 88] 0x00007fee3ef44b08 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01624840 _ZN4sysq11ppeLoopIfOKEiib+000152
[ 89] 0x00007fee3ef44c63 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwservices.so+01625187 _ZN4sysq20processPendingEventsEiib+000147
[ 90] 0x00007fee3e896664 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00312932
[ 91] 0x00007fee3e896b3c /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00314172
[ 92] 0x00007fee3e890592 /usr/local/MATLAB/R2012b/bin/glnxa64/libmwmcr.so+00288146
[ 93] 0x00007fee3cdc0e9a /lib/x86_64-linux-gnu/libpthread.so.0+00032410
[ 94] 0x00007fee3caedcbd /lib/x86_64-linux-gnu/libc.so.6+00998589 clone+000109
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 this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.** This crash report has been saved to disk as /home/gwala/matlab_crash_dump.11705-1 **
class_handle: trying to cast
Destroy object 0x7f0e1e45f090
class_handle: trying to cast
Deleted myclass with handle: 139698584223104
Error using parallel_function (line 589)
The session that parfor is using has shut down.
As can be seen, the interface is correctly created, then aFunction returns correctly the value 3 for 'out' (and this works even for multiple calls).
Then the parfor loop starts, as is known the matlab object is saved (actually it is not clear to me why it is saved twice, but this happens even from Command Window, when I save a myInterface object).
Finally a new myInterface is created, with handle 0, and the handle is restored to the correct previous value. Altought, the call to aFunctions fails.
I Finally report the myInterface matlab class:
classdef myInterface < handle
properties (SetAccess = private, Transient=true)
objectHandle; % Handle to the underlying C++ class instance
end
methods(Static=true)
function obj = loadobj(this)
obj = myInterface();
obj.objectHandle = this.objectHandle;
disp(['Load interface with CPP handle: ' num2str(this.objectHandle)]);
end
end
methods
function obj = saveobj(this)
obj.objectHandle = this.objectHandle;
disp(['Save interface with CPP handle: ' num2str(this.objectHandle)]);
end
%% Constructor - Create a new C++ class instance
function this = myInterface(varargin)
if (size(varargin) == 0) % constructor with no arguments. Used in load/save operations
this.objectHandle = 0;
else % constructor with normal arguments
this.objectHandle = myMexInterface('new', varargin{:});
end
disp(['Create interface with CPP handle: ' num2str(this.objectHandle)]);
end
%% Destructor - Destroy the C++ class instance
function delete(this)
myMexInterface('delete', this.objectHandle);
disp(['Deleted myclass with handle: ' num2str(this.objectHandle)]);
end
%% aFunction
function varargout = aFunction(this, varargin)
[varargout{1:nargout}] = myMexInterface('aFunction', this.objectHandle,varargin{:});
end
end
end
Please note that, as suggested in [2], I included the loadobj, saveobj functions, and the class has the "Transient" property in order to achieve load/save operations.
Hoping in the help of someone, I hope that this post can help someone.
Regards,
Gabriele Gualandi
Parallel computing toolbox workers are separate MATLAB processes - they might even be running on separate machines, and as such they have separate address spaces. If I've understood correctly, you are passing a pointer to an object which is valid on your MATLAB client to a worker, and trying to dereference that pointer there.
This can possibly be made to work if you explicitly use shared memory regions to communicate between client and workers. For example, see this file exchange contribution: http://www.mathworks.co.uk/matlabcentral/fileexchange/28572-sharedmatrix .
The alternative, as I proposed in the solution to one of the questions you reference above, is to support saving to disk more fully - in this case, this probably means pulling the contents out of your C++ object into a MATLAB structure, and supporting recreating your C++ object from that MATLAB structure.