36 #include "Teuchos_Time.hpp" 37 #include "Teuchos_CommandLineProcessor.hpp" 47 #ifdef PACKAGE_BUGREPORT 48 #undef PACKAGE_BUGREPORT 53 #ifdef PACKAGE_TARNAME 54 #undef PACKAGE_TARNAME 56 #ifdef PACKAGE_VERSION 57 #undef PACKAGE_VERSION 62 #include "adolc/adouble.h" 63 #include "adolc/interfaces.h" 75 y = x1*x2 +
sin(x1)/x2;
78 template <
typename TaylorType>
88 for (
int j=0; j<=degree; j++) {
93 Teuchos::Time timer(
"mult",
false);
95 for (
int j=0; j<nloop; j++) {
100 return timer.totalElapsedTime() / nloop;
105 do_time_adolc(
int degree,
int nloop)
111 X[0] =
new double[degree+1];
112 X[1] =
new double[degree+1];
114 Y[0] =
new double[degree+1];
115 for (
int j=0; j<=degree; j++) {
116 X[0][j] = urand.number();
117 X[1][j] = urand.number();
129 Teuchos::Time timer(
"mult",
false);
131 for (
int j=0; j<nloop; j++) {
132 forward(0,1,2,degree,0,X,Y);
143 return timer.totalElapsedTime() / nloop;
147 do_time_adolc_retape(
int degree,
int nloop)
153 X[0] =
new double[degree+1];
154 X[1] =
new double[degree+1];
156 Y[0] =
new double[degree+1];
157 for (
int j=0; j<=degree; j++) {
158 X[0][j] = urand.number();
159 X[1][j] = urand.number();
164 Teuchos::Time timer(
"mult",
false);
166 for (
int j=0; j<nloop; j++) {
173 forward(0,1,2,degree,0,X,Y);
184 return timer.totalElapsedTime() / nloop;
188 int main(
int argc,
char* argv[]) {
197 Teuchos::CommandLineProcessor clp;
198 clp.setDocString(
"This program tests the speed of various forward mode AD implementations for a single multiplication operation");
200 clp.setOption(
"degree", °ree,
"Polynomial degree");
202 clp.setOption(
"nloop", &nloop,
"Number of loops");
205 Teuchos::CommandLineProcessor::EParseCommandLineReturn
206 parseReturn= clp.parse(argc, argv);
207 if(parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
210 std::cout.setf(std::ios::scientific);
211 std::cout.precision(p);
212 std::cout <<
"Times (sec) for degree = " << degree
213 <<
" nloop = " << nloop <<
": " << std::endl;
215 t = do_time< Sacado::Tay::Taylor<double> >(degree, nloop);
216 std::cout <<
"Taylor: " << std::setw(w) << t << std::endl;
218 t = do_time< Sacado::Tay::CacheTaylor<double> >(degree, nloop);
219 std::cout <<
"CacheTaylor: " << std::setw(w) << t << std::endl;
222 t = do_time_adolc(degree, nloop);
223 std::cout <<
"ADOL-C: " << std::setw(w) << t << std::endl;
224 t = do_time_adolc_retape(degree, nloop);
225 std::cout <<
"ADOL-C (retape): " << std::setw(w) << t << std::endl;
229 catch (std::exception& e) {
230 cout << e.what() << endl;
233 catch (
const char *s) {
238 cout <<
"Caught unknown exception!" << endl;
int main(int argc, char *argv[])
ScalarT number()
Get random number.
Sacado::Tay::Taylor< double > TaylorType
T & fastAccessCoeff(int i)
Returns degree i term without bounds checking.
double do_time(int degree, int nloop)
SimpleFad< ValueT > sin(const SimpleFad< ValueT > &a)
void func(const T &x1, const T &x2, T &y)