[ADOL-C] Combining Adolc and Boost::Units
Kshitij Kulshreshtha
kshitij at math.upb.de
Mon Sep 19 08:32:55 EDT 2011
Hello,
using Boost wrappers on adouble class is not supported.
This is because adouble class requires special handling of intermediate
results generated in an expression like a*b*(c-d) where first (c-d) is
computed then a*b and then these two intermediates multiplied at the
end. This special handling is done in a sister class of adouble called
adub inside ADOL-C. A wrapper around adouble has no knowledge of this
class and thus isn't able to handle intermediate results, thus
overwriting the last computed one in certain cases. In fact using ADOL-C
version 2.2.1 one can consistently get the wrong answer.
Without such a special handling of intermediate computations ADOL-C
would be extremely inefficient.
Regards.
Kshitij Kulshreshtha
As on 2011-09-15 17:19, João Leal did write:
> 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
>
>
> _______________________________________________
> ADOL-C mailing list
> ADOL-C at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/adol-c
--
Dr. Kshitij Kulshreshtha
Institut für Mathematik,
Universität Paderborn,
Warburger Straße 100,
33098 Paderborn.
Büro: A3.235
Privatanschrift:
Arnikaweg 62
33100 Paderborn.
More information about the ADOL-C
mailing list