15 #include "TinyFadET/tfad.h"
23 void FAD::error(
const char *msg) {
24 std::cout << msg << std::endl;
30 y = (x1*x2 +
sin(x1)/x2);
35 double&
y,
double* ydot) {
39 double t1 = x2 + c/x2;
40 double t2 = x1 - t/x2;
42 for (
int i=0;
i<10;
i++)
43 ydot[
i] = t1*x1dot[
i] + t2*x2dot[
i];
46 template <
typename FadType>
56 for (
int j=0; j<nderiv; j++) {
57 x1.fastAccessDx(j) = urand.
number();
58 x2.fastAccessDx(j) = urand.
number();
63 for (
int j=0; j<nloop; j++) {
75 double *x1dot, *x2dot, *ydot;
81 x1dot =
new double[nderiv];
82 x2dot =
new double[nderiv];
83 ydot =
new double[nderiv];
84 for (
int j=0; j<nderiv; j++) {
91 for (
int j=0; j<nloop; j++) {
99 int main(
int argc,
char* argv[]) {
109 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a single multiplication operation");
111 clp.
setOption(
"nderiv", &nderiv,
"Number of derivative components");
113 clp.
setOption(
"nloop", &nloop,
"Number of loops");
117 parseReturn= clp.
parse(argc, argv);
121 std::cout.setf(std::ios::scientific);
122 std::cout.precision(p);
123 std::cout <<
"Times (sec) for nderiv = " << nderiv
124 <<
" nloop = " << nloop <<
": " << std::endl;
127 std::cout <<
"Analytic: " << std::setw(w) << ta << std::endl;
129 t = do_time< Sacado::Fad::SimpleFad<double> >(nderiv, nloop);
130 std::cout <<
"SimpleFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
132 t = do_time< FAD::TFad<10,double> >(nderiv, nloop);
133 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
135 t = do_time< FAD::Fad<double> >(nderiv, nloop);
136 std::cout <<
"Fad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
138 t = do_time< Sacado::Fad::SFad<double,10> >(nderiv, nloop);
139 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
141 t = do_time< Sacado::Fad::SLFad<double,10> >(nderiv, nloop);
142 std::cout <<
"SLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
144 t = do_time< Sacado::Fad::DFad<double> >(nderiv, nloop);
145 std::cout <<
"DFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
147 t = do_time< Sacado::ELRFad::SFad<double,10> >(nderiv, nloop);
148 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
150 t = do_time< Sacado::ELRFad::SLFad<double,10> >(nderiv, nloop);
151 std::cout <<
"ELRSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
153 t = do_time< Sacado::ELRFad::DFad<double> >(nderiv, nloop);
154 std::cout <<
"ELRDFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
156 t = do_time< Sacado::CacheFad::DFad<double> >(nderiv, nloop);
157 std::cout <<
"CacheFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
159 t = do_time< Sacado::Fad::DVFad<double> >(nderiv, nloop);
160 std::cout <<
"DVFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
163 catch (std::exception& e) {
164 std::cout << e.what() << std::endl;
167 catch (
const char *s) {
168 std::cout << s << std::endl;
172 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)