40 #ifndef TPETRA_DETAILS_CHECKVIEW_HPP
41 #define TPETRA_DETAILS_CHECKVIEW_HPP
51 #include "Tpetra_Details_WrappedDualView.hpp"
52 #include "Kokkos_DualView.hpp"
53 #include "Teuchos_TypeNameTraits.hpp"
54 #include "Teuchos_Comm.hpp"
55 #include "Teuchos_CommHelpers.hpp"
61 std::string memorySpaceName (
const void* ptr);
83 template<
class DataType,
class ... Properties>
86 (std::ostream* lclErrStrm,
87 const int myMpiProcessRank,
88 const Kokkos::View<DataType, Properties...>& view)
90 using Teuchos::TypeNameTraits;
92 using view_type = Kokkos::View<DataType, Properties...>;
94 if (view.size () == 0) {
100 auto ptr = view.data ();
102 if (ptr ==
nullptr) {
103 if (lclErrStrm !=
nullptr) {
104 const std::string viewName = TypeNameTraits<view_type>::name ();
105 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::View "
106 "of type " << viewName <<
" has nonzero size " << view.size ()
107 <<
" but a null pointer." << endl;
119 template<
class DataType ,
123 (std::ostream*
const lclErrStrm,
124 const int myMpiProcessRank,
125 const Kokkos::DualView<DataType, Args...>& dv)
127 const bool dev_good =
130 const bool host_good =
133 const bool good = dev_good && host_good;
134 if (! good && lclErrStrm !=
nullptr) {
135 using Teuchos::TypeNameTraits;
138 Kokkos::DualView<DataType, Args...>;
140 const std::string dvName = TypeNameTraits<dv_type>::name ();
141 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::DualView "
142 "of type " << dvName <<
" has one or more invalid Views. See "
143 "above error messages from this MPI process for details." << endl;
148 template<
class DataType ,
151 checkGlobalDualViewValidity
152 (std::ostream*
const gblErrStrm,
153 const Kokkos::DualView<DataType, Args...>& dv,
155 const Teuchos::Comm<int>*
const comm)
158 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
159 std::ostringstream lclErrStrm;
163 const bool lclValid =
165 lclSuccess = lclValid ? 1 : 0;
167 catch (std::exception& e) {
168 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
169 "threw an exception: " << e.what () << endl;
173 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
174 "threw an exception not a subclass of std::exception." << endl;
179 if (comm ==
nullptr) {
180 gblSuccess = lclSuccess;
183 using Teuchos::outArg;
184 using Teuchos::REDUCE_MIN;
185 using Teuchos::reduceAll;
186 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
189 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
190 *gblErrStrm <<
"On at least one (MPI) process, the "
191 "Kokkos::DualView has "
192 "either the device or host pointer in the "
193 "DualView equal to null, but the DualView has a nonzero number of "
194 "rows. For more detailed information, please rerun with the "
195 "TPETRA_VERBOSE environment variable set to 1. ";
197 *gblErrStrm <<
" Here are error messages from all "
198 "processes:" << endl;
199 if (comm ==
nullptr) {
200 *gblErrStrm << lclErrStrm.str ();
209 return gblSuccess == 1;
216 template<
class DataType ,
220 (std::ostream*
const lclErrStrm,
221 const int myMpiProcessRank,
224 const bool dev_good = dv.is_valid_device();
225 const bool host_good = dv. is_valid_host();
226 const bool good = dev_good && host_good;
227 if (! good && lclErrStrm !=
nullptr) {
228 using Teuchos::TypeNameTraits;
233 const std::string dvName = TypeNameTraits<dv_type>::name ();
234 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Tpetra::WrappedDualView "
235 "of type " << dvName <<
" has one or more invalid Views. See "
236 "above error messages from this MPI process for details." << endl;
241 template<
class DataType ,
244 checkGlobalWrappedDualViewValidity
245 (std::ostream*
const gblErrStrm,
248 const Teuchos::Comm<int>*
const comm)
251 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
252 std::ostringstream lclErrStrm;
256 const bool lclValid =
258 lclSuccess = lclValid ? 1 : 0;
260 catch (std::exception& e) {
261 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
262 "threw an exception: " << e.what () << endl;
266 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
267 "threw an exception not a subclass of std::exception." << endl;
272 if (comm ==
nullptr) {
273 gblSuccess = lclSuccess;
276 using Teuchos::outArg;
277 using Teuchos::REDUCE_MIN;
278 using Teuchos::reduceAll;
279 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
282 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
283 *gblErrStrm <<
"On at least one (MPI) process, the "
284 "Kokkos::DualView has "
285 "either the device or host pointer in the "
286 "DualView equal to null, but the DualView has a nonzero number of "
287 "rows. For more detailed information, please rerun with the "
288 "TPETRA_VERBOSE environment variable set to 1. ";
290 *gblErrStrm <<
" Here are error messages from all "
291 "processes:" << endl;
292 if (comm ==
nullptr) {
293 *gblErrStrm << lclErrStrm.str ();
302 return gblSuccess == 1;
309 #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?