From e2fcfd197fd030665feac691e19cc27f2c2b1f63 Mon Sep 17 00:00:00 2001 From: Ian Halim Date: Wed, 24 Jul 2024 17:51:23 -0600 Subject: [PATCH] MueLu: std::complex Replaced With Kokkos::complex Signed-off-by: Ian Halim --- .../MueLu_CoalesceDropFactory_def.hpp | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/muelu/src/Graph/MatrixTransformation/MueLu_CoalesceDropFactory_def.hpp b/packages/muelu/src/Graph/MatrixTransformation/MueLu_CoalesceDropFactory_def.hpp index da606ab20ff6..50cebaf6bfcd 100644 --- a/packages/muelu/src/Graph/MatrixTransformation/MueLu_CoalesceDropFactory_def.hpp +++ b/packages/muelu/src/Graph/MatrixTransformation/MueLu_CoalesceDropFactory_def.hpp @@ -582,10 +582,13 @@ void CoalesceDropFactory::Build(Level using ExecSpace = typename Node::execution_space; using TeamPol = Kokkos::TeamPolicy; using TeamMem = typename TeamPol::member_type; - + using ATS = Kokkos::ArithTraits; + using impl_scalar_type = typename ATS::val_type; + using implATS = Kokkos::ArithTraits; + //move from host to device - ArrayView ghostedDiagValsArrayView = ghostedDiagVals.view(ghostedDiagVals.lowerOffset(), ghostedDiagVals.size()); - Kokkos::View ghostedDiagValsView = Kokkos::Compat::getKokkosViewDeepCopy(ghostedDiagValsArrayView); + ArrayView ghostedDiagValsArrayView = ghostedDiagVals.view(ghostedDiagVals.lowerOffset(), ghostedDiagVals.size()); + Kokkos::View ghostedDiagValsView = Kokkos::Compat::getKokkosViewDeepCopy(ghostedDiagValsArrayView); auto boundaryNodesDevice = Kokkos::create_mirror_view(ExecSpace(), boundaryNodes); auto At = Utilities::Op2TpetraCrs(A); @@ -627,14 +630,14 @@ void CoalesceDropFactory::Build(Level size_t dropStart = n; if (algorithm == unscaled_cut) { //push diagonals and boundaries to the right, sort everything else by aij on the left - Kokkos::Experimental::sort_team(teamMember, index_view, [=](size_t& x, size_t& y) { + Kokkos::Experimental::sort_team(teamMember, index_view, [=](size_t& x, size_t& y) -> bool { if(drop_view(x) || drop_view(y)) { return drop_view(x) < drop_view(y); } else { - typename STS::magnitudeType x_aij = static_cast(std::fabs(static_cast(rowView.value(x) * rowView.value(x)))); - typename STS::magnitudeType y_aij = static_cast(std::fabs(static_cast(rowView.value(y) * rowView.value(y)))); - return x_aij > y_aij; + auto x_aij = implATS::magnitude(rowView.value(x) * rowView.value(x)); + auto y_aij = implATS::magnitude(rowView.value(y) * rowView.value(y)); + return x_aij > y_aij; } }); @@ -642,13 +645,13 @@ void CoalesceDropFactory::Build(Level Kokkos::parallel_reduce(Kokkos::TeamThreadRange(teamMember, 1, n), [=](size_t i, size_t& min) { auto const& x = index_view(i - 1); auto const& y = index_view(i); - typename STS::magnitudeType x_aij = 0; - typename STS::magnitudeType y_aij = 0; + typename implATS::magnitudeType x_aij = 0; + typename implATS::magnitudeType y_aij = 0; if(!drop_view(x)) { - x_aij = static_cast(std::fabs(static_cast(rowView.value(x) * rowView.value(x)))); + x_aij = implATS::magnitude(rowView.value(x) * rowView.value(x)); } if(!drop_view(y)) { - y_aij = static_cast(std::fabs(static_cast(rowView.value(y) * rowView.value(y)))); + y_aij = implATS::magnitude(rowView.value(y) * rowView.value(y)); } if(x_aij > realThreshold * y_aij) { @@ -659,16 +662,16 @@ void CoalesceDropFactory::Build(Level }, Kokkos::Min(dropStart)); } else if (algorithm == scaled_cut) { //push diagonals and boundaries to the right, sort everything else by aij/aiiajj on the left - Kokkos::Experimental::sort_team(teamMember, index_view, [=](size_t& x, size_t& y) { + Kokkos::Experimental::sort_team(teamMember, index_view, [=](size_t& x, size_t& y) -> bool { if(drop_view(x) || drop_view(y)) { return drop_view(x) < drop_view(y); } else { - typename STS::magnitudeType x_aij = static_cast(std::fabs(static_cast(rowView.value(x) * rowView.value(x)))); - typename STS::magnitudeType y_aij = static_cast(std::fabs(static_cast(rowView.value(y) * rowView.value(y)))); - typename STS::magnitudeType x_aiiajj = static_cast(std::fabs(static_cast(threshold * threshold * ghostedDiagValsView(rowView.colidx(x)) * ghostedDiagValsView(row)))); - typename STS::magnitudeType y_aiiajj = static_cast(std::fabs(static_cast(threshold * threshold * ghostedDiagValsView(rowView.colidx(y)) * ghostedDiagValsView(row)))); - return x_aij / x_aiiajj > y_aij / y_aiiajj; + auto x_aij = implATS::magnitude(rowView.value(x) * rowView.value(x)); + auto y_aij = implATS::magnitude(rowView.value(y) * rowView.value(y)); + auto x_aiiajj = implATS::magnitude(threshold * threshold * ghostedDiagValsView(rowView.colidx(x)) * ghostedDiagValsView(row)); + auto y_aiiajj = implATS::magnitude(threshold * threshold * ghostedDiagValsView(rowView.colidx(y)) * ghostedDiagValsView(row)); + return (x_aij / x_aiiajj) > (y_aij / y_aiiajj); } }); @@ -676,16 +679,16 @@ void CoalesceDropFactory::Build(Level Kokkos::parallel_reduce(Kokkos::TeamThreadRange(teamMember, 1, n), [=](size_t i, size_t& min) { auto const& x = index_view(i - 1); auto const& y = index_view(i); - typename STS::magnitudeType x_val = 0; - typename STS::magnitudeType y_val = 0; + typename implATS::magnitudeType x_val = 0; + typename implATS::magnitudeType y_val = 0; if(!drop_view(x)) { - typename STS::magnitudeType x_aij = static_cast(std::fabs(static_cast(rowView.value(x) * rowView.value(x)))); - typename STS::magnitudeType x_aiiajj = static_cast(std::fabs(static_cast(threshold * threshold * ghostedDiagValsView(rowView.colidx(x)) * ghostedDiagValsView(row)))); + typename implATS::magnitudeType x_aij = implATS::magnitude(rowView.value(x) * rowView.value(x)); + typename implATS::magnitudeType x_aiiajj = implATS::magnitude(threshold * threshold * ghostedDiagValsView(rowView.colidx(x)) * ghostedDiagValsView(row)); x_val = x_aij / x_aiiajj; } if(!drop_view(y)) { - typename STS::magnitudeType y_aij = static_cast(std::fabs(static_cast(rowView.value(y) * rowView.value(y)))); - typename STS::magnitudeType y_aiiajj = static_cast(std::fabs(static_cast(threshold * threshold * ghostedDiagValsView(rowView.colidx(y)) * ghostedDiagValsView(row)))); + typename implATS::magnitudeType y_aij = implATS::magnitude(rowView.value(y) * rowView.value(y)); + typename implATS::magnitudeType y_aiiajj = implATS::magnitude(threshold * threshold * ghostedDiagValsView(rowView.colidx(y)) * ghostedDiagValsView(row)); y_val = y_aij / y_aiiajj; }