80 #ifdef HAVE_TEUCHOS_ARPREC 
   81 #include <arprec/mp_real.h> 
   84 #ifdef HAVE_TEUCHOS_GNU_MP 
   90 using namespace Teuchos;
 
   92 #ifdef HAVE_TEUCHOS_ARPREC 
   93 #define SType1     mp_real 
   94 #elif defined(HAVE_TEUCHOS_GNU_MP) 
   95 #define SType1     mpf_class 
  102 template<
typename TYPE>
 
  105 template<
typename TYPE>
 
  108 template<
typename TYPE1, 
typename TYPE2>
 
  111 template<
typename TYPE1, 
typename TYPE2>
 
  114 #ifdef HAVE_TEUCHOS_ARPREC 
  122 #ifdef HAVE_TEUCHOS_GNU_MP 
  130 template<
typename TYPE>
 
  133 template<
typename TYPE>
 
  134 int Solve(
int, TYPE*, TYPE*, TYPE*);
 
  136 template<
typename TYPE>
 
  139 template<
typename TYPE>
 
  142 #ifdef HAVE_TEUCHOS_ARPREC 
  150 int main(
int argc, 
char *argv[]) {
 
  160   hilbertCLP.
setOption(
"precision", &precision, 
"Arbitrary precision");
 
  161   bool verbose = 
false;
 
  162   hilbertCLP.
setOption(
"verbose", 
"quiet", &verbose, 
"Verbosity of example");
 
  165   hilbertCLP.
parse( argc, argv );
 
  167 #ifdef HAVE_TEUCHOS_ARPREC 
  168   mp::mp_init( precision );
 
  171 #ifdef HAVE_TEUCHOS_GNU_MP 
  172   mpf_set_default_prec( precision );
 
  173   std::cout<< 
"The precision of the GNU MP variable is (in bits) : "<< mpf_get_default_prec() << std::endl;
 
  187   SType1 result1, result2_1;
 
  188   SType2 result2, result1_2;
 
  195   while ( compSType1>0 || compSType2>0 || convSType1>0 || convSType2>0 ) {
 
  197     if (compSType1 > 0) {
 
  203       ConstructHilbertMatrix< SType1 >(H1, 
n);
 
  204       ConstructHilbertSumVector< SType1 >(b1, 
n);
 
  208       compSType1 = 
Solve(n, H1, b1, &result1);
 
  209       if (compSType1 < 0 && verbose)
 
  210   std::cout << 
typeid( result1 ).name() << 
" -- Cholesky factorization failed (negative diagonal) at row "<<-compSType1<< std::endl;
 
  213       delete [] H1; H1 = 0;
 
  214       delete [] b1; b1 = 0;
 
  216     if (compSType2 > 0) {
 
  222       ConstructHilbertMatrix< SType2 >(H2, 
n);
 
  223       ConstructHilbertSumVector< SType2 >(b2, 
n);
 
  227       compSType2 = 
Solve(n, H2, b2, &result2);
 
  228       if (compSType2 < 0 && verbose)
 
  229   std::cout << 
typeid( result2 ).name() << 
" -- Cholesky factorization failed (negative diagonal) at row "<<-compSType2<< std::endl;
 
  232       delete [] H2; H2 = 0;
 
  233       delete [] b2; b2 = 0;
 
  235     if (convSType2 > 0) {
 
  239       if (!H1) H1 = 
new SType1[ n*
n ];
 
  244       if (!H2) H2 = 
new SType2[ n*
n ];
 
  254       convSType2 = 
Solve(n, H2, b2, &result1_2);
 
  255       if (convSType2 < 0 && verbose)
 
  256   std::cout << 
typeid( result1_2 ).name() << 
" (converted) -- Cholesky factorization failed (negative diagonal) at row "<<-convSType2<< std::endl;
 
  260       delete [] H2; H2 = 0;
 
  261       delete [] b2; b2 = 0;
 
  262       delete [] H1; H1 = 0;
 
  263       delete [] b1; b1 = 0;
 
  265     if (convSType1 > 0) {
 
  269       if (!H2) H2 = 
new SType2[ n*
n ];
 
  274       if (!H1) H1 = 
new SType1[ n*
n ];
 
  284       convSType1 = 
Solve(n, H1, b1, &result2_1);
 
  285       if (convSType1 < 0 && verbose)
 
  286   std::cout << 
typeid( result2_1 ).name() << 
" (converted) -- Cholesky factorization failed (negative diagonal) at row "<<-convSType1<< std::endl;
 
  290       delete [] H1; H1 = 0;
 
  291       delete [] b1; b1 = 0;
 
  292       delete [] H2; H2 = 0;
 
  293       delete [] b2; b2 = 0;
 
  295     if (verbose && (compSType1>0 || compSType2>0 || convSType1>0 || convSType2>0) ) {
 
  296       std::cout << 
"***************************************************" << std::endl;
 
  297       std::cout << 
"Dimension of Hilbert Matrix : "<< n << std::endl;
 
  298       std::cout << 
"***************************************************" << std::endl;
 
  299       std::cout << 
"Datatype : Absolute error || x_hat - x ||"<< std::endl;
 
  300       std::cout << 
"---------------------------------------------------" << std::endl;
 
  302     if (compSType1>0 && verbose)
 
  303       std::cout << 
typeid( result1 ).name() << 
"\t : "<< result1 << std::endl;
 
  305     if (convSType1>0 && verbose)
 
  306       std::cout << 
typeid( result2_1 ).name() <<
"(converted) : "<< result2_1 << std::endl;
 
  308     if (convSType2>0 && verbose)
 
  309       std::cout << 
typeid( result1_2 ).name() <<
"(converted) : "<< result2_1 << std::endl;
 
  311     if (compSType2>0 && verbose)
 
  312       std::cout << 
typeid( result2 ).name() << 
"\t : "<< result2 << std::endl;
 
  319 #ifdef HAVE_TEUCHOS_ARPREC 
  326 template<
typename TYPE>
 
  329   for(
int i = 0; i < 
n; i++) {
 
  330     for(
int j = 0; j < 
n; j++) {
 
  331       A[i + (j * 
n)] = (scal1 / (i + j + scal1));
 
  336 template<
typename TYPE>
 
  340   for(
int i = 0; i < 
n; i++) {
 
  342     for(
int j = 0; j < 
n; j++) {
 
  343       x[i] += (scal1 / (i + j + scal1));
 
  348 template<
typename TYPE1, 
typename TYPE2>
 
  350   for(
int i = 0; i < 
n; i++) {
 
  351     for(
int j = 0; j < 
n; j++) {
 
  352       B[i + (j * 
n)] = A[i + (j * n)];
 
  357 template<
typename TYPE1, 
typename TYPE2>
 
  359   for(
int i = 0; i < 
n; i++) {
 
  364 #ifdef HAVE_TEUCHOS_ARPREC 
  367   for(
int i = 0; i < 
n; i++) {
 
  368     for(
int j = 0; j < 
n; j++) {
 
  369       B[i + (j * 
n)] = dble( A[i + (j * n)] );
 
  376   for(
int i = 0; i < 
n; i++) {
 
  382 #ifdef HAVE_TEUCHOS_GNU_MP 
  385   for(
int i = 0; i < 
n; i++) {
 
  386     for(
int j = 0; j < 
n; j++) {
 
  387       B[i + (j * 
n)] = A[i + (j * n)].get_d();
 
  394   for(
int i = 0; i < 
n; i++) {
 
  400 template<
typename TYPE>
 
  403   for(
int k = 0; k < 
n; k++) {
 
  404     for(
int j = k + 1; j < 
n; j++) {
 
  405       TYPE alpha = A[k + (j * 
n)] / A[k + (k * n)];
 
  406       for(
int i = j; i < 
n; i++) {
 
  407   A[j + (i * 
n)] -= (alpha * A[k + (i * n)]);
 
  410     if(A[k + (k * n)] <= scal0) {
 
  414     for(
int i = k; i < 
n; i++) {
 
  415       A[k + (i * 
n)] /= beta;
 
  421 template<
typename TYPE>
 
  422 int Solve(
int n, TYPE* H, TYPE* b, TYPE* err) {
 
  425   TYPE scalNeg1 = scal0 - scal1;
 
  427   TYPE* x = 
new TYPE[
n];
 
  428   for(
int i = 0; i < 
n; i++) {
 
  431   int choleskySuccessful = 
Cholesky(H, n);
 
  432   if(choleskySuccessful > 0) {
 
  433     blasObj.
TRSM(
Teuchos::LEFT_SIDE, 
Teuchos::UPPER_TRI, 
Teuchos::TRANS, 
Teuchos::NON_UNIT_DIAG, n, 1, scal1, H, n, b, n);
 
  434     blasObj.
TRSM(
Teuchos::LEFT_SIDE, 
Teuchos::UPPER_TRI, 
Teuchos::NO_TRANS, 
Teuchos::NON_UNIT_DIAG, n, 1, scal1, H, n, b, n);
 
  435     blasObj.
AXPY(n, scalNeg1, x, 1, b, 1);
 
  436     *err = blasObj.
NRM2(n, b, 1);
 
  439   return choleskySuccessful;
 
  442 template<
typename TYPE>
 
  445   for(
int i = 0; i < 
n; i++) {
 
  446     std::cout << 
" " << x[i];
 
  448   std::cout << 
" ]" << std::endl;
 
  451 template<
typename TYPE>
 
  454   for(
int i = 0; i < m; i++) {
 
  459     for(
int j = 0; j < 
n; j++) {
 
  460       std::cout << 
" " << a[i + (j * m)];
 
  464       std::cout << std::endl;
 
  467   std::cout << 
"]" << std::endl;
 
  470 #ifdef HAVE_TEUCHOS_ARPREC 
  474   for(
int i = 0; i < 
n; i++) {
 
  480   std::cout << 
"]" << std::endl;
 
  486   for(
int i = 0; i < m; i++) {
 
  491     for(
int j = 0; j < 
n; j++) {
 
  495       std::cout << 
" " << a[i + (j * m)];
 
  499       std::cout << std::endl;
 
  502   std::cout << 
"]" << std::endl;
 
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb) const 
Solves the matrix equations: op(A)*X=alpha*B or X*op(A)=alpha*B where X and B are m by n matrices...
 
void AXPY(const OrdinalType &n, const alpha_type alpha, const x_type *x, const OrdinalType &incx, ScalarType *y, const OrdinalType &incy) const 
Perform the operation: y <- y+alpha*x. 
 
void ConstructHilbertSumVector(TYPE *, int)
 
Templated interface class to BLAS routines. 
 
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x. 
 
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
 
void PrintArrayAsMatrix(TYPE *, int, int)
 
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const 
Compute the 2-norm of the vector x. 
 
void PrintArrayAsVector(TYPE *, int)
 
void ConvertHilbertSumVector(TYPE1 *, TYPE2 *, int)
 
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option. 
 
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const 
Parse a command line. 
 
std::string Teuchos_Version()
 
int main(int argc, char *argv[])
 
void ConvertHilbertMatrix(TYPE1 *, TYPE2 *, int)
 
Basic command line parser for input from (argc,argv[]) 
 
void ConstructHilbertMatrix(TYPE *, int)
 
static T zero()
Returns representation of zero for this scalar type. 
 
int Cholesky(TYPE *, int)
 
int Solve(int, TYPE *, TYPE *, TYPE *)
 
static T one()
Returns representation of one for this scalar type. 
 
Class that helps parse command line input arguments from (argc,argv[]) and set options.