MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_AMGXOperator_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
47 #ifndef MUELU_AMGXOPERATOR_DEF_HPP
48 #define MUELU_AMGXOPERATOR_DEF_HPP
49 
50 
51 #if defined (HAVE_MUELU_AMGX)
53 
54 namespace MueLu {
55 
56  template<class Node>
59  return domainMap_;
60  }
61 
62  template<class Node>
64  return rangeMap_;
65  }
66 
67  template<class Node>
68  void AMGXOperator<double,int,int,Node>::apply(const Tpetra::MultiVector<double,int,int,Node>& X,
69  Tpetra::MultiVector<double,int,int,Node>& Y,
70  Teuchos::ETransp mode, double alpha, double beta) const {
71  RCP<const Teuchos::Comm<int> > comm = Y.getMap()->getComm();
72 
73  ArrayRCP<const double> mueluXdata, amgxXdata;
74  ArrayRCP<double> mueluYdata, amgxYdata;
75 
76  try {
77  for (int i = 0; i < (int)Y.getNumVectors(); i++) {
78  {
79  vectorTimer1_->start();
80 
81  mueluXdata = X.getData(i);
82  mueluYdata = Y.getDataNonConst(i);
83 
84  if (comm->getSize() == 1) {
85  amgxXdata = mueluXdata;
86  amgxYdata = mueluYdata;
87 
88  } else {
89  int n = mueluXdata.size();
90 
91  amgxXdata.resize(n);
92  amgxYdata.resize(n);
93 
94  ArrayRCP<double> amgxXdata_nonConst = Teuchos::arcp_const_cast<double>(amgxXdata);
95  for (int j = 0; j < n; j++) {
96  amgxXdata_nonConst[muelu2amgx_[j]] = mueluXdata[j];
97  amgxYdata [muelu2amgx_[j]] = mueluYdata[j];
98  }
99  }
100 
101  AMGX_vector_upload(X_, N_, 1, &amgxXdata[0]);
102  AMGX_vector_upload(Y_, N_, 1, &amgxYdata[0]);
103 
104  vectorTimer1_->stop();
105  vectorTimer1_->incrementNumCalls();
106  }
107 
108  AMGX_solver_solve(Solver_, X_, Y_);
109 
110  {
111  vectorTimer2_->start();
112 
113  AMGX_vector_download(Y_, &amgxYdata[0]);
114 
115  if (comm->getSize() > 1) {
116  int n = mueluYdata.size();
117 
118  for (int j = 0; j < n; j++)
119  mueluYdata[j] = amgxYdata[muelu2amgx_[j]];
120  }
121 
122  vectorTimer2_->stop();
123  vectorTimer2_->incrementNumCalls();
124  }
125  }
126 
127  } catch (std::exception& e) {
128  std::string errMsg = std::string("Caught an exception in MueLu::AMGXOperator::Apply():\n") + e.what() + "\n";
129  throw Exceptions::RuntimeError(errMsg);
130  }
131  }
132 
133  template<class Node>
135  return false;
136  }
137 
138 } // namespace
139 #endif //if defined(HAVE_MUELU_AMGX)
140 
141 #endif //ifdef MUELU_AMGXOPERATOR_DEF_HPP
Teuchos::RCP< const Map > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
size_type size() const
void resize(const size_type n, const T &val=T())
void apply(const MultiVector &X, MultiVector &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const
Returns a solution for the linear system AX=Y in the Tpetra::MultiVector X.
Teuchos::RCP< const Map > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
Exception throws to report errors in the internal logical of the program.
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.