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>
55 const int myMpiProcessRank,
56 const Kokkos::View<DataType, Properties...>& view) {
58 using Teuchos::TypeNameTraits;
59 using view_type = Kokkos::View<DataType, Properties...>;
61 if (view.size() == 0) {
66 auto ptr = view.data();
69 if (lclErrStrm !=
nullptr) {
70 const std::string viewName = TypeNameTraits<view_type>::name();
71 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::View "
73 << viewName <<
" has nonzero size " << view.size()
74 <<
" but a null pointer." << endl;
85 template <
class DataType,
88 const int myMpiProcessRank,
89 const Kokkos::DualView<DataType, Args...>& dv) {
93 const bool host_good =
96 const bool good = dev_good && host_good;
97 if (!good && lclErrStrm !=
nullptr) {
99 using Teuchos::TypeNameTraits;
101 Kokkos::DualView<DataType, Args...>;
103 const std::string dvName = TypeNameTraits<dv_type>::name();
104 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Kokkos::DualView "
106 << dvName <<
" has one or more invalid Views. See "
107 "above error messages from this MPI process for details."
113 template <
class DataType,
115 bool checkGlobalDualViewValidity(std::ostream*
const gblErrStrm,
116 const Kokkos::DualView<DataType, Args...>& dv,
118 const Teuchos::Comm<int>*
const comm) {
120 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
121 std::ostringstream lclErrStrm;
125 const bool lclValid =
127 lclSuccess = lclValid ? 1 : 0;
128 }
catch (std::exception& e) {
129 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
130 "threw an exception: "
134 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
135 "threw an exception not a subclass of std::exception."
141 if (comm ==
nullptr) {
142 gblSuccess = lclSuccess;
144 using Teuchos::outArg;
145 using Teuchos::REDUCE_MIN;
146 using Teuchos::reduceAll;
147 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
150 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
151 *gblErrStrm <<
"On at least one (MPI) process, the "
152 "Kokkos::DualView has "
153 "either the device or host pointer in the "
154 "DualView equal to null, but the DualView has a nonzero number of "
155 "rows. For more detailed information, please rerun with the "
156 "TPETRA_VERBOSE environment variable set to 1. ";
158 *gblErrStrm <<
" Here are error messages from all "
161 if (comm ==
nullptr) {
162 *gblErrStrm << lclErrStrm.str();
170 return gblSuccess == 1;
176 template <
class DataType,
179 const int myMpiProcessRank,
181 const bool dev_good = dv.is_valid_device();
182 const bool host_good = dv.is_valid_host();
183 const bool good = dev_good && host_good;
184 if (!good && lclErrStrm !=
nullptr) {
186 using Teuchos::TypeNameTraits;
190 const std::string dvName = TypeNameTraits<dv_type>::name();
191 *lclErrStrm <<
"Proc " << myMpiProcessRank <<
": Tpetra::WrappedDualView "
193 << dvName <<
" has one or more invalid Views. See "
194 "above error messages from this MPI process for details."
200 template <
class DataType,
202 bool checkGlobalWrappedDualViewValidity(std::ostream*
const gblErrStrm,
205 const Teuchos::Comm<int>*
const comm) {
207 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
208 std::ostringstream lclErrStrm;
212 const bool lclValid =
214 lclSuccess = lclValid ? 1 : 0;
215 }
catch (std::exception& e) {
216 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
217 "threw an exception: "
221 lclErrStrm <<
"Proc " << myRank <<
": checkLocalDualViewValidity "
222 "threw an exception not a subclass of std::exception."
228 if (comm ==
nullptr) {
229 gblSuccess = lclSuccess;
231 using Teuchos::outArg;
232 using Teuchos::REDUCE_MIN;
233 using Teuchos::reduceAll;
234 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
237 if (gblSuccess != 1 && gblErrStrm !=
nullptr) {
238 *gblErrStrm <<
"On at least one (MPI) process, the "
239 "Kokkos::DualView has "
240 "either the device or host pointer in the "
241 "DualView equal to null, but the DualView has a nonzero number of "
242 "rows. For more detailed information, please rerun with the "
243 "TPETRA_VERBOSE environment variable set to 1. ";
245 *gblErrStrm <<
" Here are error messages from all "
248 if (comm ==
nullptr) {
249 *gblErrStrm << lclErrStrm.str();
257 return gblSuccess == 1;
263 #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?