[ADOL-C] Combining Adolc and Boost::Units

João Leal joaoruileal at gmail.com
Thu Sep 15 11:19:03 EDT 2011


Hello!

Looking for some knowledge on how to combine adolc and boost::units (
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_units.html).
Has anyone attempted this?

The following program will exemplify the problem.

##########
#include <adolc/adouble.h>
#include <boost/units/systems/si.hpp>

int main(int argc, char **argv) {

    for (int i = 0; i < 9; i++) {
        boost::units::quantity<boost::units::si::length, adouble> a = 1 *
boost::units::si::meters;
        boost::units::quantity<boost::units::si::length, adouble> b = 2 *
boost::units::si::meters;
        boost::units::quantity<boost::units::si::length, adouble> c = 3 *
boost::units::si::meters;
        boost::units::quantity<boost::units::si::length, adouble> d = 4 *
boost::units::si::meters;
        boost::units::quantity<boost::units::si::volume, adouble>* x = new
boost::units::quantity<boost::units::si::volume, adouble>();

        *x = a * b * (c - d);

        std::cout << *x << endl;

        delete x;
    }

    return 1;
}
##########

Output with no compiler optimization on 64bit Linux (gcc 4.5.2):

##########
4(a) m^3
4(a) m^3
-2(a) m^3
-2(a) m^3
-2(a) m^3
-2(a) m^3
-2(a) m^3
-2(a) m^3
-2(a) m^3
##########

As can be seen by the output there is something fishy going on... the values
of the 1st two lines are wrong!

Unfortunately valgrind does not find anything wrong.
I am using boost 1.42 and adolc 2.1.12.

Any help would be appreciated.


Best regards,

Joao Leal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/adol-c/attachments/20110915/bb6ab451/attachment.html>


More information about the ADOL-C mailing list