使用较大的boost-matrices时出现分段错误(核心转储)

时间:2013-11-07 07:22:33

标签: c++ boost segmentation-fault

如果我运行代码,则会发生错误:分段错误(核心转储)

如果我减少头文件中MatSamplesDimM的尺寸(例如从300000到30000)或者我只是在主文件中声明Matrix1而不是Matrix2,则问题不存在。问题与我运行代码的环境无关(eclipse或终端)。

你有什么想法吗?非常感谢您的帮助!

StrangeBehavior.cpp是我的主要文件:

// System includes
#include <iostream>
#include <fstream>   //fstream: Stream class to both read and write from/to files; for output

// Boost includes
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/math/distributions/normal.hpp>      //to create normal distribution
#include <vector>                                   // stl vector header
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>  //accumulator for mean, variance...
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/bind/bind.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>     // for using row()...
#include <boost/numeric/ublas/matrix_proxy.hpp>     // for using row()...
#include <boost/numeric/ublas/vector_expression.hpp>   // for using inner_prod
#include <boost/numeric/ublas/matrix_expression.hpp>   // for using inner_prod, element_div
#include <boost/math/special_functions/gamma.hpp> // for Gamma function

#include "ParameterDeclaration.hpp"

using namespace std; // saves us typing std:: before vector


int main() {

    std::cout << "Starting " << std::endl;

          MatSamplesDimM    Matrix1;
          MatSamplesDimM    Matrix2;

    std::cout << "Finishing" << std::endl;
    return 0;
}

和ParameterDeclaration.hpp我的标题 - 文件:

#ifndef parameter_
#define parameter_


#include <iostream>

namespace ublas = boost::numeric::ublas;

typedef     ublas::bounded_matrix<double,300000,2>        MatSamplesDimM;


#endif

1 个答案:

答案 0 :(得分:0)

尝试使用堆而不是堆栈。这意味着使用 new 分配矩阵。