37 #include "TinyFadET/tfad.h"
48 void FAD::error(
const char *msg) {
49 std::cout << msg << std::endl;
55 y = (x1*x2 +
sin(x1)/x2);
60 double& y,
double* ydot) {
64 double t1 = x2 + c/x2;
65 double t2 = x1 - t/x2;
67 for (
int i=0; i<10; i++)
68 ydot[i] = t1*x1dot[i] + t2*x2dot[i];
71 template <
typename FadType>
81 for (
int j=0; j<nderiv; j++) {
82 x1.fastAccessDx(j) = urand.
number();
83 x2.fastAccessDx(j) = urand.
number();
88 for (
int j=0; j<nloop; j++) {
100 double *x1dot, *x2dot, *ydot;
106 x1dot =
new double[nderiv];
107 x2dot =
new double[nderiv];
108 ydot =
new double[nderiv];
109 for (
int j=0; j<nderiv; j++) {
110 x1dot[j] = urand.
number();
111 x2dot[j] = urand.
number();
116 for (
int j=0; j<nloop; j++) {
124 int main(
int argc,
char* argv[]) {
134 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a single multiplication operation");
136 clp.
setOption(
"nderiv", &nderiv,
"Number of derivative components");
138 clp.
setOption(
"nloop", &nloop,
"Number of loops");
142 parseReturn= clp.
parse(argc, argv);
151 std::cout.setf(std::ios::scientific);
152 std::cout.precision(p);
153 std::cout <<
"Times (sec) for nderiv = " << nderiv
154 <<
" nloop = " << nloop <<
": " << std::endl;
157 std::cout <<
"Analytic: " << std::setw(w) << ta << std::endl;
159 t = do_time< Sacado::Fad::SimpleFad<double> >(nderiv, nloop);
160 std::cout <<
"SimpleFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
162 t = do_time< FAD::TFad<10,double> >(nderiv, nloop);
163 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
165 t = do_time< FAD::Fad<double> >(nderiv, nloop);
166 std::cout <<
"Fad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
168 t = do_time< Sacado::Fad::SFad<double,10> >(nderiv, nloop);
169 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
171 t = do_time< Sacado::Fad::SLFad<double,10> >(nderiv, nloop);
172 std::cout <<
"SLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
174 t = do_time< Sacado::Fad::DFad<double> >(nderiv, nloop);
175 std::cout <<
"DFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
177 t = do_time< Sacado::Fad::DMFad<double> >(nderiv, nloop);
178 std::cout <<
"DMFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
180 t = do_time< Sacado::ELRFad::SFad<double,10> >(nderiv, nloop);
181 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
183 t = do_time< Sacado::ELRFad::SLFad<double,10> >(nderiv, nloop);
184 std::cout <<
"ELRSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
186 t = do_time< Sacado::ELRFad::DFad<double> >(nderiv, nloop);
187 std::cout <<
"ELRDFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
189 t = do_time< Sacado::CacheFad::DFad<double> >(nderiv, nloop);
190 std::cout <<
"CacheFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
192 t = do_time< Sacado::Fad::DVFad<double> >(nderiv, nloop);
193 std::cout <<
"DVFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta << std::endl;
196 catch (std::exception& e) {
197 std::cout << e.what() << std::endl;
200 catch (
const char *s) {
201 std::cout << s << std::endl;
205 std::cout <<
"Caught unknown exception!" << std::endl;
MemPool * getMemoryPool(unsigned int dim)
Get memory pool for supplied dimension dim.
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)
Derivative array storage class using dynamic memory allocation.
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
Forward-mode AD class using dynamic memory allocation and expression templates.
void func1(const T &x1, const T &x2, T &y)