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 #if defined(HAVE_MUELU_AMGX)
52 
53 namespace MueLu {
54 
55 template <class Node>
58  return domainMap_;
59 }
60 
61 template <class Node>
63  return rangeMap_;
64 }
65 
66 template <class Node>
69  Teuchos::ETransp mode, double alpha, double beta) const {
70  RCP<const Teuchos::Comm<int> > comm = Y.getMap()->getComm();
71 
72  ArrayRCP<const double> mueluXdata, amgxXdata;
73  ArrayRCP<double> mueluYdata, amgxYdata;
74 
75  try {
76  for (int i = 0; i < (int)Y.getNumVectors(); i++) {
77  {
78  vectorTimer1_->start();
79 
80  mueluXdata = X.getData(i);
81  mueluYdata = Y.getDataNonConst(i);
82 
83  if (comm->getSize() == 1) {
84  amgxXdata = mueluXdata;
85  amgxYdata = mueluYdata;
86 
87  } else {
88  int n = mueluXdata.size();
89 
90  amgxXdata.resize(n);
91  amgxYdata.resize(n);
92 
93  ArrayRCP<double> amgxXdata_nonConst = Teuchos::arcp_const_cast<double>(amgxXdata);
94  for (int j = 0; j < n; j++) {
95  amgxXdata_nonConst[muelu2amgx_[j]] = mueluXdata[j];
96  amgxYdata[muelu2amgx_[j]] = mueluYdata[j];
97  }
98  }
99 
100  AMGX_vector_upload(X_, N_, 1, &amgxXdata[0]);
101  AMGX_vector_upload(Y_, N_, 1, &amgxYdata[0]);
102 
103  vectorTimer1_->stop();
104  vectorTimer1_->incrementNumCalls();
105  }
106 
107  // Solve the system and time.
108  solverTimer_->start();
109  AMGX_solver_solve(Solver_, X_, Y_);
110  solverTimer_->stop();
111  solverTimer_->incrementNumCalls();
112 
113  {
114  vectorTimer2_->start();
115 
116  AMGX_vector_download(Y_, &amgxYdata[0]);
117 
118  if (comm->getSize() > 1) {
119  int n = mueluYdata.size();
120 
121  for (int j = 0; j < n; j++)
122  mueluYdata[j] = amgxYdata[muelu2amgx_[j]];
123  }
124 
125  vectorTimer2_->stop();
126  vectorTimer2_->incrementNumCalls();
127  }
128  }
129 
130  } catch (std::exception& e) {
131  std::string errMsg = std::string("Caught an exception in MueLu::AMGXOperator::Apply():\n") + e.what() + "\n";
132  throw Exceptions::RuntimeError(errMsg);
133  }
134 }
135 
136 template <class Node>
138  return false;
139 }
140 
141 } // namespace MueLu
142 #endif // if defined(HAVE_MUELU_AMGX)
143 
144 #endif // ifdef MUELU_AMGXOPERATOR_DEF_HPP
size_t getNumVectors() const
Teuchos::RCP< const Map > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
size_type size() const
Teuchos::ArrayRCP< const Scalar > getData(size_t j) 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::ArrayRCP< Scalar > getDataNonConst(size_t j)
Teuchos::RCP< const Map > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
virtual Teuchos::RCP< const map_type > getMap() const
Exception throws to report errors in the internal logical of the program.
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.