Mystery exception.
Here is a simple unit test. #include <iostream> #include <vector> #include "data.generator.h" #include "reg.class.h" #include <boost/smart_ptr/shared_ptr.hpp> int main(int argc, char* argv[]) { basicGenerator bg; std::cout << "Sample size: " << bg.get_sampleSize() << std::endl; bg.makeData(); std::vector<std::vector<double> > x; std::vector<double> y; bg.getDataForRegression(x,y); unsigned int imax = y.size(); for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; } std::cout << "==================================================================" << std::endl; regressionPCA rpca(x,y); std::cout << "==================================================================" << std::endl; boost::shared_ptr<regressionPCA> prpca; for (unsigned int j = 0 ; j < 25 ; j++) { std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl; bg.makeData(); bg.getDataForRegression(x,y); /* for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; }*/ prpca.reset(new regressionPCA(x,y)); std::cout << "==================================================================" << std::endl; } return 0; } The mystery is why I get the following output: 86 -0.727354 -0.252937 -0.841919 87 2.46787 2.13614 1.48789 88 1.79373 1.49828 1.25923 89 0.416356 0.565407 -0.114605 90 -0.258883 -0.585597 -0.183372 91 0.833355 0.914344 0.81171 92 -0.0338814 -0.00264442 -0.118973 93 1.13764 0.41599 1.33175 94 -1.86323 -1.90867 -1.35118 95 0.907604 1.14917 0.621669 96 2.1166 1.06194 1.1703 97 0.159543 0.14446 -0.665135 98 -0.508617 -0.370597 -0.703225 99 2.69086 2.75267 1.40633 ================================================================== r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 ================================================================== Run #: 1 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 14.1699 10.7091 V = 0.49497 -0.86891 0.86891 0.49497 Beta = 0.476181 0.391545 Aborted (core dumped) Ted@Ted-acer-i7w7 ~/New.System/tests $ I do not know if it is something peculiar to GSL or to my use of either the boost::shared_ptr or the boost::shared_array, but for whatever reason, I get only one analysis out if a given instance of my PCA regression class. Here is how it is declared: #ifndef REG_CLASS_H #define REG_CLASS_H #include <iosfwd> #include <vector> #include <gsl/gsl_linalg.h> class regressionPCA { private: unsigned int nrows, ncols; regressionPCA(void) {}; // makes default construction impossible public: regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&); void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&); inline void setNrows(unsigned int v) { nrows = v;}; inline void setNcols(unsigned int v) { ncols = v;}; inline unsigned int getNrows(void) const { return nrows; }; inline unsigned int getNcols(void) const { return ncols; }; }; #endif And here is how it is implemented: #include "reg.class.h" #include <iostream> #include <algorithm> #include <gsl/gsl_linalg.h> #include <boost/smart_ptr/shared_array.hpp> regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { Reset(data,Ydata); } void regressionPCA::Reset(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { unsigned int r(0),c(0),n(0); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; r = data.size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; c = data[0].size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; setNrows(r); setNcols(c); n = r * c; std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; /* */ boost::shared_array<double> Btmp(new double[c]), Ytmp(new double[r]), Utmp(new double[n]), Vtmp(new double[c*c]), Stmp(new double[c]); double* B = Btmp.get(); double* Y = Ytmp.get(); double* U = Utmp.get(); double* V = Vtmp.get(); double* S = Stmp.get(); /* */ /* double* B = new double[c]; double* Y = new double[r]; double* U = new double[n]; double* V = new double[c*c]; double* S = new double[c]; */ // double *bptr = U.get(); double *bptr = U; std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end(); while (it != end) { bptr = std::copy(it->begin(), it->end(),bptr); ++it; } bptr = Y; std::copy(Ydata.begin(),Ydata.end(),bptr); gsl_matrix_view Um = gsl_matrix_view_array(U, getNrows(), getNcols()); gsl_vector_view Ym = gsl_vector_view_array(Y, getNrows()); gsl_vector_view Bm = gsl_vector_view_array(B, getNcols()); gsl_vector_view Sm = gsl_vector_view_array(S, getNcols()); gsl_matrix_view Vm = gsl_matrix_view_array(V, getNcols(), getNcols()); gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector); gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl; std::cout << std::endl << std::endl << "V = " << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl; std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl; /* delete[] B; delete[] Y; delete[] U; delete[] V; delete[] S; */ }; NB: It does not matter whether I use naked arrays (and explicitly use operator delete[], or boost::array. Nor does it matter whether I have the instance of it in the loop on the stack or heap (I did make all the work inReset so that the same instance could be used to do all of a series of regressions, but there is little point if I get a core dump). Since I am working with a system that may be non-autonomous, I was going to modify it to work with a boost:: circular_buffer, and then use the std::copy on that container's begin and end iterators in exactly the same way that I use it with the std:;vector above, so I can doing a moving analysis with a fixed length sample temporal period. And I can't stop here, as I need not only the regression coefficients, but the residuals. Since this core dump is happening after the last executable line of function reset, and before the last executable line in my for loop in function main (and I don't have any lines of code to eb executed between the two), I wonder if this is due to an unfortunate interaction between the boost::shared_array and the gsl code. Do the gsl matrix and vector views have to be cleaned up before the memory they're configured to use is freed? Or is there something odd with boost::shared_array (I have only used boost::shared_ptr before - so I am not entirely comfortable with my knowledge of boost::shared_array)? If so, how? Or is it the case I have abused the shared_array? If so, how do I fix it? Any insights as to what may be awry would be appreciated. Cheers Ted
Hi Ted, On 03/25/2012 03:38 AM, Ted Byers wrote:
boost::shared_array<double> Btmp(new double[c]),
Ytmp(new double[r]),
Utmp(new double[n]),
Vtmp(new double[c*c]),
Stmp(new double[c]);
double* B = Btmp.get();
double* Y = Ytmp.get();
double* U = Utmp.get();
double* V = Vtmp.get();
double* S = Stmp.get();
I am a little bit astonished about these lines. The pointer B is only valid as long as Btmp is in scope and this scope exits after your Reset method has finished (and therefore the object Btmp will be deleted since it is a object created on the stack). So after reset has finished, B,Y,... are all dangling pointer, which should never be accessed. Doing so may arise a core dump earlier or later. You have to store at least one instance of the shared_array to have access to B, Y, ... . As it seems, your first post to the list have the same problem. I found this section in your code (maybe you should post an example without the misleading comments, since the program won't compile if one will remove the comments in the first example. This was very missleading in your first post, so I was unable to see your problem there! Maybe you should rewrite your class: #ifndef REG_CLASS_H #define REG_CLASS_H #include <iosfwd> #include <vector> #include <gsl/gsl_linalg.h> class regressionPCA { private: unsigned int nrows, ncols; regressionPCA(void) {}; // makes default construction impossible // Add this to your class, holding the pointers as long as they were needed! boost::shared_array<double> B, Y, U, V, S; public: regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&); void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&); inline void setNrows(unsigned int v) { nrows = v;}; inline void setNcols(unsigned int v) { ncols = v;}; inline unsigned int getNrows(void) const { return nrows; }; inline unsigned int getNcols(void) const { return ncols; }; }; #endif --------- #include "reg.class.h" #include <iostream> #include <algorithm> #include <gsl/gsl_linalg.h> #include <boost/smart_ptr/shared_array.hpp> regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { Reset(data,Ydata); } void regressionPCA::Reset(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { unsigned int r(0),c(0),n(0); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; r = data.size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; c = data[0].size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; setNrows(r); setNcols(c); n = r * c; std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; /* THIS CODE IN THIS COMMENT IS WRONG, THIS WILL CREATE A STACK OBJECT ONLY! Refering to your first post on the list, B is not the B of your class. The B of your class is hidden by the B you have created on the stack here. boost::shared_array<double> B(new double[c]); // wrong! */ // This is what you want to do: B.reset( new double[c] ); Y.reset( new double[n] ); // ... do this with the rest too! // Use the pointer with B.get() for external libs, this was quite correct. // double *bptr = U.get(); double *bptr = U; std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end(); while (it != end) { bptr = std::copy(it->begin(), it->end(),bptr); ++it; } bptr = Y; std::copy(Ydata.begin(),Ydata.end(),bptr); gsl_matrix_view Um = gsl_matrix_view_array(U, getNrows(), getNcols()); gsl_vector_view Ym = gsl_vector_view_array(Y, getNrows()); gsl_vector_view Bm = gsl_vector_view_array(B, getNcols()); gsl_vector_view Sm = gsl_vector_view_array(S, getNcols()); gsl_matrix_view Vm = gsl_matrix_view_array(V, getNcols(), getNcols()); gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector); gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl; std::cout << std::endl << std::endl << "V = " << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl; std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl; };
Hi Sven, Thanks for this. Second, in my first post, the problem was due to some unpleasant behaviour of Gnu make I wasn't aware of that resulting in a certain object file not being remade even though the source for it had changed (actually, I don't know if it is in make itself or a bug in my suite of make files - something to be investigated further - doing make realclean followed by make solved that). My current problem is something else, probably due to how memory is handled either in GSL or in boost::shared_array, but maybe something more subtle. I had left the comments in place to show alternatives I had tried. It is no surprise that compiling would fail if they were uncommented. I have now changed regressionPCA back to the way I had intended it to be in the first place. Here is the header: #ifndef REG_CLASS_H #define REG_CLASS_H #include <iosfwd> #include <vector> #include <gsl/gsl_linalg.h> #include <boost/smart_ptr/shared_array.hpp> class regressionPCA { private: unsigned int nrows, ncols; boost::shared_array<double> B, Y, U, V, S; regressionPCA(void) {}; // makes default construction impossible public: regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&); void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&); inline void setNrows(unsigned int v) { nrows = v;}; inline void setNcols(unsigned int v) { ncols = v;}; inline unsigned int getNrows(void) const { return nrows; }; inline unsigned int getNcols(void) const { return ncols; }; }; #endif And here is the implementation: #include "reg.class.h" #include <iostream> #include <algorithm> #include <gsl/gsl_linalg.h> regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { Reset(data,Ydata); } void regressionPCA::Reset(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { unsigned int r(0),c(0),n(0); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; r = data.size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; c = data[0].size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; setNrows(r); setNcols(c); n = r * c; std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; B.reset(new double[c]); Y.reset(new double[r]); U.reset(new double[n]); V.reset(new double[c*c]); S.reset(new double[c]); double* Btmp = B.get(); double* Ytmp = Y.get(); double* Utmp = U.get(); double* Vtmp = V.get(); double* Stmp = S.get(); double *bptr = Utmp; std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end(); while (it != end) { bptr = std::copy(it->begin(), it->end(),bptr); ++it; } bptr = Ytmp; std::copy(Ydata.begin(),Ydata.end(),bptr); gsl_matrix_view Um = gsl_matrix_view_array(Utmp, getNrows(), getNcols()); gsl_vector_view Ym = gsl_vector_view_array(Ytmp, getNrows()); gsl_vector_view Bm = gsl_vector_view_array(Btmp, getNcols()); gsl_vector_view Sm = gsl_vector_view_array(Stmp, getNcols()); gsl_matrix_view Vm = gsl_matrix_view_array(Vtmp, getNcols(), getNcols()); gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector); gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl; std::cout << std::endl << std::endl << "V = " << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl; std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl; }; Obviously a work in progress as I need to create data members to store the result of the analysis, and member functions to pass the results back to the calling code. I also need to get and analyse the residuals.. Here is function main: #include <iostream> #include <vector> #include "data.generator.h" #include "reg.class.h" #include <boost/smart_ptr/shared_ptr.hpp> int main(int argc, char* argv[]) { basicGenerator bg; std::cout << "Sample size: " << bg.get_sampleSize() << std::endl; bg.makeData(); std::vector<std::vector<double> > x; std::vector<double> y; bg.getDataForRegression(x,y); unsigned int imax = y.size(); for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; } std::cout << "==================================================================" << std::endl; regressionPCA rpca(x,y); std::cout << "==================================================================" << std::endl; boost::shared_ptr<regressionPCA> prpca; for (unsigned int j = 0 ; j < 25 ; j++) { std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl; bg.makeData(); bg.getDataForRegression(x,y); /* for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; }*/ prpca.reset(new regressionPCA(x,y)); std::cout << "==================================================================" << std::endl; } return 0; } The following output shows that cleaning up the declaration and definition has not changed anything: 94 -1.86323 -1.90867 -1.35118 95 0.907604 1.14917 0.621669 96 2.1166 1.06194 1.1703 97 0.159543 0.14446 -0.665135 98 -0.508617 -0.370597 -0.703225 99 2.69086 2.75267 1.40633 ================================================================== r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 ================================================================== Run #: 1 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 14.1699 10.7091 V = 0.49497 -0.86891 0.86891 0.49497 Beta = 0.476181 0.391545 ================================================================== Run #: 2 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 Aborted (core dumped) Ted@Ted-acer-i7w7 ~/New.System/tests $ There are a couple things I see. 1) the last statement successfully executed was the last statement of my Reset function. It then returns to function main, and it's nect statement produces the line of '+' symbols, and this is not successfully executed. So, something bad is happening between the end of the function and the return to function main. 2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely). 3) It must be something subtle, as I get one execution of the analysis done in Reset, as shown in the first analysis reported by 'rpca', and then I get two complete passes through my loop over j before it crashes. I am baffled as to even how I determine whether it is something I have done wrong with GSL or with boost::shared_array. But here is an experiment I tried, let's see what you make of this. I changed my main loop to use: rpca.Reset(x,y); instead of prpca.reset(new regressionPCA(x,y)); That is, I used the object I'd made on the stack, instead of the one(s) made on the heap. I then added " std::cout << "Flag 1" << std::endl << std::flush;" right after I invoked boost::shared_array's reset, and " std::cout << "Flag 2" << std::endl << std::flush;" right after I copy new data to these arrays. Here is the result: 98 -0.508617 -0.370597 -0.703225 99 2.69086 2.75267 1.40633 ================================================================== r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Flag 1 Flag 2 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 ================================================================== Run #: 1 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Flag 1 Flag 2 Sv = 14.1699 10.7091 V = 0.49497 -0.86891 0.86891 0.49497 Beta = 0.476181 0.391545 ================================================================== Run #: 2 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped) Ted@Ted-acer-i7w7 ~/New.System/tests $ Do you notice the change? Instead of finishing the second analysis in the loop, it crashes after I print the dimensions of the input matrix and vector, at some point in resetting one of the boost::shared_array objects. How do I determine whether this is a bug in boost::shared_array or some bad interaction between boost::shared_array and GSL? Cheers Ted From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sven Steckmann Sent: March-25-12 4:13 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Mystery exception. Hi Ted,
Hi, Ted, 2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new
regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely).
It sounds like you haven't looked at the core file. You don't have to wonder where it is crashing if it produces a core file. That's what they are for. Cheers, Will On Sun, Mar 25, 2012 at 12:00 PM, Ted Byers <r.ted.byers@gmail.com> wrote:
Hi Sven,****
** **
Thanks for this. ****
** **
** **
Second, in my first post, the problem was due to some unpleasant behaviour of Gnu make I wasn't aware of that resulting in a certain object file not being remade even though the source for it had changed (actually, I don't know if it is in make itself or a bug in my suite of make files - something to be investigated further - doing make realclean followed by make solved that). My current problem is something else, probably due to how memory is handled either in GSL or in boost::shared_array, but maybe something more subtle.****
** **
I had left the comments in place to show alternatives I had tried. It is no surprise that compiling would fail if they were uncommented.****
** **
I have now changed regressionPCA back to the way I had intended it to be in the first place.****
** **
Here is the header:****
** **
#ifndef REG_CLASS_H****
#define REG_CLASS_H****
** **
#include <iosfwd>****
#include <vector>****
#include <gsl/gsl_linalg.h>****
#include <boost/smart_ptr/shared_array.hpp>****
** **
class regressionPCA {****
private:****
unsigned int nrows, ncols;****
boost::shared_array<double> B, Y, U, V, S;****
regressionPCA(void) {}; // makes default construction impossible****
public:****
regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&);****
void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&);****
inline void setNrows(unsigned int v) { nrows = v;};****
inline void setNcols(unsigned int v) { ncols = v;};****
inline unsigned int getNrows(void) const { return nrows; };****
inline unsigned int getNcols(void) const { return ncols; };****
};****
** **
#endif****
** **
And here is the implementation:****
** **
#include "reg.class.h"****
** **
#include <iostream>****
#include <algorithm>****
#include <gsl/gsl_linalg.h>****
** **
regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, ****
const std::vector<double>& Ydata) {****
Reset(data,Ydata);****
}****
** **
void regressionPCA::Reset(const std::vector<std::vector<double> >&data, ** **
const std::vector<double>& Ydata) {****
unsigned int r(0),c(0),n(0);****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
r = data.size();****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
c = data[0].size();****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
setNrows(r);****
setNcols(c);****
n = r * c;****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
B.reset(new double[c]);****
Y.reset(new double[r]); ****
U.reset(new double[n]);****
V.reset(new double[c*c]);****
S.reset(new double[c]);****
double* Btmp = B.get();****
double* Ytmp = Y.get();****
double* Utmp = U.get();****
double* Vtmp = V.get();****
double* Stmp = S.get();****
double *bptr = Utmp;****
std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end();****
while (it != end) {****
bptr = std::copy(it->begin(), it->end(),bptr);****
++it;****
}****
bptr = Ytmp;****
std::copy(Ydata.begin(),Ydata.end(),bptr);****
gsl_matrix_view Um = gsl_matrix_view_array(Utmp, getNrows(), getNcols()); ****
gsl_vector_view Ym = gsl_vector_view_array(Ytmp, getNrows());****
gsl_vector_view Bm = gsl_vector_view_array(Btmp, getNcols());****
gsl_vector_view Sm = gsl_vector_view_array(Stmp, getNcols());****
gsl_matrix_view Vm = gsl_matrix_view_array(Vtmp, getNcols(), getNcols()); ****
gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector);****
gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); ****
std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl;****
std::cout << std::endl << std::endl << "V = " << std::endl;****
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl;****
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl;****
std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl;****
};****
** **
Obviously a work in progress as I need to create data members to store the result of the analysis, and member functions to pass the results back to the calling code. I also need to get and analyse the residuals….****
** **
Here is function main:****
** **
#include <iostream>****
#include <vector>****
#include "data.generator.h"****
#include "reg.class.h"****
#include <boost/smart_ptr/shared_ptr.hpp>****
** **
int main(int argc, char* argv[]) {****
basicGenerator bg;****
std::cout << "Sample size: " << bg.get_sampleSize() << std::endl;****
bg.makeData();****
std::vector<std::vector<double> > x;****
std::vector<double> y;****
bg.getDataForRegression(x,y);****
unsigned int imax = y.size();****
for (unsigned int i = 0 ; i < imax ; i++) {****
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;****
}****
std::cout << "==================================================================" << std::endl;****
regressionPCA rpca(x,y);****
std::cout << "==================================================================" << std::endl;****
boost::shared_ptr<regressionPCA> prpca;****
for (unsigned int j = 0 ; j < 25 ; j++) {****
std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl;****
bg.makeData();****
bg.getDataForRegression(x,y);****
/* for (unsigned int i = 0 ; i < imax ; i++) {****
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;****
}*/****
prpca.reset(new regressionPCA(x,y));****
std::cout << "==================================================================" << std::endl;****
}****
return 0;****
}****
** **
The following output shows that cleaning up the declaration and definition has not changed anything:****
** **
94 -1.86323 -1.90867 -1.35118****
95 0.907604 1.14917 0.621669****
96 2.1166 1.06194 1.1703****
97 0.159543 0.14446 -0.665135****
98 -0.508617 -0.370597 -0.703225****
99 2.69086 2.75267 1.40633****
==================================================================****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
** **
Sv = 18.3225 4.69155****
** **
V =****
0.695362 -0.718659****
0.718659 0.695362****
** **
Beta = 0.693195 0.627794****
==================================================================****
Run #: 1****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
** **
Sv = 14.1699 10.7091****
** **
V =****
0.49497 -0.86891****
0.86891 0.49497****
** **
Beta = 0.476181 0.391545****
==================================================================****
** **
Run #: 2****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
** **
Sv = 18.3225 4.69155****
** **
V =****
0.695362 -0.718659****
0.718659 0.695362****
** **
Beta = 0.693195 0.627794****
Aborted (core dumped)****
** **
Ted@Ted-acer-i7w7 ~/New.System/tests****
$****
** **
There are a couple things I see.****
** **
1) the last statement successfully executed was the last statement of my Reset function. It then returns to function main, and it's nect statement produces the line of '+' symbols, and this is not successfully executed. So, something bad is happening between the end of the function and the return to function main.****
2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely).****
3) It must be something subtle, as I get one execution of the analysis done in Reset, as shown in the first analysis reported by 'rpca', and then I get two complete passes through my loop over j before it crashes. I am baffled as to even how I determine whether it is something I have done wrong with GSL or with boost::shared_array.****
** **
But here is an experiment I tried, let's see what you make of this. I changed my main loop to use:****
** **
rpca.Reset(x,y);****
** **
instead of ****
** **
prpca.reset(new regressionPCA(x,y));****
** **
That is, I used the object I'd made on the stack, instead of the one(s) made on the heap. I then added " std::cout << "Flag 1" << std::endl << std::flush;" right after I invoked boost::shared_array's reset, and " std::cout << "Flag 2" << std::endl << std::flush;" right after I copy new data to these arrays. Here is the result:****
** **
98 -0.508617 -0.370597 -0.703225****
99 2.69086 2.75267 1.40633****
==================================================================****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
Flag 1****
Flag 2****
** **
** **
Sv = 18.3225 4.69155****
** **
** **
V =****
0.695362 -0.718659****
0.718659 0.695362****
** **
** **
Beta = 0.693195 0.627794****
==================================================================****
** **
** **
Run #: 1****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
Flag 1****
Flag 2****
** **
** **
Sv = 14.1699 10.7091****
** **
** **
V =****
0.49497 -0.86891****
0.86891 0.49497****
** **
** **
Beta = 0.476181 0.391545****
==================================================================****
** **
** **
Run #: 2****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack)****
Segmentation fault (core dumped)****
** **
Ted@Ted-acer-i7w7 ~/New.System/tests****
$****
** **
** **
Do you notice the change?****
** **
Instead of finishing the second analysis in the loop, it crashes after I print the dimensions of the input matrix and vector, at some point in resetting one of the boost::shared_array objects. How do I determine whether this is a bug in boost::shared_array or some bad interaction between boost::shared_array and GSL?****
** **
** **
Cheers****
** **
Ted****
** **
*From:* boost-users-bounces@lists.boost.org [mailto: boost-users-bounces@lists.boost.org] *On Behalf Of *Sven Steckmann *Sent:* March-25-12 4:13 AM *To:* boost-users@lists.boost.org *Subject:* Re: [Boost-users] Mystery exception.****
** **
Hi Ted,
****
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
As an aside, does anyone know how to tell MS Outlook not to top-post? Anyway, Hi Will, Thanks, I would if I knew how to make sense of it. Here is what is in the latest stackdump: Exception: STATUS_ACCESS_VIOLATION at eip=6110D500 eax=20024D68 ebx=00000338 ecx=3FBBDE84 edx=20022070 esi=200223A8 edi=A9AE95F4 ebp=1ED48072 esp=0028BD00 program=C:\cygwin\home\Ted\New.System\tests\test.pca.reg.gsl.exe, pid 7888, thread main cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B Stack trace: Frame Function Args 0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack) I look at it and I don't know what to make of what it is telling me. How can I turn an of those values into something meaningful? And the other one is even less intelligible: Stack trace: Frame Function Args 0028BBA4 75961194 (00000104, 0000EA60, 00000000, 0028BCD8) 0028BBB8 75961148 (00000104, 0000EA60, 000000A4, 0028BCB4) 0028BCD8 610D9339 (00000000, 0028BDF4, 0028BD08, 611352F4) 0028BDC8 610D67CE (00000000, 6C4F4A60, 6C4F4A60, 6C4F4A60) 0028BE28 610D6C9E (00000000, 0028BE34, 61183704, 00000006) 0028BED8 610D6DF0 (00002FDC, 00000006, 00000000, 200223B0) 0028BEF8 610D6E1C (00000006, 0028CE80, 00000000, 00000064) 0028BF28 610D70A5 (00000000, 00000000, 00000002, 00000001) 0028BFC8 6110D4E5 (200217D0, 0028CC5C, 0028CC50, 00000000) 0028CC88 00401C2D (0000002F, 00000000, 6127390C, 61006F58) 0028CD28 61006F58 (00000000, 0028CD78, 61006550, 0000000A) End of stack trace How does one make sense of this? Cheers Ted From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Will Mason Sent: March-25-12 2:38 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Mystery exception. Hi, Ted, 2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely). It sounds like you haven't looked at the core file. You don't have to wonder where it is crashing if it produces a core file. That's what they are for. Cheers, Will On Sun, Mar 25, 2012 at 12:00 PM, Ted Byers <r.ted.byers@gmail.com> wrote: Hi Sven, Thanks for this. Second, in my first post, the problem was due to some unpleasant behaviour of Gnu make I wasn't aware of that resulting in a certain object file not being remade even though the source for it had changed (actually, I don't know if it is in make itself or a bug in my suite of make files - something to be investigated further - doing make realclean followed by make solved that). My current problem is something else, probably due to how memory is handled either in GSL or in boost::shared_array, but maybe something more subtle. I had left the comments in place to show alternatives I had tried. It is no surprise that compiling would fail if they were uncommented. I have now changed regressionPCA back to the way I had intended it to be in the first place. Here is the header: #ifndef REG_CLASS_H #define REG_CLASS_H #include <iosfwd> #include <vector> #include <gsl/gsl_linalg.h> #include <boost/smart_ptr/shared_array.hpp> class regressionPCA { private: unsigned int nrows, ncols; boost::shared_array<double> B, Y, U, V, S; regressionPCA(void) {}; // makes default construction impossible public: regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&); void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&); inline void setNrows(unsigned int v) { nrows = v;}; inline void setNcols(unsigned int v) { ncols = v;}; inline unsigned int getNrows(void) const { return nrows; }; inline unsigned int getNcols(void) const { return ncols; }; }; #endif And here is the implementation: #include "reg.class.h" #include <iostream> #include <algorithm> #include <gsl/gsl_linalg.h> regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { Reset(data,Ydata); } void regressionPCA::Reset(const std::vector<std::vector<double> >&data, const std::vector<double>& Ydata) { unsigned int r(0),c(0),n(0); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; r = data.size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; c = data[0].size(); std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; setNrows(r); setNcols(c); n = r * c; std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl; B.reset(new double[c]); Y.reset(new double[r]); U.reset(new double[n]); V.reset(new double[c*c]); S.reset(new double[c]); double* Btmp = B.get(); double* Ytmp = Y.get(); double* Utmp = U.get(); double* Vtmp = V.get(); double* Stmp = S.get(); double *bptr = Utmp; std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end(); while (it != end) { bptr = std::copy(it->begin(), it->end(),bptr); ++it; } bptr = Ytmp; std::copy(Ydata.begin(),Ydata.end(),bptr); gsl_matrix_view Um = gsl_matrix_view_array(Utmp, getNrows(), getNcols()); gsl_vector_view Ym = gsl_vector_view_array(Ytmp, getNrows()); gsl_vector_view Bm = gsl_vector_view_array(Btmp, getNcols()); gsl_vector_view Sm = gsl_vector_view_array(Stmp, getNcols()); gsl_matrix_view Vm = gsl_matrix_view_array(Vtmp, getNcols(), getNcols()); gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector); gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl; std::cout << std::endl << std::endl << "V = " << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl; std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl; std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl; }; Obviously a work in progress as I need to create data members to store the result of the analysis, and member functions to pass the results back to the calling code. I also need to get and analyse the residuals…. Here is function main: #include <iostream> #include <vector> #include "data.generator.h" #include "reg.class.h" #include <boost/smart_ptr/shared_ptr.hpp> int main(int argc, char* argv[]) { basicGenerator bg; std::cout << "Sample size: " << bg.get_sampleSize() << std::endl; bg.makeData(); std::vector<std::vector<double> > x; std::vector<double> y; bg.getDataForRegression(x,y); unsigned int imax = y.size(); for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; } std::cout << "==================================================================" << std::endl; regressionPCA rpca(x,y); std::cout << "==================================================================" << std::endl; boost::shared_ptr<regressionPCA> prpca; for (unsigned int j = 0 ; j < 25 ; j++) { std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl; bg.makeData(); bg.getDataForRegression(x,y); /* for (unsigned int i = 0 ; i < imax ; i++) { std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl; }*/ prpca.reset(new regressionPCA(x,y)); std::cout << "==================================================================" << std::endl; } return 0; } The following output shows that cleaning up the declaration and definition has not changed anything: 94 -1.86323 -1.90867 -1.35118 95 0.907604 1.14917 0.621669 96 2.1166 1.06194 1.1703 97 0.159543 0.14446 -0.665135 98 -0.508617 -0.370597 -0.703225 99 2.69086 2.75267 1.40633 ================================================================== r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 ================================================================== Run #: 1 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 14.1699 10.7091 V = 0.49497 -0.86891 0.86891 0.49497 Beta = 0.476181 0.391545 ================================================================== Run #: 2 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 Aborted (core dumped) Ted@Ted-acer-i7w7 ~/New.System/tests $ There are a couple things I see. 1) the last statement successfully executed was the last statement of my Reset function. It then returns to function main, and it's nect statement produces the line of '+' symbols, and this is not successfully executed. So, something bad is happening between the end of the function and the return to function main. 2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely). 3) It must be something subtle, as I get one execution of the analysis done in Reset, as shown in the first analysis reported by 'rpca', and then I get two complete passes through my loop over j before it crashes. I am baffled as to even how I determine whether it is something I have done wrong with GSL or with boost::shared_array. But here is an experiment I tried, let's see what you make of this. I changed my main loop to use: rpca.Reset(x,y); instead of prpca.reset(new regressionPCA(x,y)); That is, I used the object I'd made on the stack, instead of the one(s) made on the heap. I then added " std::cout << "Flag 1" << std::endl << std::flush;" right after I invoked boost::shared_array's reset, and " std::cout << "Flag 2" << std::endl << std::flush;" right after I copy new data to these arrays. Here is the result: 98 -0.508617 -0.370597 -0.703225 99 2.69086 2.75267 1.40633 ================================================================== r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Flag 1 Flag 2 Sv = 18.3225 4.69155 V = 0.695362 -0.718659 0.718659 0.695362 Beta = 0.693195 0.627794 ================================================================== Run #: 1 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 Flag 1 Flag 2 Sv = 14.1699 10.7091 V = 0.49497 -0.86891 0.86891 0.49497 Beta = 0.476181 0.391545 ================================================================== Run #: 2 r: 0 c: 0 n: 0 r: 100 c: 0 n: 0 r: 100 c: 2 n: 0 r: 100 c: 2 n: 200 0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped) Ted@Ted-acer-i7w7 ~/New.System/tests $ Do you notice the change? Instead of finishing the second analysis in the loop, it crashes after I print the dimensions of the input matrix and vector, at some point in resetting one of the boost::shared_array objects. How do I determine whether this is a bug in boost::shared_array or some bad interaction between boost::shared_array and GSL? Cheers Ted From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sven Steckmann Sent: March-25-12 4:13 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Mystery exception. Hi Ted, _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Ted, On Sun, Mar 25, 2012 at 2:06 PM, Ted Byers <r.ted.byers@gmail.com> wrote:
As an aside, does anyone know how to tell MS Outlook not to top-post?****
** **
Anyway, Hi Will,****
** **
Thanks, I would if I knew how to make sense of it. Here is what is in the latest stackdump:****
** **
Exception: STATUS_ACCESS_VIOLATION at eip=6110D500****
****
eax=20024D68 ebx=00000338 ecx=3FBBDE84 edx=20022070 esi=200223A8 edi=A9AE95F4****
****
ebp=1ED48072 esp=0028BD00 program=C:\cygwin\home\Ted\New.System\tests\test.pca.reg.gsl.exe, pid 7888, thread main****
****
cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B****
****
Stack trace:****
****
Frame Function Args****
****
0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack)****
** **
I look at it and I don't know what to make of what it is telling me. How can I turn an of those values into something meaningful?****
** **
And the other one is even less intelligible:****
** **
Stack trace:****
****
Frame Function Args****
****
0028BBA4 75961194 (00000104, 0000EA60, 00000000, 0028BCD8)****
****
0028BBB8 75961148 (00000104, 0000EA60, 000000A4, 0028BCB4)****
****
0028BCD8 610D9339 (00000000, 0028BDF4, 0028BD08, 611352F4)****
****
0028BDC8 610D67CE (00000000, 6C4F4A60, 6C4F4A60, 6C4F4A60)****
****
0028BE28 610D6C9E (00000000, 0028BE34, 61183704, 00000006)****
****
0028BED8 610D6DF0 (00002FDC, 00000006, 00000000, 200223B0)****
****
0028BEF8 610D6E1C (00000006, 0028CE80, 00000000, 00000064)****
****
0028BF28 610D70A5 (00000000, 00000000, 00000002, 00000001)****
****
0028BFC8 6110D4E5 (200217D0, 0028CC5C, 0028CC50, 00000000)****
****
0028CC88 00401C2D (0000002F, 00000000, 6127390C, 61006F58)****
****
0028CD28 61006F58 (00000000, 0028CD78, 61006550, 0000000A)****
****
End of stack trace****
** **
How does one make sense of this?
I usually use gdb to help me see what's going on when I have a core file. I assume that since you mentioned gmake before you probably have gdb. If not, any system's normal debugger, like dbx, will make use of core files. $ gdb prog-name core-name Will load the core. The most useful command for me is "bt" ("where" under dbx), which shows you the call stack of the current thread. Cheers, Will
****
** **
Cheers****
** **
Ted****
** **
*From:* boost-users-bounces@lists.boost.org [mailto: boost-users-bounces@lists.boost.org] *On Behalf Of *Will Mason *Sent:* March-25-12 2:38 PM
*To:* boost-users@lists.boost.org *Subject:* Re: [Boost-users] Mystery exception.****
** **
Hi, Ted,****
** **
2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely).****
** **
It sounds like you haven't looked at the core file. You don't have to wonder where it is crashing if it produces a core file. That's what they are for.****
** **
Cheers,****
Will****
** **
On Sun, Mar 25, 2012 at 12:00 PM, Ted Byers <r.ted.byers@gmail.com> wrote: ****
Hi Sven,****
****
Thanks for this. ****
****
****
Second, in my first post, the problem was due to some unpleasant behaviour of Gnu make I wasn't aware of that resulting in a certain object file not being remade even though the source for it had changed (actually, I don't know if it is in make itself or a bug in my suite of make files - something to be investigated further - doing make realclean followed by make solved that). My current problem is something else, probably due to how memory is handled either in GSL or in boost::shared_array, but maybe something more subtle.****
****
I had left the comments in place to show alternatives I had tried. It is no surprise that compiling would fail if they were uncommented.****
****
I have now changed regressionPCA back to the way I had intended it to be in the first place.****
****
Here is the header:****
****
#ifndef REG_CLASS_H****
#define REG_CLASS_H****
****
#include <iosfwd>****
#include <vector>****
#include <gsl/gsl_linalg.h>****
#include <boost/smart_ptr/shared_array.hpp>****
****
class regressionPCA {****
private:****
unsigned int nrows, ncols;****
boost::shared_array<double> B, Y, U, V, S;****
regressionPCA(void) {}; // makes default construction impossible****
public:****
regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&);****
void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&);****
inline void setNrows(unsigned int v) { nrows = v;};****
inline void setNcols(unsigned int v) { ncols = v;};****
inline unsigned int getNrows(void) const { return nrows; };****
inline unsigned int getNcols(void) const { return ncols; };****
};****
****
#endif****
****
And here is the implementation:****
****
#include "reg.class.h"****
****
#include <iostream>****
#include <algorithm>****
#include <gsl/gsl_linalg.h>****
****
regressionPCA::regressionPCA(const std::vector<std::vector<double> >&data, ****
const std::vector<double>& Ydata) {****
Reset(data,Ydata);****
}****
****
void regressionPCA::Reset(const std::vector<std::vector<double> >&data, ** **
const std::vector<double>& Ydata) {****
unsigned int r(0),c(0),n(0);****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
r = data.size();****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
c = data[0].size();****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
setNrows(r);****
setNcols(c);****
n = r * c;****
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;*** *
B.reset(new double[c]);****
Y.reset(new double[r]); ****
U.reset(new double[n]);****
V.reset(new double[c*c]);****
S.reset(new double[c]);****
double* Btmp = B.get();****
double* Ytmp = Y.get();****
double* Utmp = U.get();****
double* Vtmp = V.get();****
double* Stmp = S.get();****
double *bptr = Utmp;****
std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end();****
while (it != end) {****
bptr = std::copy(it->begin(), it->end(),bptr);****
++it;****
}****
bptr = Ytmp;****
std::copy(Ydata.begin(),Ydata.end(),bptr);****
gsl_matrix_view Um = gsl_matrix_view_array(Utmp, getNrows(), getNcols()); ****
gsl_vector_view Ym = gsl_vector_view_array(Ytmp, getNrows());****
gsl_vector_view Bm = gsl_vector_view_array(Btmp, getNcols());****
gsl_vector_view Sm = gsl_vector_view_array(Stmp, getNcols());****
gsl_matrix_view Vm = gsl_matrix_view_array(Vtmp, getNcols(), getNcols()); ****
gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector);****
gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector); ****
std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl;****
std::cout << std::endl << std::endl << "V = " << std::endl;****
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl;****
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl;****
std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl;****
};****
****
Obviously a work in progress as I need to create data members to store the result of the analysis, and member functions to pass the results back to the calling code. I also need to get and analyse the residuals….****
****
Here is function main:****
****
#include <iostream>****
#include <vector>****
#include "data.generator.h"****
#include "reg.class.h"****
#include <boost/smart_ptr/shared_ptr.hpp>****
****
int main(int argc, char* argv[]) {****
basicGenerator bg;****
std::cout << "Sample size: " << bg.get_sampleSize() << std::endl;****
bg.makeData();****
std::vector<std::vector<double> > x;****
std::vector<double> y;****
bg.getDataForRegression(x,y);****
unsigned int imax = y.size();****
for (unsigned int i = 0 ; i < imax ; i++) {****
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;****
}****
std::cout << "==================================================================" << std::endl;****
regressionPCA rpca(x,y);****
std::cout << "==================================================================" << std::endl;****
boost::shared_ptr<regressionPCA> prpca;****
for (unsigned int j = 0 ; j < 25 ; j++) {****
std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl;****
bg.makeData();****
bg.getDataForRegression(x,y);****
/* for (unsigned int i = 0 ; i < imax ; i++) {****
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;****
}*/****
prpca.reset(new regressionPCA(x,y));****
std::cout << "==================================================================" << std::endl;****
}****
return 0;****
}****
****
The following output shows that cleaning up the declaration and definition has not changed anything:****
****
94 -1.86323 -1.90867 -1.35118****
95 0.907604 1.14917 0.621669****
96 2.1166 1.06194 1.1703****
97 0.159543 0.14446 -0.665135****
98 -0.508617 -0.370597 -0.703225****
99 2.69086 2.75267 1.40633****
==================================================================****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
****
Sv = 18.3225 4.69155****
****
V =****
0.695362 -0.718659****
0.718659 0.695362****
****
Beta = 0.693195 0.627794****
==================================================================****
Run #: 1****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
****
Sv = 14.1699 10.7091****
****
V =****
0.49497 -0.86891****
0.86891 0.49497****
****
Beta = 0.476181 0.391545****
==================================================================****
****
Run #: 2****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
****
Sv = 18.3225 4.69155****
****
V =****
0.695362 -0.718659****
0.718659 0.695362****
****
Beta = 0.693195 0.627794****
Aborted (core dumped)****
****
Ted@Ted-acer-i7w7 ~/New.System/tests****
$****
****
There are a couple things I see.****
****
1) the last statement successfully executed was the last statement of my Reset function. It then returns to function main, and it's nect statement produces the line of '+' symbols, and this is not successfully executed. So, something bad is happening between the end of the function and the return to function main.****
2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely).****
3) It must be something subtle, as I get one execution of the analysis done in Reset, as shown in the first analysis reported by 'rpca', and then I get two complete passes through my loop over j before it crashes. I am baffled as to even how I determine whether it is something I have done wrong with GSL or with boost::shared_array.****
****
But here is an experiment I tried, let's see what you make of this. I changed my main loop to use:****
****
rpca.Reset(x,y);****
****
instead of ****
****
prpca.reset(new regressionPCA(x,y));****
****
That is, I used the object I'd made on the stack, instead of the one(s) made on the heap. I then added " std::cout << "Flag 1" << std::endl << std::flush;" right after I invoked boost::shared_array's reset, and " std::cout << "Flag 2" << std::endl << std::flush;" right after I copy new data to these arrays. Here is the result:****
****
98 -0.508617 -0.370597 -0.703225****
99 2.69086 2.75267 1.40633****
==================================================================****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
Flag 1****
Flag 2****
****
****
Sv = 18.3225 4.69155****
****
****
V =****
0.695362 -0.718659****
0.718659 0.695362****
****
****
Beta = 0.693195 0.627794****
==================================================================****
****
****
Run #: 1****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
Flag 1****
Flag 2****
****
****
Sv = 14.1699 10.7091****
****
****
V =****
0.49497 -0.86891****
0.86891 0.49497****
****
****
Beta = 0.476181 0.391545****
==================================================================****
****
****
Run #: 2****
r: 0 c: 0 n: 0****
r: 100 c: 0 n: 0****
r: 100 c: 2 n: 0****
r: 100 c: 2 n: 200****
0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack)****
Segmentation fault (core dumped)****
****
Ted@Ted-acer-i7w7 ~/New.System/tests****
$****
****
****
Do you notice the change?****
****
Instead of finishing the second analysis in the loop, it crashes after I print the dimensions of the input matrix and vector, at some point in resetting one of the boost::shared_array objects. How do I determine whether this is a bug in boost::shared_array or some bad interaction between boost::shared_array and GSL?****
****
****
Cheers****
****
Ted****
****
*From:* boost-users-bounces@lists.boost.org [mailto: boost-users-bounces@lists.boost.org] *On Behalf Of *Sven Steckmann *Sent:* March-25-12 4:13 AM *To:* boost-users@lists.boost.org *Subject:* Re: [Boost-users] Mystery exception.****
****
Hi Ted,
****
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users****
** **
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Will, this was compiled using gcc, but even though the end of the output says the core was dumped, it only seems to produce a stackdump file, and gdb says that that is not a core dump file, and does nothing with it. Do I have to change the compile or link flags to have it produce a core dump file? Cheers Ted From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Will Mason Sent: March-25-12 5:05 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Mystery exception. Hi, Ted, On Sun, Mar 25, 2012 at 2:06 PM, Ted Byers <r.ted.byers@gmail.com> wrote: As an aside, does anyone know how to tell MS Outlook not to top-post? Anyway, Hi Will, Thanks, I would if I knew how to make sense of it. Here is what is in the latest stackdump: Exception: STATUS_ACCESS_VIOLATION at eip=6110D500 eax=20024D68 ebx=00000338 ecx=3FBBDE84 edx=20022070 esi=200223A8 edi=A9AE95F4 ebp=1ED48072 esp=0028BD00 program=C:\cygwin\home\Ted\New.System\tests\test.pca.reg.gsl.exe, pid 7888, thread main cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B Stack trace: Frame Function Args 0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack) I look at it and I don't know what to make of what it is telling me. How can I turn an of those values into something meaningful? And the other one is even less intelligible: Stack trace: Frame Function Args 0028BBA4 75961194 (00000104, 0000EA60, 00000000, 0028BCD8) 0028BBB8 75961148 (00000104, 0000EA60, 000000A4, 0028BCB4) 0028BCD8 610D9339 (00000000, 0028BDF4, 0028BD08, 611352F4) 0028BDC8 610D67CE (00000000, 6C4F4A60, 6C4F4A60, 6C4F4A60) 0028BE28 610D6C9E (00000000, 0028BE34, 61183704, 00000006) 0028BED8 610D6DF0 (00002FDC, 00000006, 00000000, 200223B0) 0028BEF8 610D6E1C (00000006, 0028CE80, 00000000, 00000064) 0028BF28 610D70A5 (00000000, 00000000, 00000002, 00000001) 0028BFC8 6110D4E5 (200217D0, 0028CC5C, 0028CC50, 00000000) 0028CC88 00401C2D (0000002F, 00000000, 6127390C, 61006F58) 0028CD28 61006F58 (00000000, 0028CD78, 61006550, 0000000A) End of stack trace How does one make sense of this? I usually use gdb to help me see what's going on when I have a core file. I assume that since you mentioned gmake before you probably have gdb. If not, any system's normal debugger, like dbx, will make use of core files. $ gdb prog-name core-name Will load the core. The most useful command for me is "bt" ("where" under dbx), which shows you the call stack of the current thread. Cheers, Will
Hi, Ted, On Sun, Mar 25, 2012 at 3:23 PM, Ted Byers <r.ted.byers@gmail.com> wrote:
Hi Will, ****
** **
this was compiled using gcc, but even though the end of the output says the core was dumped, it only seems to produce a stackdump file, and gdb says that that is not a core dump file, and does nothing with it. Do I have to change the compile or link flags to have it produce a core dump file?
You probably have to enable core dumps with: $ ulimit -c unlimited Cheers, Will
Since you're asking folks to help you debug a crash and which tools to use, it would be helpful if you posted some information about the toolset you're using for compilation and the target platform. Just based on things I've read in this thread, I'm guessing you're using cygwin or mingw on windows. If that's the case, one thing I would suggest is that you pick a more mainstream development system, i.e., either windows with visual studio or linux with gcc et. al. and work with the code there. The tools will be better. On Sun, Mar 25, 2012 at 5:30 PM, Will Mason <willchido@gmail.com> wrote:
Hi, Ted,
On Sun, Mar 25, 2012 at 3:23 PM, Ted Byers <r.ted.byers@gmail.com> wrote:
Hi Will, ****
** **
this was compiled using gcc, but even though the end of the output says the core was dumped, it only seems to produce a stackdump file, and gdb says that that is not a core dump file, and does nothing with it. Do I have to change the compile or link flags to have it produce a core dump file?
You probably have to enable core dumps with:
$ ulimit -c unlimited
Cheers, Will
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Chris Cleeland
Hi Ted, I had a long look to your sources, but I am unable to find any problems there. But I think there is still one, maybe also inside the gsl if something has the wrong size. Speaking from my experience, I would not look for problems with the shared_ptr stuff. I am using it very often and as long as I had problems, these problems had their source in my program :) Do you know valgrind? In cases of memory corruption, this can be a valuable tool too. Cheers, Sven On 03/25/2012 08:00 PM, Ted Byers wrote:
Hi Sven,
Thanks for this.
Second, in my first post, the problem was due to some unpleasant behaviour of Gnu make I wasn't aware of that resulting in a certain object file not being remade even though the source for it had changed (actually, I don't know if it is in make itself or a bug in my suite of make files - something to be investigated further - doing make realclean followed by make solved that). My current problem is something else, probably due to how memory is handled either in GSL or in boost::shared_array, but maybe something more subtle.
I had left the comments in place to show alternatives I had tried. It is no surprise that compiling would fail if they were uncommented.
I have now changed regressionPCA back to the way I had intended it to be in the first place.
Here is the header:
#ifndef REG_CLASS_H
#define REG_CLASS_H
#include <iosfwd>
#include <vector>
#include <gsl/gsl_linalg.h>
#include <boost/smart_ptr/shared_array.hpp>
class regressionPCA {
private:
unsigned int nrows, ncols;
boost::shared_array<double> B, Y, U, V, S;
regressionPCA(void) {}; // makes default construction impossible
public:
regressionPCA(const std::vector<std::vector<double> >&, const std::vector<double>&);
void Reset(const std::vector<std::vector<double> >&, const std::vector<double>&);
inline void setNrows(unsigned int v) { nrows = v;};
inline void setNcols(unsigned int v) { ncols = v;};
inline unsigned int getNrows(void) const { return nrows; };
inline unsigned int getNcols(void) const { return ncols; };
};
#endif
And here is the implementation:
#include "reg.class.h"
#include <iostream>
#include <algorithm>
#include <gsl/gsl_linalg.h>
regressionPCA::regressionPCA(const std::vector<std::vector<double>
&data,
const std::vector<double>& Ydata) {
Reset(data,Ydata);
}
void regressionPCA::Reset(const std::vector<std::vector<double> >&data,
const std::vector<double>& Ydata) {
unsigned int r(0),c(0),n(0);
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;
r = data.size();
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;
c = data[0].size();
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;
setNrows(r);
setNcols(c);
n = r * c;
std::cout << "r: " << r << "\tc: " << c << "\tn: " << n << std::endl;
B.reset(new double[c]);
Y.reset(new double[r]);
U.reset(new double[n]);
V.reset(new double[c*c]);
S.reset(new double[c]);
double* Btmp = B.get();
double* Ytmp = Y.get();
double* Utmp = U.get();
double* Vtmp = V.get();
double* Stmp = S.get();
double *bptr = Utmp;
std::vector<std::vector<double> >::const_iterator it = data.begin(), end = data.end();
while (it != end) {
bptr = std::copy(it->begin(), it->end(),bptr);
++it;
}
bptr = Ytmp;
std::copy(Ydata.begin(),Ydata.end(),bptr);
gsl_matrix_view Um = gsl_matrix_view_array(Utmp, getNrows(), getNcols());
gsl_vector_view Ym = gsl_vector_view_array(Ytmp, getNrows());
gsl_vector_view Bm = gsl_vector_view_array(Btmp, getNcols());
gsl_vector_view Sm = gsl_vector_view_array(Stmp, getNcols());
gsl_matrix_view Vm = gsl_matrix_view_array(Vtmp, getNcols(), getNcols());
gsl_linalg_SV_decomp_jacobi(&Um.matrix,&Vm.matrix,&Sm.vector);
gsl_linalg_SV_solve(&Um.matrix,&Vm.matrix,&Sm.vector,&Ym.vector,&Bm.vector);
std::cout << std::endl << std::endl << "Sv = " << gsl_vector_get(&Sm.vector,0) << "\t" << gsl_vector_get(&Sm.vector,1) << std::endl;
std::cout << std::endl << std::endl << "V = " << std::endl;
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,0,0) << "\t" << gsl_matrix_get(&Vm.matrix,0,1) << std::endl;
std::cout << "\t" << gsl_matrix_get(&Vm.matrix,1,0) << "\t" << gsl_matrix_get(&Vm.matrix,1,1) << std::endl;
std::cout << std::endl << std::endl << "Beta = " << gsl_vector_get(&Bm.vector,0) << "\t" << gsl_vector_get(&Bm.vector,1) << std::endl;
};
Obviously a work in progress as I need to create data members to store the result of the analysis, and member functions to pass the results back to the calling code. I also need to get and analyse the residuals....
Here is function main:
#include <iostream>
#include <vector>
#include "data.generator.h"
#include "reg.class.h"
#include <boost/smart_ptr/shared_ptr.hpp>
int main(int argc, char* argv[]) {
basicGenerator bg;
std::cout << "Sample size: " << bg.get_sampleSize() << std::endl;
bg.makeData();
std::vector<std::vector<double> > x;
std::vector<double> y;
bg.getDataForRegression(x,y);
unsigned int imax = y.size();
for (unsigned int i = 0 ; i < imax ; i++) {
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;
}
std::cout << "==================================================================" << std::endl;
regressionPCA rpca(x,y);
std::cout << "==================================================================" << std::endl;
boost::shared_ptr<regressionPCA> prpca;
for (unsigned int j = 0 ; j < 25 ; j++) {
std::cout << std::endl << std::endl << "Run #: " << (j + 1) << std::endl;
bg.makeData();
bg.getDataForRegression(x,y);
/* for (unsigned int i = 0 ; i < imax ; i++) {
std::cout << i << "\t" << y[i] << "\t" << x[i][0] << "\t" << x[i][1] << std::endl;
}*/
prpca.reset(new regressionPCA(x,y));
std::cout << "==================================================================" << std::endl;
}
return 0;
}
The following output shows that cleaning up the declaration and definition has not changed anything:
94 -1.86323 -1.90867 -1.35118
95 0.907604 1.14917 0.621669
96 2.1166 1.06194 1.1703
97 0.159543 0.14446 -0.665135
98 -0.508617 -0.370597 -0.703225
99 2.69086 2.75267 1.40633
==================================================================
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
Sv = 18.3225 4.69155
V =
0.695362 -0.718659
0.718659 0.695362
Beta = 0.693195 0.627794
==================================================================
Run #: 1
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
Sv = 14.1699 10.7091
V =
0.49497 -0.86891
0.86891 0.49497
Beta = 0.476181 0.391545
==================================================================
Run #: 2
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
Sv = 18.3225 4.69155
V =
0.695362 -0.718659
0.718659 0.695362
Beta = 0.693195 0.627794
Aborted (core dumped)
Ted@Ted-acer-i7w7 ~/New.System/tests
$
There are a couple things I see.
1) the last statement successfully executed was the last statement of my Reset function. It then returns to function main, and it's nect statement produces the line of '+' symbols, and this is not successfully executed. So, something bad is happening between the end of the function and the return to function main.
2) if I uncomment the inner loop, over I, and comment out ' prpca.reset(new regressionPCA(x,y));', that loop runs to completion. Thus, we can exclude bg from having any role in this core dump. It must be something in either gsl or boost::shared_array, or maybe boost::shared_ptr (but the core dump happens too soon to be in shared_ptr's reset, unless the output to std::cout is buffered and contents of the buffer are lost in the core dump before they can be printed, but this is unlikely).
3) It must be something subtle, as I get one execution of the analysis done in Reset, as shown in the first analysis reported by 'rpca', and then I get two complete passes through my loop over j before it crashes. I am baffled as to even how I determine whether it is something I have done wrong with GSL or with boost::shared_array.
But here is an experiment I tried, let's see what you make of this. I changed my main loop to use:
rpca.Reset(x,y);
instead of
prpca.reset(new regressionPCA(x,y));
That is, I used the object I'd made on the stack, instead of the one(s) made on the heap. I then added " std::cout << "Flag 1" << std::endl << std::flush;" right after I invoked boost::shared_array's reset, and " std::cout << "Flag 2" << std::endl << std::flush;" right after I copy new data to these arrays. Here is the result:
98 -0.508617 -0.370597 -0.703225
99 2.69086 2.75267 1.40633
==================================================================
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
Flag 1
Flag 2
Sv = 18.3225 4.69155
V =
0.695362 -0.718659
0.718659 0.695362
Beta = 0.693195 0.627794
==================================================================
Run #: 1
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
Flag 1
Flag 2
Sv = 14.1699 10.7091
V =
0.49497 -0.86891
0.86891 0.49497
Beta = 0.476181 0.391545
==================================================================
Run #: 2
r: 0 c: 0 n: 0
r: 100 c: 0 n: 0
r: 100 c: 2 n: 0
r: 100 c: 2 n: 200
0 [main] test.pca.reg.gsl 7888 exception::handle: Error while dumping state (probably corrupted stack)
Segmentation fault (core dumped)
Ted@Ted-acer-i7w7 ~/New.System/tests
$
Do you notice the change?
Instead of finishing the second analysis in the loop, it crashes after I print the dimensions of the input matrix and vector, at some point in resetting one of the boost::shared_array objects. How do I determine whether this is a bug in boost::shared_array or some bad interaction between boost::shared_array and GSL?
Cheers
Ted
*From:*boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] *On Behalf Of *Sven Steckmann *Sent:* March-25-12 4:13 AM *To:* boost-users@lists.boost.org *Subject:* Re: [Boost-users] Mystery exception.
Hi Ted,
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Chris Cleeland
-
Sven Steckmann
-
Ted Byers
-
Will Mason