Static function for large amount of contractors instanciation

Hi,

I would like to instantiate several thousand times the same contractor C, for example:

class C:ibex::Ctc {

  public:

  C(){};

  void contract(ibex::IntervalVector &box) {

    ibex::Variable v1(2);
    ibex::Variable v2(2);

    ibex::Function f(v1,v2,v1+v2);

    f.backward(box);

  }

}

In order to save memory and time, I would like to have the Function defined only once as a static member of the class:

class C:ibex::Ctc {

  public:

  C(){};

  static ibex::Function f;

  void contract(ibex::IntervalVector &box) { f.backward(box); }

}

ibex::Variable v1(2);
ibex::Variable v2(2);
ibex::Function C::f(v1,v2,v1+v2);

 

However, instantiation of global ibex::Variable throws a segmentation fault at execution.

For example, this minimalistic main file compiles and runs:

#include <ibex/ibex.h>

int main() { ibex::Variable v0(1); return 0; }

While this one compile but throws a segmentation fault at runtime:

#include <ibex/ibex.h>

ibex::Variable v0(1);

int main(){ return 0; }

 

Could you tell me where am I wrong?

Regards

Hi Jeremy,

Your last piece of code:

#include <ibex/ibex.h>

ibex::Variable v0(1);

int main(){return 0;}

does not throw a segmentation fault in my computer. Which version of the code are you using exactly?

It's a very good idea however to create the function once, statically. Note that you can avoid creating Variable object using string directly. The following program works:

#include "ibex.h"

using namespace std;
using namespace ibex;

class C : Ctc {
public:

    void contract(IntervalVector& box) {
        f.backward(Interval::ZERO,box);
    }

    static Function f;

};

Function C::f("v1","v2","v1+v2");

int main(){

    C c;

    IntervalVector box(2,Interval(-1,2));
    cout << "box before contraction:" << box << endl;
    c.contract(box);
    cout << "box after contraction:" << box << endl;

    return 0;

}


Output:

box before contraction:([-1, 2] ; [-1, 2])
box after contraction:([-1, 1] ; [-1, 1])

Regards,

Gilles

 

Hello Gilles,
thank you for your prompt reply.
For some reason, I don't get the segmentation fault anymore.
It may be that it was due to the order I was using when linking the libraries (soplex, prim, ibex), but I can't reproduce this message anymore...
Anyway, thank you!

You are welcome.

I think pkg-config is automatically ordering librairies correctly.

See comment here: http://www.ibex-lib.org/comment/6#comment-6

Regards,

Gilles