Segmentation fault in boost::odeint my_vector.cpp example

Bociek

I am trying to test the my_vector.cpp program from boost::odeint examples but without any success. I get Segmentation Fault when I run the program. Compilation: g++ -std=c++14 -o my_vector my_vector.cpp

It runs with std::vector<> instead of my_vector for the state_type. I suspect there is something wrong with is_resizable but I don't know how to fix it.

Here is the code for my_vector.cpp which you can get from github

/*
* Copyright 2011-2012 Mario Mulansky
* Copyright 2012-2013 Karsten Ahnert
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or
* copy at http://www.boost.org/LICENSE_1_0.txt)
*
* Example for self defined vector type.
*/

#include <vector>

#include <boost/numeric/odeint.hpp>

//[my_vector
template< int MAX_N >
class my_vector
{
    typedef std::vector< double > vector;

public:
    typedef vector::iterator iterator;
    typedef vector::const_iterator const_iterator;

public:
    my_vector( const size_t N )
        : m_v( N )
    { 
        m_v.reserve( MAX_N );
    }

    my_vector()
        : m_v()
    {
        m_v.reserve( MAX_N );
    }

// ... [ implement container interface ]
//]
    const double & operator[]( const size_t n ) const
    { return m_v[n]; }

    double & operator[]( const size_t n )
    { return m_v[n]; }

    iterator begin()
    { return m_v.begin(); }

    const_iterator begin() const
    { return m_v.begin(); }

    iterator end()
    { return m_v.end(); }

    const_iterator end() const
    { return m_v.end(); }

    size_t size() const 
    { return m_v.size(); }

    void resize( const size_t n )
    { m_v.resize( n ); }

private:
    std::vector< double > m_v;

};

//[my_vector_resizeable
// define my_vector as resizeable

namespace boost { namespace numeric { namespace odeint {

template<size_t N>
struct is_resizeable< my_vector<N> >
{
    typedef boost::true_type type;
    static const bool value = type::value;
};

} } }
//]


typedef my_vector<3> state_type;

void lorenz( const state_type &x , state_type &dxdt , const double t )
{
    const double sigma( 10.0 );
    const double R( 28.0 );
    const double b( 8.0 / 3.0 );

    dxdt[0] = sigma * ( x[1] - x[0] );
    dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
    dxdt[2] = -b * x[2] + x[0] * x[1];
}

using namespace boost::numeric::odeint;

int main()
{
    state_type x(3);
    x[0] = 5.0 ; x[1] = 10.0 ; x[2] = 10.0;

    // my_vector works with range_algebra as it implements 
    // the required parts of a container interface
    // no further work is required

    integrate_const( runge_kutta4< state_type >() , lorenz , x , 0.0 , 10.0 , 0.1 );
}
mariomulansky

I can reproduce this with g++-4.8.

I've opened an issue on this at the odeint github repository: https://github.com/headmyshoulder/odeint-v2/issues/180

edit:

I've found the problem and solved it: https://github.com/headmyshoulder/odeint-v2/commit/965a8e456d5e9dff47f0121a4d12aac8c845ea5e

The problem was an inconsistent template parameter type that prevented the is_resizeable definition to work properly, as expected by the op already.

changing the my_ vector template parameter type to size_t fixes this:

template<size_t N>
class my_vector

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Segmentation fault in boost::odeint my_vector.cpp example

From Dev

Segmentation fault on using boost syslog and cpp-netlib

From Dev

boost::asio example code segmentation fault in Visual Studio 2013

From Dev

Debugging segmentation fault with backtrace in cpp

From Dev

boost python threading segmentation fault

From Dev

segmentation-fault with boost::polygon

From Dev

segmentation fault on vector

From Dev

Vector Iterator (Segmentation fault)

From Dev

Segmentation fault in x86 example program

From Dev

Using Boost::odeint with Eigen::Matrix as state vector

From Dev

Using Boost::odeint with Eigen::Matrix as state vector

From Dev

Error C2309 in boost odeint package example code

From Dev

C++ Segmentation fault with vector

From Dev

Going over a vector (Segmentation fault)

From Dev

Segmentation fault in std::vector destructor

From Dev

C++ Segmentation fault with vector

From Dev

Pointer of a struct with vector - Segmentation Fault

From Dev

C++ Segmentation fault vector

From Dev

Getting segmentation fault (vector declaration)

From Dev

Segmentation fault while calling cpp function from Python

From Dev

Segmentation fault in a vector<vector<Point> > in opencv

From Dev

Segmentation fault on class destruction with boost::timer as a member of the class with periodic invocation

From Dev

c++ boost python list extract causing Segmentation fault

From Dev

Boost.Asio: Segmentation fault when sending too big message

From Dev

Segmentation fault(core dumped) in multi threading using boost threads

From Dev

CRASH: Segmentation fault: Boost serialization loading - calling constructor with null

From Dev

Boost.spirit segmentation fault when parsing with composite grammar

From Dev

Server connection example head first c (Segmentation fault (`core' generado))

From Dev

Segmentation fault while declaring an iterator in c++ example of leveldb

Related Related

  1. 1

    Segmentation fault in boost::odeint my_vector.cpp example

  2. 2

    Segmentation fault on using boost syslog and cpp-netlib

  3. 3

    boost::asio example code segmentation fault in Visual Studio 2013

  4. 4

    Debugging segmentation fault with backtrace in cpp

  5. 5

    boost python threading segmentation fault

  6. 6

    segmentation-fault with boost::polygon

  7. 7

    segmentation fault on vector

  8. 8

    Vector Iterator (Segmentation fault)

  9. 9

    Segmentation fault in x86 example program

  10. 10

    Using Boost::odeint with Eigen::Matrix as state vector

  11. 11

    Using Boost::odeint with Eigen::Matrix as state vector

  12. 12

    Error C2309 in boost odeint package example code

  13. 13

    C++ Segmentation fault with vector

  14. 14

    Going over a vector (Segmentation fault)

  15. 15

    Segmentation fault in std::vector destructor

  16. 16

    C++ Segmentation fault with vector

  17. 17

    Pointer of a struct with vector - Segmentation Fault

  18. 18

    C++ Segmentation fault vector

  19. 19

    Getting segmentation fault (vector declaration)

  20. 20

    Segmentation fault while calling cpp function from Python

  21. 21

    Segmentation fault in a vector<vector<Point> > in opencv

  22. 22

    Segmentation fault on class destruction with boost::timer as a member of the class with periodic invocation

  23. 23

    c++ boost python list extract causing Segmentation fault

  24. 24

    Boost.Asio: Segmentation fault when sending too big message

  25. 25

    Segmentation fault(core dumped) in multi threading using boost threads

  26. 26

    CRASH: Segmentation fault: Boost serialization loading - calling constructor with null

  27. 27

    Boost.spirit segmentation fault when parsing with composite grammar

  28. 28

    Server connection example head first c (Segmentation fault (`core' generado))

  29. 29

    Segmentation fault while declaring an iterator in c++ example of leveldb

HotTag

Archive