13 #include "TinyFadET/tfad.h"
18 void FAD::error(
const char *msg) {
19 std::cout << msg << std::endl;
22 int main(
int argc,
char* argv[]) {
31 const int slfad_max = 130;
35 clp.
setDocString(
"This program tests the speed of various forward mode AD implementations for a finite-element-like Jacobian fill");
36 int num_nodes = 100000;
39 clp.
setOption(
"n", &num_nodes,
"Number of nodes");
40 clp.
setOption(
"p", &num_eqns,
"Number of equations");
41 clp.
setOption(
"rt", &rt,
"Include ADOL-C retaping test");
45 parseReturn= clp.
parse(argc, argv);
49 double mesh_spacing = 1.0 /
static_cast<double>(num_nodes - 1);
51 std::cout.setf(std::ios::scientific);
52 std::cout.precision(p);
53 std::cout <<
"num_nodes = " << num_nodes
54 <<
", num_eqns = " << num_eqns <<
": " << std::endl
55 <<
" " <<
" Time " <<
"\t"<<
"Time/Analytic" <<
"\t"
56 <<
"Time/(2*p*Residual)" << std::endl;
64 std::cout <<
"Analytic: " << std::setw(w) << ta <<
"\t" << std::setw(w) << ta/ta <<
"\t" << std::setw(w) << ta/(2.0*num_eqns*tr) << std::endl;
67 #ifndef ADOLC_TAPELESS
68 t = adolc_jac_fill(num_nodes, num_eqns, mesh_spacing);
69 std::cout <<
"ADOL-C: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
72 t = adolc_retape_jac_fill(num_nodes, num_eqns, mesh_spacing);
73 std::cout <<
"ADOL-C(rt): " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
77 t = adolc_tapeless_jac_fill(num_nodes, num_eqns, mesh_spacing);
78 std::cout <<
"ADOL-C(tl): " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
83 t = adic_jac_fill(num_nodes, num_eqns, mesh_spacing);
84 std::cout <<
"ADIC: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
87 if (num_eqns*2 == 4) {
88 t = fad_jac_fill< FAD::TFad<16,double> >(num_nodes, num_eqns, mesh_spacing);
89 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
91 else if (num_eqns*2 == 16) {
92 t = fad_jac_fill< FAD::TFad<16,double> >(num_nodes, num_eqns, mesh_spacing);
93 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
95 else if (num_eqns*2 == 32) {
96 t = fad_jac_fill< FAD::TFad<32,double> >(num_nodes, num_eqns, mesh_spacing);
97 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
99 else if (num_eqns*2 == 64) {
100 t = fad_jac_fill< FAD::TFad<64,double> >(num_nodes, num_eqns, mesh_spacing);
101 std::cout <<
"TFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
104 t = fad_jac_fill< FAD::Fad<double> >(num_nodes, num_eqns, mesh_spacing);
105 std::cout <<
"Fad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
107 if (num_eqns*2 == 4) {
108 t = fad_jac_fill< Sacado::Fad::SFad<double,4> >(num_nodes, num_eqns, mesh_spacing);
109 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
111 else if (num_eqns*2 == 16) {
112 t = fad_jac_fill< Sacado::Fad::SFad<double,16> >(num_nodes, num_eqns, mesh_spacing);
113 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
115 else if (num_eqns*2 == 32) {
116 t = fad_jac_fill< Sacado::Fad::SFad<double,32> >(num_nodes, num_eqns, mesh_spacing);
117 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
119 else if (num_eqns*2 == 64) {
120 t = fad_jac_fill< Sacado::Fad::SFad<double,64> >(num_nodes, num_eqns, mesh_spacing);
121 std::cout <<
"SFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
124 if (num_eqns*2 < slfad_max) {
125 t = fad_jac_fill< Sacado::Fad::SLFad<double,slfad_max> >(num_nodes, num_eqns, mesh_spacing);
126 std::cout <<
"SLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
129 t = fad_jac_fill< Sacado::Fad::DFad<double> >(num_nodes, num_eqns, mesh_spacing);
130 std::cout <<
"DFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
132 t = fad_jac_fill< Sacado::Fad::SimpleFad<double> >(num_nodes, num_eqns, mesh_spacing);
133 std::cout <<
"SimpleFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
135 if (num_eqns*2 == 4) {
136 t = fad_jac_fill< Sacado::ELRFad::SFad<double,4> >(num_nodes, num_eqns, mesh_spacing);
137 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
139 else if (num_eqns*2 == 16) {
140 t = fad_jac_fill< Sacado::ELRFad::SFad<double,16> >(num_nodes, num_eqns, mesh_spacing);
141 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
143 else if (num_eqns*2 == 32) {
144 t = fad_jac_fill< Sacado::ELRFad::SFad<double,32> >(num_nodes, num_eqns, mesh_spacing);
145 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
147 else if (num_eqns*2 == 64) {
148 t = fad_jac_fill< Sacado::ELRFad::SFad<double,64> >(num_nodes, num_eqns, mesh_spacing);
149 std::cout <<
"ELRSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
152 if (num_eqns*2 < slfad_max) {
153 t = fad_jac_fill< Sacado::ELRFad::SLFad<double,slfad_max> >(num_nodes, num_eqns, mesh_spacing);
154 std::cout <<
"ELRSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
157 t = fad_jac_fill< Sacado::ELRFad::DFad<double> >(num_nodes, num_eqns, mesh_spacing);
158 std::cout <<
"ELRDFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
160 if (num_eqns*2 == 4) {
161 t = fad_jac_fill< Sacado::CacheFad::SFad<double,4> >(num_nodes, num_eqns, mesh_spacing);
162 std::cout <<
"CacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
164 else if (num_eqns*2 == 16) {
165 t = fad_jac_fill< Sacado::CacheFad::SFad<double,16> >(num_nodes, num_eqns, mesh_spacing);
166 std::cout <<
"CacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
168 else if (num_eqns*2 == 32) {
169 t = fad_jac_fill< Sacado::CacheFad::SFad<double,32> >(num_nodes, num_eqns, mesh_spacing);
170 std::cout <<
"CacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
172 else if (num_eqns*2 == 64) {
173 t = fad_jac_fill< Sacado::CacheFad::SFad<double,64> >(num_nodes, num_eqns, mesh_spacing);
174 std::cout <<
"CacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
177 if (num_eqns*2 < slfad_max) {
178 t = fad_jac_fill< Sacado::CacheFad::SLFad<double,slfad_max> >(num_nodes, num_eqns, mesh_spacing);
179 std::cout <<
"CacheSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
182 t = fad_jac_fill< Sacado::CacheFad::DFad<double> >(num_nodes, num_eqns, mesh_spacing);
183 std::cout <<
"CacheFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
185 if (num_eqns*2 == 4) {
186 t = fad_jac_fill< Sacado::ELRCacheFad::SFad<double,4> >(num_nodes, num_eqns, mesh_spacing);
187 std::cout <<
"ELRCacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
189 else if (num_eqns*2 == 16) {
190 t = fad_jac_fill< Sacado::ELRCacheFad::SFad<double,16> >(num_nodes, num_eqns, mesh_spacing);
191 std::cout <<
"ELRCacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
193 else if (num_eqns*2 == 32) {
194 t = fad_jac_fill< Sacado::ELRCacheFad::SFad<double,32> >(num_nodes, num_eqns, mesh_spacing);
195 std::cout <<
"ELRCacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
197 else if (num_eqns*2 == 64) {
198 t = fad_jac_fill< Sacado::ELRCacheFad::SFad<double,64> >(num_nodes, num_eqns, mesh_spacing);
199 std::cout <<
"ELRCacheSFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
202 if (num_eqns*2 < slfad_max) {
203 t = fad_jac_fill< Sacado::ELRCacheFad::SLFad<double,slfad_max> >(num_nodes, num_eqns, mesh_spacing);
204 std::cout <<
"ELRCacheSLFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
207 t = fad_jac_fill< Sacado::ELRCacheFad::DFad<double> >(num_nodes, num_eqns, mesh_spacing);
208 std::cout <<
"ELRCacheFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
210 t = fad_jac_fill< Sacado::Fad::DVFad<double> >(num_nodes, num_eqns, mesh_spacing);
211 std::cout <<
"DVFad: " << std::setw(w) << t <<
"\t" << std::setw(w) << t/ta <<
"\t" << std::setw(w) << t/(2.0*num_eqns*tr) << std::endl;
214 catch (std::exception& e) {
215 std::cout << e.what() << std::endl;
218 catch (
const char *s) {
219 std::cout << s << std::endl;
223 std::cout <<
"Caught unknown exception!" << std::endl;
double residual_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)
double analytic_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)
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
void setDocString(const char doc_string[])