25 #ifdef PACKAGE_BUGREPORT
26 #undef PACKAGE_BUGREPORT
31 #ifdef PACKAGE_TARNAME
32 #undef PACKAGE_TARNAME
34 #ifdef PACKAGE_VERSION
35 #undef PACKAGE_VERSION
40 #include "adolc/adouble.h"
41 #include "adolc/interfaces.h"
42 #include "adolc/taping.h"
54 y = x1*x2 +
sin(x1)/x2;
57 template <
typename TaylorType>
67 for (
int j=0; j<=degree; j++) {
74 for (
int j=0; j<nloop; j++) {
84 do_time_adolc(
int degree,
int nloop)
90 X[0] =
new double[degree+1];
91 X[1] =
new double[degree+1];
93 Y[0] =
new double[degree+1];
94 for (
int j=0; j<=degree; j++) {
95 X[0][j] = urand.number();
96 X[1][j] = urand.number();
110 for (
int j=0; j<nloop; j++) {
111 forward(0,1,2,degree,0,X,Y);
122 return timer.totalElapsedTime() / nloop;
126 do_time_adolc_retape(
int degree,
int nloop)
132 X[0] =
new double[degree+1];
133 X[1] =
new double[degree+1];
135 Y[0] =
new double[degree+1];
136 for (
int j=0; j<=degree; j++) {
137 X[0][j] = urand.number();
138 X[1][j] = urand.number();
145 for (
int j=0; j<nloop; j++) {
152 forward(0,1,2,degree,0,X,Y);
163 return timer.totalElapsedTime() / nloop;
167 int main(
int argc,
char* argv[]) {
177 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a single multiplication operation");
179 clp.
setOption(
"degree", °ree,
"Polynomial degree");
181 clp.
setOption(
"nloop", &nloop,
"Number of loops");
185 parseReturn= clp.
parse(argc, argv);
189 std::cout.setf(std::ios::scientific);
190 std::cout.precision(p);
191 std::cout <<
"Times (sec) for degree = " << degree
192 <<
" nloop = " << nloop <<
": " << std::endl;
194 t = do_time< Sacado::Tay::Taylor<double> >(degree, nloop);
195 std::cout <<
"Taylor: " << std::setw(w) << t << std::endl;
197 t = do_time< Sacado::Tay::CacheTaylor<double> >(degree, nloop);
198 std::cout <<
"CacheTaylor: " << std::setw(w) << t << std::endl;
201 t = do_time_adolc(degree, nloop);
202 std::cout <<
"ADOL-C: " << std::setw(w) << t << std::endl;
203 t = do_time_adolc_retape(degree, nloop);
204 std::cout <<
"ADOL-C (retape): " << std::setw(w) << t << std::endl;
208 catch (std::exception& e) {
209 cout << e.what() << endl;
212 catch (
const char *s) {
217 cout <<
"Caught unknown exception!" << endl;
ScalarT number()
Get random number.
Sacado::Tay::Taylor< double > TaylorType
void start(bool reset=false)
T & fastAccessCoeff(int i)
Returns degree i term without bounds checking.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
double do_time(int nderiv, int nloop)
void setDocString(const char doc_string[])
double totalElapsedTime(bool readCurrentTime=false) const
const T func(int n, T *x)