10 #ifndef TPETRA_DETAILS_CHECKVIEW_HPP
11 #define TPETRA_DETAILS_CHECKVIEW_HPP
21 #include "Tpetra_Details_WrappedDualView.hpp"
22 #include "Kokkos_DualView.hpp"
23 #include "Teuchos_TypeNameTraits.hpp"
24 #include "Teuchos_Comm.hpp"
25 #include "Teuchos_CommHelpers.hpp"
31 std::string memorySpaceName (
const void* ptr);
53 template<
class DataType,
class ... Properties>
56 (std::ostream* lclErrStrm,
57 const int myMpiProcessRank,
58 const Kokkos::View<DataType, Properties...>& view)
60 using Teuchos::TypeNameTraits;
62 using view_type = Kokkos::View<DataType, Properties...>;
64 if (view.size () == 0) {
70 auto ptr = view.data ();
73 if (lclErrStrm !=
nullptr) {
74 const std::string viewName = TypeNameTraits<view_type>::name ();
75 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::View "
76 "of type " << viewName <<
" has nonzero size " << view.size ()
77 <<
" but a null pointer." << endl;
89 template<
class DataType ,
93 (std::ostream*
const lclErrStrm,
94 const int myMpiProcessRank,
95 const Kokkos::DualView<DataType, Args...>& dv)
100 const bool host_good =
103 const bool good = dev_good && host_good;
104 if (! good && lclErrStrm !=
nullptr) {
105 using Teuchos::TypeNameTraits;
108 Kokkos::DualView<DataType, Args...>;
110 const std::string dvName = TypeNameTraits<dv_type>::name ();
111 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::DualView "
112 "of type " << dvName <<
" has one or more invalid Views. See "
113 "above error messages from this MPI process for details." << endl;
118 template<
class DataType ,
121 checkGlobalDualViewValidity
122 (std::ostream*
const gblErrStrm,
123 const Kokkos::DualView<DataType, Args...>& dv,
125 const Teuchos::Comm<int>*
const comm)
128 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
129 std::ostringstream lclErrStrm;
133 const bool lclValid =
135 lclSuccess = lclValid ? 1 : 0;
137 catch (std::exception& e) {
138 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
139 "threw an exception: " << e.what () << endl;
143 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
144 "threw an exception not a subclass of std::exception." << endl;
149 if (comm ==
nullptr) {
150 gblSuccess = lclSuccess;
153 using Teuchos::outArg;
154 using Teuchos::REDUCE_MIN;
155 using Teuchos::reduceAll;
156 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
159 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
160 *gblErrStrm <<
"On at least one (MPI) process, the "
161 "Kokkos::DualView has "
162 "either the device or host pointer in the "
163 "DualView equal to null, but the DualView has a nonzero number of "
164 "rows. For more detailed information, please rerun with the "
165 "TPETRA_VERBOSE environment variable set to 1. ";
167 *gblErrStrm <<
" Here are error messages from all "
168 "processes:" << endl;
169 if (comm ==
nullptr) {
170 *gblErrStrm << lclErrStrm.str ();
179 return gblSuccess == 1;
186 template<
class DataType ,
190 (std::ostream*
const lclErrStrm,
191 const int myMpiProcessRank,
194 const bool dev_good = dv.is_valid_device();
195 const bool host_good = dv. is_valid_host();
196 const bool good = dev_good && host_good;
197 if (! good && lclErrStrm !=
nullptr) {
198 using Teuchos::TypeNameTraits;
203 const std::string dvName = TypeNameTraits<dv_type>::name ();
204 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Tpetra::WrappedDualView "
205 "of type " << dvName <<
" has one or more invalid Views. See "
206 "above error messages from this MPI process for details." << endl;
211 template<
class DataType ,
214 checkGlobalWrappedDualViewValidity
215 (std::ostream*
const gblErrStrm,
218 const Teuchos::Comm<int>*
const comm)
221 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
222 std::ostringstream lclErrStrm;
226 const bool lclValid =
228 lclSuccess = lclValid ? 1 : 0;
230 catch (std::exception& e) {
231 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
232 "threw an exception: " << e.what () << endl;
236 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
237 "threw an exception not a subclass of std::exception." << endl;
242 if (comm ==
nullptr) {
243 gblSuccess = lclSuccess;
246 using Teuchos::outArg;
247 using Teuchos::REDUCE_MIN;
248 using Teuchos::reduceAll;
249 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
252 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
253 *gblErrStrm <<
"On at least one (MPI) process, the "
254 "Kokkos::DualView has "
255 "either the device or host pointer in the "
256 "DualView equal to null, but the DualView has a nonzero number of "
257 "rows. For more detailed information, please rerun with the "
258 "TPETRA_VERBOSE environment variable set to 1. ";
260 *gblErrStrm <<
" Here are error messages from all "
261 "processes:" << endl;
262 if (comm ==
nullptr) {
263 *gblErrStrm << lclErrStrm.str ();
272 return gblSuccess == 1;
279 #endif // TPETRA_DETAILS_CHECKVIEW_HPP
Declaration of a function that prints strings from each process.
A wrapper around Kokkos::DualView to safely manage data that might be replicated between host and dev...
bool checkLocalWrappedDualViewValidity(std::ostream *const lclErrStrm, const int myMpiProcessRank, const Tpetra::Details::WrappedDualView< Kokkos::DualView< DataType, Args...> > &dv)
Is the given Tpetra::WrappedDualView valid?
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator, in rank order.
bool checkLocalViewValidity(std::ostream *lclErrStrm, const int myMpiProcessRank, const Kokkos::View< DataType, Properties...> &view)
Is the given View valid?
bool checkLocalDualViewValidity(std::ostream *const lclErrStrm, const int myMpiProcessRank, const Kokkos::DualView< DataType, Args...> &dv)
Is the given Kokkos::DualView valid?