8 constexpr
int Rank = T::rank;
9 using value_type =
typename T::value_type;
13 for (
int d = 0; d < Rank; d++) max_ndim = std::max(max_ndim, view.extent(d));
14 View<bool**,CLayout,typename T::device_type> dim_nan_flags(
NoInit(
"dim_nan_flags"), Rank, max_ndim);
15 Kokkos::deep_copy(dim_nan_flags,
false);
18 const size_t N = view.size();
20 if constexpr (Rank == 1) {
21 Kokkos::parallel_for(
"nan_check_by_dim", Kokkos::RangePolicy<typename T::execution_space>(0,
N), KOKKOS_LAMBDA(
size_t idx_flat) {
24 dim_nan_flags(0,i) =
true;
27 }
else if constexpr (Rank == 2) {
28 Kokkos::parallel_for(
"nan_check_by_dim", Kokkos::RangePolicy<typename T::execution_space>(0,
N), KOKKOS_LAMBDA(
size_t idx_flat) {
29 int e1 = view.extent(1);
30 int i = idx_flat / e1;
31 int j = idx_flat % e1;
33 dim_nan_flags(0,i) =
true;
34 dim_nan_flags(1,j) =
true;
37 }
else if constexpr (Rank == 3) {
38 Kokkos::parallel_for(
"nan_check_by_dim", Kokkos::RangePolicy<typename T::execution_space>(0,
N), KOKKOS_LAMBDA(
size_t idx_flat) {
39 int e1 = view.extent(1), e2 = view.extent(2);
40 int i = idx_flat / (e1 * e2);
41 int j = (idx_flat / e2) % e1;
42 int k = idx_flat % e2;
44 dim_nan_flags(0,i) =
true;
45 dim_nan_flags(1,j) =
true;
46 dim_nan_flags(2,k) =
true;
49 }
else if constexpr (Rank == 4) {
50 Kokkos::parallel_for(
"nan_check_by_dim", Kokkos::RangePolicy<typename T::execution_space>(0,
N), KOKKOS_LAMBDA(
size_t idx_flat) {
51 int e1 = view.extent(1), e2 = view.extent(2), e3 = view.extent(3);
52 int i = idx_flat / (e1 * e2 * e3);
53 int j = (idx_flat / (e2 * e3)) % e1;
54 int k = (idx_flat / e3) % e2;
55 int l = idx_flat % e3;
57 dim_nan_flags(0,i) =
true;
58 dim_nan_flags(1,j) =
true;
59 dim_nan_flags(2,k) =
true;
60 dim_nan_flags(3,l) =
true;
67 auto flags_host = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), dim_nan_flags);
68 for (
int d = 0; d < Rank; d++) {
69 std::cout <<
"Dimension " << d <<
": Found NaNs in: {";
71 bool inside_range =
false;
72 for (
size_t i = 0; i < view.extent(d); i++) {
74 if(!inside_range) range_start = i;
83 std::cout << range_start <<
"-" << i-1 <<
", ";
86 std::cout << range_start <<
", ";
92 std::cout << range_start <<
"-" << view.extent(d)-1;
104 View<typename T::value_type*,CLayout, typename T::device_type, Kokkos::MemoryTraits<Kokkos::Unmanaged>> view_1D(view.data(), view.size());
107 Kokkos::parallel_reduce(
"nan_check", Kokkos::RangePolicy<typename T::execution_space>( 0,view.size() ), KOKKOS_LAMBDA(
const int i,
int& n_nan_l){
108 n_nan_l += (!
isfinite(view_1D(i)) ? 1 : 0);
113 if(n_nan==0)
return 0;
115 printf(
"Warning: %d NaNs found in %s!!\n", n_nan, name.c_str());
KOKKOS_INLINE_FUNCTION bool isfinite(const Field< VarType::Vector, PhiInterpType::Planes > &f)
Definition: field.hpp:114
@ N
Definition: col_grid.hpp:35
void parallel_for(const std::string name, int n_ptl, Function func, Option option, HostAoSoA aosoa_h, DeviceAoSoA aosoa_d)
Definition: streamed_parallel_for.hpp:252
int nan_check(const T &view, std::string name)
Definition: nan_check.hpp:102
void nan_check_by_dim(const T &view, std::string name)
Definition: nan_check.hpp:7
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:69