37 #include "TinyFadET/tfad.h"
45 void FAD::error(
const char *msg) {
46 std::cout << msg << std::endl;
52 y = (x1*x2 +
sin(x1)/x2);
57 double& y,
double* ydot) {
61 double t1 = x2 + c/x2;
62 double t2 = x1 - t/x2;
64 for (
int i=0; i<10; i++)
65 ydot[i] = t1*x1dot[i] + t2*x2dot[i];
68 template <
typename FadType>
78 for (
int j=0; j<nderiv; j++) {
79 x1.fastAccessDx(j) = urand.
number();
80 x2.fastAccessDx(j) = urand.
number();
85 for (
int j=0; j<nloop; j++) {
97 double *x1dot, *x2dot, *ydot;
103 x1dot =
new double[nderiv];
104 x2dot =
new double[nderiv];
105 ydot =
new double[nderiv];
106 for (
int j=0; j<nderiv; j++) {
107 x1dot[j] = urand.
number();
108 x2dot[j] = urand.
number();
113 for (
int j=0; j<nloop; j++) {
121 int main(
int argc,
char* argv[]) {
131 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a single multiplication operation");
133 clp.
setOption(
"nderiv", &nderiv,
"Number of derivative components");
135 clp.
setOption(
"nloop", &nloop,
"Number of loops");
139 parseReturn= clp.
parse(argc, argv);
143 std::cout.setf(std::ios::scientific);
144 std::cout.precision(p);
145 std::cout <<
"Times (sec) for nderiv = " << nderiv
146 <<
" nloop = " << nloop <<
": " << std::endl;
149 std::cout <<
"Analytic: " << std::setw(w) << ta << std::endl;
151 t = do_time< Sacado::Fad::SimpleFad<double> >(nderiv, nloop);
152 std::cout <<
"SimpleFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
154 t = do_time< FAD::TFad<10,double> >(nderiv, nloop);
155 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
157 t = do_time< FAD::Fad<double> >(nderiv, nloop);
158 std::cout <<
"Fad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
160 t = do_time< Sacado::Fad::SFad<double,10> >(nderiv, nloop);
161 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
163 t = do_time< Sacado::Fad::SLFad<double,10> >(nderiv, nloop);
164 std::cout <<
"SLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
166 t = do_time< Sacado::Fad::DFad<double> >(nderiv, nloop);
167 std::cout <<
"DFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
169 t = do_time< Sacado::ELRFad::SFad<double,10> >(nderiv, nloop);
170 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
172 t = do_time< Sacado::ELRFad::SLFad<double,10> >(nderiv, nloop);
173 std::cout <<
"ELRSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
175 t = do_time< Sacado::ELRFad::DFad<double> >(nderiv, nloop);
176 std::cout <<
"ELRDFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
178 t = do_time< Sacado::CacheFad::DFad<double> >(nderiv, nloop);
179 std::cout <<
"CacheFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
181 t = do_time< Sacado::Fad::DVFad<double> >(nderiv, nloop);
182 std::cout <<
"DVFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
185 catch (std::exception& e) {
186 std::cout << e.what() << std::endl;
189 catch (
const char *s) {
190 std::cout << s << std::endl;
194 std::cout <<
"Caught unknown exception!" << std::endl;
double do_time_analytic(int nderiv, int nloop)
Sacado::Fad::DFad< double > FadType
void func1_and_deriv(int n, double x1, double x2, double *x1dot, double *x2dot, double &y, double *ydot)
ScalarT number()
Get random number.
void start(bool reset=false)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
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
void func1(const T &x1, const T &x2, T &y)