Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_EpetraMultiVector.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
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
47 
48 #include "Xpetra_EpetraImport.hpp"
49 #include "Xpetra_EpetraExport.hpp"
50 #include "Xpetra_Exceptions.hpp"
51 
52 #include "Xpetra_EpetraVector.hpp"
53 
54 #include "Epetra_SerialComm.h"
55 
56 
57 namespace Xpetra {
58 
59 // specialization for GO=int and NO=EpetraNode
60 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
61 Teuchos::RCP< const Vector< double, int, int, EpetraNode > > EpetraMultiVectorT<int, EpetraNode>::getVector(size_t j) const {
62  XPETRA_MONITOR("EpetraMultiVectorT::getVector");
63  return rcp(new Xpetra::EpetraVectorT<int,EpetraNode>(vec_, j)); // See constructor EpetraVectorT(const RCP<EpetraMultiVectorT> &mv, size_t j) for more info
64 }
65 
67 Teuchos::RCP< Vector< double, int, int, EpetraNode > > EpetraMultiVectorT<int,EpetraNode>::getVectorNonConst(size_t j) {
68  XPETRA_MONITOR("EpetraMultiVectorT::getVector");
69  return rcp(new EpetraVectorT<int,EpetraNode>(vec_, j)); // See constructor EpetraVectorT(const RCP<EpetraMultiVectorT> &mv, size_t j) for more info
70 }
71 #endif
72 
73 // specialization for GO=long long and NO=EpetraNode
74 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
75 Teuchos::RCP< const Vector< double, int, long long, EpetraNode > > EpetraMultiVectorT<long long, EpetraNode>::getVector(size_t j) const {
76  XPETRA_MONITOR("EpetraMultiVectorT::getVector");
77  return rcp(new Xpetra::EpetraVectorT<long long,EpetraNode>(vec_, j)); // See constructor EpetraVectorT(const RCP<EpetraMultiVectorT> &mv, size_t j) for more info
78 }
79 
81 Teuchos::RCP< Vector< double, int, long long, EpetraNode > > EpetraMultiVectorT<long long,EpetraNode>::getVectorNonConst(size_t j) {
82  XPETRA_MONITOR("EpetraMultiVectorT::getVector");
83  return rcp(new EpetraVectorT<long long,EpetraNode>(vec_, j)); // See constructor EpetraVectorT(const RCP<EpetraMultiVectorT> &mv, size_t j) for more info
84 }
85 #endif
86 
87 // TODO: move that elsewhere
88 template<class GlobalOrdinal,class Node>
89 const Epetra_MultiVector & toEpetra(const MultiVector<double, int, GlobalOrdinal,Node> & x) {
91  return *tX.getEpetra_MultiVector();
92 }
93 
94 template<class GlobalOrdinal,class Node>
97  return *tX.getEpetra_MultiVector();
98 }
99 //
100 
101 template<class GlobalOrdinal,class Node>
102 RCP<MultiVector<double, int, GlobalOrdinal,Node> > toXpetra(RCP<Epetra_MultiVector> vec) {
103  if (!vec.is_null())
104  return rcp(new EpetraMultiVectorT<GlobalOrdinal,Node>(vec));
105 
106  return Teuchos::null;
107 }
108 
109 
110 
111 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
112 #ifdef HAVE_XPETRA_TPETRA
113 #include "TpetraCore_config.h"
114 #if ((defined(EPETRA_HAVE_OMP) && !defined(HAVE_TPETRA_INST_OPENMP)) || \
115  (!defined(EPETRA_HAVE_OMP) && !defined(HAVE_TPETRA_INST_SERIAL)))
116 template class EpetraMultiVectorT<int, Xpetra::EpetraNode >;
117 template RCP<MultiVector<double, int, int, Xpetra::EpetraNode > > toXpetra<int, Xpetra::EpetraNode>(RCP<Epetra_MultiVector>);
118 template Epetra_MultiVector & toEpetra<int,Xpetra::EpetraNode >(MultiVector<double, int, int,Xpetra::EpetraNode> &);
119 template const Epetra_MultiVector & toEpetra<int, Xpetra::EpetraNode >(const MultiVector<double, int, int, Xpetra::EpetraNode > &);
120 #endif
121 
122 #ifdef HAVE_TPETRA_INST_SERIAL
123 template class EpetraMultiVectorT<int, Kokkos::Compat::KokkosSerialWrapperNode >;
124 template RCP<MultiVector<double, int, int, Kokkos::Compat::KokkosSerialWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosSerialWrapperNode>(RCP<Epetra_MultiVector>);
125 template Epetra_MultiVector & toEpetra<int,Kokkos::Compat::KokkosSerialWrapperNode >(MultiVector<double, int, int, Kokkos::Compat::KokkosSerialWrapperNode> &);
126 template const Epetra_MultiVector & toEpetra<int, Kokkos::Compat::KokkosSerialWrapperNode >(const MultiVector<double, int, int, Kokkos::Compat::KokkosSerialWrapperNode > &);
127 #endif
128 #ifdef HAVE_TPETRA_INST_PTHREAD
129 template class EpetraMultiVectorT<int, Kokkos::Compat::KokkosThreadsWrapperNode >;
130 template RCP<MultiVector<double, int, int, Kokkos::Compat::KokkosThreadsWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosThreadsWrapperNode>(RCP<Epetra_MultiVector>);
131 template Epetra_MultiVector & toEpetra<int,Kokkos::Compat::KokkosThreadsWrapperNode >(MultiVector<double, int, int, Kokkos::Compat::KokkosThreadsWrapperNode> &);
132 template const Epetra_MultiVector & toEpetra<int, Kokkos::Compat::KokkosThreadsWrapperNode >(const MultiVector<double, int, int, Kokkos::Compat::KokkosThreadsWrapperNode > &);
133 #endif
134 #ifdef HAVE_TPETRA_INST_OPENMP
135 template class EpetraMultiVectorT<int, Kokkos::Compat::KokkosOpenMPWrapperNode >;
136 template RCP<MultiVector<double, int, int, Kokkos::Compat::KokkosOpenMPWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosOpenMPWrapperNode>(RCP<Epetra_MultiVector>);
137 template Epetra_MultiVector & toEpetra<int,Kokkos::Compat::KokkosOpenMPWrapperNode >(MultiVector<double, int, int, Kokkos::Compat::KokkosOpenMPWrapperNode> &);
138 template const Epetra_MultiVector & toEpetra<int, Kokkos::Compat::KokkosOpenMPWrapperNode >(const MultiVector<double, int, int, Kokkos::Compat::KokkosOpenMPWrapperNode > &);
139 #endif
140 #ifdef HAVE_TPETRA_INST_CUDA
141 template class EpetraMultiVectorT<int, Kokkos::Compat::KokkosCudaWrapperNode >;
142 template RCP<MultiVector<double, int, int, Kokkos::Compat::KokkosCudaWrapperNode > > toXpetra<int, Kokkos::Compat::KokkosCudaWrapperNode>(RCP<Epetra_MultiVector>);
143 template Epetra_MultiVector & toEpetra<int,Kokkos::Compat::KokkosCudaWrapperNode >(MultiVector<double, int, int,Kokkos::Compat::KokkosCudaWrapperNode> &);
144 template const Epetra_MultiVector & toEpetra<int, Kokkos::Compat::KokkosCudaWrapperNode >(const MultiVector<double, int, int, Kokkos::Compat::KokkosCudaWrapperNode > &);
145 #endif
146 #else // Tpetra is disabled
147 typedef Xpetra::EpetraNode default_node_type;
148 template class EpetraMultiVectorT<int, default_node_type >;
149 template RCP<MultiVector<double, int, int, default_node_type > > toXpetra<int, default_node_type>(RCP<Epetra_MultiVector>);
150 template Epetra_MultiVector & toEpetra<int,default_node_type >(MultiVector<double, int, int,default_node_type> &);
151 template const Epetra_MultiVector & toEpetra<int, default_node_type >(const MultiVector<double, int, int, default_node_type > &);
152 #endif
153 #endif
154 
155 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
156 #ifdef HAVE_XPETRA_TPETRA
157 #include "TpetraCore_config.h"
158 #if ((defined(EPETRA_HAVE_OMP) && !defined(HAVE_TPETRA_INST_OPENMP)) || \
159  (!defined(EPETRA_HAVE_OMP) && !defined(HAVE_TPETRA_INST_SERIAL)))
160 template class EpetraMultiVectorT<long long, Xpetra::EpetraNode >;
161 template RCP<MultiVector<double, int, long long, Xpetra::EpetraNode > > toXpetra<long long, Xpetra::EpetraNode>(RCP<Epetra_MultiVector>);
162 template Epetra_MultiVector & toEpetra<long long,Xpetra::EpetraNode >(MultiVector<double, int, long long,Xpetra::EpetraNode> &);
163 template const Epetra_MultiVector & toEpetra<long long, Xpetra::EpetraNode >(const MultiVector<double, int, long long, Xpetra::EpetraNode > &);
164 #endif
165 
166 #ifdef HAVE_TPETRA_INST_SERIAL
167 template class EpetraMultiVectorT<long long, Kokkos::Compat::KokkosSerialWrapperNode >;
168 template RCP<MultiVector<double, int, long long, Kokkos::Compat::KokkosSerialWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosSerialWrapperNode>(RCP<Epetra_MultiVector>);
169 template Epetra_MultiVector & toEpetra<long long,Kokkos::Compat::KokkosSerialWrapperNode >(MultiVector<double, int, long long, Kokkos::Compat::KokkosSerialWrapperNode> &);
170 template const Epetra_MultiVector & toEpetra<long long, Kokkos::Compat::KokkosSerialWrapperNode >(const MultiVector<double, int, long long, Kokkos::Compat::KokkosSerialWrapperNode > &);
171 #endif
172 #ifdef HAVE_TPETRA_INST_PTHREAD
173 template class EpetraMultiVectorT<long long,Kokkos::Compat::KokkosThreadsWrapperNode >;
174 template RCP<MultiVector<double, int, long long, Kokkos::Compat::KokkosThreadsWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosThreadsWrapperNode>(RCP<Epetra_MultiVector>);
175 template Epetra_MultiVector & toEpetra<long long,Kokkos::Compat::KokkosThreadsWrapperNode >(MultiVector<double, int, long long,Kokkos::Compat::KokkosThreadsWrapperNode> &);
176 template const Epetra_MultiVector & toEpetra<long long, Kokkos::Compat::KokkosThreadsWrapperNode >(const MultiVector<double, int, long long, Kokkos::Compat::KokkosThreadsWrapperNode > &);
177 #endif
178 #ifdef HAVE_TPETRA_INST_OPENMP
179 template class EpetraMultiVectorT<long long, Kokkos::Compat::KokkosOpenMPWrapperNode >;
180 template RCP<MultiVector<double, int, long long, Kokkos::Compat::KokkosOpenMPWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosOpenMPWrapperNode>(RCP<Epetra_MultiVector>);
181 template Epetra_MultiVector & toEpetra<long long,Kokkos::Compat::KokkosOpenMPWrapperNode >(MultiVector<double, int, long long,Kokkos::Compat::KokkosOpenMPWrapperNode> &);
182 template const Epetra_MultiVector & toEpetra<long long, Kokkos::Compat::KokkosOpenMPWrapperNode >(const MultiVector<double, int, long long, Kokkos::Compat::KokkosOpenMPWrapperNode > &);
183 #endif
184 #ifdef HAVE_TPETRA_INST_CUDA
185 template class EpetraMultiVectorT<long long, Kokkos::Compat::KokkosCudaWrapperNode >;
186 template RCP<MultiVector<double, int, long long, Kokkos::Compat::KokkosCudaWrapperNode > > toXpetra<long long, Kokkos::Compat::KokkosCudaWrapperNode>(RCP<Epetra_MultiVector>);
187 template Epetra_MultiVector & toEpetra<long long,Kokkos::Compat::KokkosCudaWrapperNode >(MultiVector<double, int, long long, Kokkos::Compat::KokkosCudaWrapperNode> &);
188 template const Epetra_MultiVector & toEpetra<long long, Kokkos::Compat::KokkosCudaWrapperNode >(const MultiVector<double, int, long long, Kokkos::Compat::KokkosCudaWrapperNode > &);
189 #endif
190 #else // Tpetra is disabled
191 typedef Xpetra::EpetraNode default_node_type;
192 template class EpetraMultiVectorT<long long, default_node_type >;
193 template RCP<MultiVector<double, int, long long, default_node_type > > toXpetra<long long, default_node_type>(RCP<Epetra_MultiVector>);
194 template Epetra_MultiVector & toEpetra<long long,default_node_type >(MultiVector<double, int, long long,default_node_type> &);
195 template const Epetra_MultiVector & toEpetra<long long, default_node_type >(const MultiVector<double, int, long long, default_node_type > &);
196 #endif
197 #endif
198 
199 } // namespace Xpetra
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
#define XPETRA_MONITOR(funcName)
Teuchos::RCP< const Vector< double, int, GlobalOrdinal, Node > > getVector(size_t j) const
Return a Vector which is a const view of column j.
Teuchos::RCP< Vector< double, int, GlobalOrdinal, Node > > getVectorNonConst(size_t j)
Return a Vector which is a nonconst view of column j.