52 int main(
int argc,
char **argv)
54 const unsigned int n = 5;
56 for (
unsigned int i=0; i<n; i++) {
57 for (
unsigned int j=0; j<n; j++)
60 for (
unsigned int j=0; j<n; j++)
68 std::vector<double>
c(n), cdx(n*n);
71 blas.
GEMV(
Teuchos::NO_TRANS, n, n, 1.0, &a[0], n, &b[0], 1, 0.0, &
c[0], 1);
72 blas.
GEMM(
Teuchos::NO_TRANS,
Teuchos::NO_TRANS, n, n, n, 1.0, &a[0], n, &bdx[0], n, 0.0, &cdx[0], n);
78 sacado_fad_blas.
GEMV(
Teuchos::NO_TRANS, n, n, 1.0, &
A[0], n, &
B[0], 1, 0.0, &C[0], 1);
83 std::cout.setf(std::ios::scientific);
84 std::cout.precision(p);
86 std::cout <<
"BLAS GEMV calculation:" << std::endl;
87 std::cout <<
"a = " << std::endl;
88 for (
unsigned int i=0; i<n; i++) {
89 for (
unsigned int j=0; j<n; j++)
90 std::cout <<
" " << std::setw(w) << a[i+j*n];
91 std::cout << std::endl;
93 std::cout <<
"b = " << std::endl;
94 for (
unsigned int i=0; i<n; i++) {
95 std::cout <<
" " << std::setw(w) << b[i];
97 std::cout << std::endl;
98 std::cout <<
"bdot = " << std::endl;
99 for (
unsigned int i=0; i<n; i++) {
100 for (
unsigned int j=0; j<n; j++)
101 std::cout <<
" " << std::setw(w) << bdx[i+j*n];
102 std::cout << std::endl;
104 std::cout <<
"c = " << std::endl;
105 for (
unsigned int i=0; i<n; i++) {
106 std::cout <<
" " << std::setw(w) <<
c[i];
108 std::cout << std::endl;
109 std::cout <<
"cdot = " << std::endl;
110 for (
unsigned int i=0; i<n; i++) {
111 for (
unsigned int j=0; j<n; j++)
112 std::cout <<
" " << std::setw(w) << cdx[i+j*n];
113 std::cout << std::endl;
115 std::cout << std::endl << std::endl;
117 std::cout <<
"FAD BLAS GEMV calculation:" << std::endl;
118 std::cout <<
"A.val() (should = a) = " << std::endl;
119 for (
unsigned int i=0; i<n; i++) {
120 for (
unsigned int j=0; j<n; j++)
121 std::cout <<
" " << std::setw(w) <<
A[i+j*n].val();
122 std::cout << std::endl;
124 std::cout <<
"B.val() (should = b) = " << std::endl;
125 for (
unsigned int i=0; i<n; i++) {
126 std::cout <<
" " << std::setw(w) <<
B[i].val();
128 std::cout << std::endl;
129 std::cout <<
"B.dx() (should = bdot) = " << std::endl;
130 double *Bdx =
B.dx();
131 for (
unsigned int i=0; i<n; i++) {
132 for (
unsigned int j=0; j<n; j++)
133 std::cout <<
" " << std::setw(w) << Bdx[i+j*n];
134 std::cout << std::endl;
136 std::cout <<
"C.val() (should = c) = " << std::endl;
137 for (
unsigned int i=0; i<n; i++) {
138 std::cout <<
" " << std::setw(w) << C[i].val();
140 std::cout << std::endl;
141 std::cout <<
"C.dx() (should = cdot) = " << std::endl;
142 double *Cdx = C.dx();
143 for (
unsigned int i=0; i<n; i++) {
144 for (
unsigned int j=0; j<n; j++)
145 std::cout <<
" " << std::setw(w) << Cdx[i+j*n];
146 std::cout << std::endl;
149 double tol = 1.0e-14;
151 for (
unsigned int i=0; i<n; i++) {
154 for (
unsigned int j=0; j<n; j++) {
160 std::cout <<
"\nExample passed!" << std::endl;
164 std::cout <<
"\nSomething is wrong, example failed!" << std::endl;
void GEMV(ETransp trans, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const x_type *x, const OrdinalType &incx, const beta_type beta, ScalarType *y, const OrdinalType &incy) const
Sacado::Fad::DFad< double > FadType
A class for storing a contiguously allocated array of Fad objects. This is a general definition that ...
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
Forward-mode AD class using dynamic memory allocation and expression templates.
void GEMM(ETransp transa, ETransp transb, const int &m, const int &n, const int &k, const double &alpha, const double *A, const int &lda, const double *B, const int &ldb, const double &beta, double *C, const int &ldc) const
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
void GEMV(ETransp trans, const int &m, const int &n, const double &alpha, const double *A, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy) const