10 #ifndef _ZOLTAN2_DISTANCE1_2GHOSTLAYER_HPP_
11 #define _ZOLTAN2_DISTANCE1_2GHOSTLAYER_HPP_
14 #include <unordered_map>
31 #include "Tpetra_Core.hpp"
32 #include "Teuchos_RCP.hpp"
33 #include "Tpetra_Import.hpp"
34 #include "Tpetra_FEMultiVector.hpp"
36 #include "KokkosKernels_Handle.hpp"
37 #include "KokkosKernels_IOUtils.hpp"
38 #include "KokkosGraph_Distance1Color.hpp"
39 #include "KokkosGraph_Distance1ColorHandle.hpp"
48 template <
typename Adapter>
56 using map_t = Tpetra::Map<lno_t,gno_t>;
58 using femv_t = Tpetra::FEMultiVector<femv_scalar_t, lno_t, gno_t>;
62 using host_exec =
typename femv_t::host_view_type::device_type::execution_space;
63 using host_mem =
typename femv_t::host_view_type::device_type::memory_space;
67 template <
class ExecutionSpace,
typename MemorySpace>
68 void localColoring(
const size_t nVtx,
69 Kokkos::View<
lno_t*, Kokkos::Device<ExecutionSpace, MemorySpace>> adjs_view,
70 Kokkos::View<
offset_t*, Kokkos::Device<ExecutionSpace, MemorySpace>> offset_view,
71 Teuchos::RCP<femv_t> femv,
72 Kokkos::View<
lno_t*, Kokkos::Device<ExecutionSpace, MemorySpace> > vertex_list,
73 size_t vertex_list_size = 0,
74 bool use_vertex_based_coloring=
false){
75 using KernelHandle = KokkosKernels::Experimental::KokkosKernelsHandle
77 using lno_row_view_t = Kokkos::View<offset_t*,Kokkos::Device<ExecutionSpace, MemorySpace>>;
78 using lno_nnz_view_t = Kokkos::View<lno_t*, Kokkos::Device<ExecutionSpace, MemorySpace>>;
83 if(use_vertex_based_coloring){
84 kh.create_graph_coloring_handle(KokkosGraph::COLORING_VBBIT);
86 kh.create_graph_coloring_handle(KokkosGraph::COLORING_EB);
91 if(vertex_list_size != 0){
92 kh.get_graph_coloring_handle()->set_vertex_list(vertex_list, vertex_list_size);
99 auto femvColors = femv->template getLocalView<Kokkos::Device<ExecutionSpace,MemorySpace> >(Tpetra::Access::ReadWrite);
100 auto sv = subview(femvColors, Kokkos::ALL, 0);
101 kh.get_graph_coloring_handle()->set_vertex_colors(sv);
104 kh.get_graph_coloring_handle()->set_tictoc(this->
verbose);
107 KokkosGraph::Experimental::graph_color_symbolic
108 <KernelHandle, lno_row_view_t, lno_nnz_view_t> (&kh,
117 std::cout<<
"\nKokkosKernels Coloring: "
118 <<kh.get_graph_coloring_handle()->get_overall_coloring_time()
120 <<kh.get_graph_coloring_handle()->get_num_phases()
125 virtual void colorInterior(
const size_t nVtx,
126 Kokkos::View<lno_t*,device_type > adjs_view,
127 Kokkos::View<offset_t*,device_type > offset_view,
128 Teuchos::RCP<femv_t> femv,
129 Kokkos::View<lno_t*, device_type > vertex_list,
130 size_t vertex_list_size = 0,
133 this->localColoring<execution_space, memory_space>(nVtx,
142 virtual void colorInterior_serial(
const size_t nVtx,
143 typename Kokkos::View<lno_t*, device_type >::HostMirror adjs_view,
144 typename Kokkos::View<offset_t*,device_type >::HostMirror offset_view,
145 Teuchos::RCP<femv_t> femv,
146 typename Kokkos::View<lno_t*, device_type>::HostMirror vertex_list,
147 size_t vertex_list_size = 0,
148 bool recolor=
false) {
149 this->localColoring<host_exec, host_mem>(nVtx,
159 template <
class ExecutionSpace,
typename MemorySpace>
162 Kokkos::Device<ExecutionSpace, MemorySpace>> dist_offsets,
164 Kokkos::Device<ExecutionSpace, MemorySpace>> dist_adjs,
166 Kokkos::Device<ExecutionSpace, MemorySpace>> femv_colors,
168 Kokkos::Device<ExecutionSpace, MemorySpace>> boundary_verts_view,
170 Kokkos::Device<ExecutionSpace, MemorySpace> > verts_to_recolor_view,
172 Kokkos::Device<ExecutionSpace, MemorySpace>,
173 Kokkos::MemoryTraits<Kokkos::Atomic> > verts_to_recolor_size_atomic,
175 Kokkos::Device<ExecutionSpace, MemorySpace> > verts_to_send_view,
176 Kokkos::View<
size_t*,
177 Kokkos::Device<ExecutionSpace, MemorySpace>,
178 Kokkos::MemoryTraits<Kokkos::Atomic> > verts_to_send_size_atomic,
179 Kokkos::View<
size_t*, Kokkos::Device<ExecutionSpace, MemorySpace> > recoloringSize,
181 Kokkos::Device<ExecutionSpace, MemorySpace> > rand,
183 Kokkos::Device<ExecutionSpace, MemorySpace> > gid,
185 Kokkos::Device<ExecutionSpace, MemorySpace> > ghost_degrees,
186 bool recolor_degrees){
187 size_t local_recoloring_size;
188 Kokkos::RangePolicy<ExecutionSpace> policy(n_local,rand.size());
189 Kokkos::parallel_reduce(
"D1-2GL Conflict Detection",policy, KOKKOS_LAMBDA (
const int& i,
size_t& recoloring_size){
191 int currColor = femv_colors(localIdx);
192 int currDegree = ghost_degrees(i-n_local);
193 for(
offset_t j = dist_offsets(i); j < dist_offsets(i+1); j++){
194 int nborColor = femv_colors(dist_adjs(j));
196 if((
size_t)dist_adjs(j) < n_local) nborDegree = dist_offsets(dist_adjs(j)+1) - dist_offsets(dist_adjs(j));
197 else nborDegree = ghost_degrees(dist_adjs(j) - n_local);
198 if(currColor == nborColor ){
199 if(currDegree < nborDegree && recolor_degrees){
200 femv_colors(localIdx) = 0;
203 }
else if(nborDegree < currDegree && recolor_degrees){
204 femv_colors(dist_adjs(j)) = 0;
206 }
else if(rand(localIdx) > rand(dist_adjs(j))){
208 femv_colors(localIdx) = 0;
210 }
else if(rand(dist_adjs(j)) > rand(localIdx)){
212 femv_colors(dist_adjs(j)) = 0;
214 if (gid(localIdx) >= gid(dist_adjs(j))){
215 femv_colors(localIdx) = 0;
219 femv_colors(dist_adjs(j)) = 0;
225 },local_recoloring_size);
226 Kokkos::deep_copy(recoloringSize, local_recoloring_size);
228 Kokkos::parallel_for(
"rebuild verts_to_send and verts_to_recolor",
229 Kokkos::RangePolicy<ExecutionSpace>(0,femv_colors.size()),
230 KOKKOS_LAMBDA (
const size_t& i){
231 if(femv_colors(i) == 0){
233 verts_to_send_view(verts_to_send_size_atomic(0)++) = i;
235 verts_to_recolor_view(verts_to_recolor_size_atomic(0)++) = i;
243 Kokkos::View<offset_t*, device_type > dist_offsets_dev,
244 Kokkos::View<lno_t*, device_type > dist_adjs_dev,
245 Kokkos::View<int*,device_type > femv_colors,
246 Kokkos::View<lno_t*, device_type > boundary_verts_view,
251 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_recolor_size_atomic,
254 Kokkos::View<
size_t*,
256 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_send_size_atomic,
257 Kokkos::View<size_t*, device_type> recoloringSize,
264 bool recolor_degrees){
265 this->detectD1Conflicts<execution_space, memory_space>(n_local,
270 verts_to_recolor_view,
271 verts_to_recolor_size_atomic,
273 verts_to_send_size_atomic,
282 typename Kokkos::View<offset_t*, device_type >::HostMirror dist_offsets_host,
283 typename Kokkos::View<lno_t*, device_type >::HostMirror dist_adjs_host,
284 typename Kokkos::View<int*,device_type >::HostMirror femv_colors,
285 typename Kokkos::View<lno_t*, device_type >::HostMirror boundary_verts_view,
286 typename Kokkos::View<lno_t*,device_type>::HostMirror verts_to_recolor,
287 typename Kokkos::View<int*,device_type>::HostMirror verts_to_recolor_size,
288 typename Kokkos::View<lno_t*,device_type>::HostMirror verts_to_send,
289 typename Kokkos::View<size_t*,device_type>::HostMirror verts_to_send_size,
290 typename Kokkos::View<size_t*, device_type>::HostMirror recoloringSize,
291 typename Kokkos::View<int*, device_type>::HostMirror rand,
292 typename Kokkos::View<gno_t*,device_type>::HostMirror gid,
293 typename Kokkos::View<gno_t*,device_type>::HostMirror ghost_degrees,
294 bool recolor_degrees) {
295 this->detectD1Conflicts<host_exec, host_mem >(n_local,
301 verts_to_recolor_size,
313 Kokkos::View<offset_t*, device_type> dist_offsets_dev,
314 Kokkos::View<lno_t*, device_type> dist_adjs_dev,
315 typename Kokkos::View<offset_t*, device_type>::HostMirror dist_offsets_host,
316 typename Kokkos::View<lno_t*, device_type>::HostMirror dist_adjs_host,
317 Kokkos::View<lno_t*, device_type>& boundary_verts,
320 Kokkos::View<
size_t*,
322 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_send_size_atomic){
324 Kokkos::parallel_for(
"constructBoundary",
325 Kokkos::RangePolicy<execution_space, int>(0,n_local),
326 KOKKOS_LAMBDA(
const int& i){
327 for(
offset_t j = dist_offsets_dev(i); j < dist_offsets_dev(i+1); j++){
328 if((
size_t)dist_adjs_dev(j) >= n_local){
329 verts_to_send_view(verts_to_send_size_atomic(0)++) = i;
333 for(
offset_t k = dist_offsets_dev(dist_adjs_dev(j)); k < dist_offsets_dev(dist_adjs_dev(j)+1); k++){
334 if((
size_t)dist_adjs_dev(k) >= n_local){
335 verts_to_send_view(verts_to_send_size_atomic(0)++) = i;
349 const RCP<const base_adapter_t> &adapter_,
350 const RCP<Teuchos::ParameterList> &pl_,
351 const RCP<Environment> &env_,
352 const RCP<
const Teuchos::Comm<int> > &comm_)
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
Tpetra::FEMultiVector< femv_scalar_t, lno_t, gno_t > femv_t
typename Adapter::gno_t gno_t
virtual void constructBoundary(const size_t n_local, Kokkos::View< offset_t *, device_type > dist_offsets_dev, Kokkos::View< lno_t *, device_type > dist_adjs_dev, typename Kokkos::View< offset_t *, device_type >::HostMirror dist_offsets_host, typename Kokkos::View< lno_t *, device_type >::HostMirror dist_adjs_host, Kokkos::View< lno_t *, device_type > &boundary_verts, Kokkos::View< lno_t *, device_type > verts_to_send_view, Kokkos::View< size_t *, device_type, Kokkos::MemoryTraits< Kokkos::Atomic >> verts_to_send_size_atomic)
typename Adapter::lno_t lno_t
map_t::global_ordinal_type gno_t
typename Adapter::offset_t offset_t
typename Adapter::lno_t lno_t
virtual void detectConflicts_serial(const size_t n_local, typename Kokkos::View< offset_t *, device_type >::HostMirror dist_offsets_host, typename Kokkos::View< lno_t *, device_type >::HostMirror dist_adjs_host, typename Kokkos::View< int *, device_type >::HostMirror femv_colors, typename Kokkos::View< lno_t *, device_type >::HostMirror boundary_verts_view, typename Kokkos::View< lno_t *, device_type >::HostMirror verts_to_recolor, typename Kokkos::View< int *, device_type >::HostMirror verts_to_recolor_size, typename Kokkos::View< lno_t *, device_type >::HostMirror verts_to_send, typename Kokkos::View< size_t *, device_type >::HostMirror verts_to_send_size, typename Kokkos::View< size_t *, device_type >::HostMirror recoloringSize, typename Kokkos::View< int *, device_type >::HostMirror rand, typename Kokkos::View< gno_t *, device_type >::HostMirror gid, typename Kokkos::View< gno_t *, device_type >::HostMirror ghost_degrees, bool recolor_degrees)
typename femv_t::host_view_type::device_type::memory_space host_mem
AlgDistance1TwoGhostLayer(const RCP< const base_adapter_t > &adapter_, const RCP< Teuchos::ParameterList > &pl_, const RCP< Environment > &env_, const RCP< const Teuchos::Comm< int > > &comm_)
virtual void detectConflicts(const size_t n_local, Kokkos::View< offset_t *, device_type > dist_offsets_dev, Kokkos::View< lno_t *, device_type > dist_adjs_dev, Kokkos::View< int *, device_type > femv_colors, Kokkos::View< lno_t *, device_type > boundary_verts_view, Kokkos::View< lno_t *, device_type > verts_to_recolor_view, Kokkos::View< int *, device_type, Kokkos::MemoryTraits< Kokkos::Atomic >> verts_to_recolor_size_atomic, Kokkos::View< lno_t *, device_type > verts_to_send_view, Kokkos::View< size_t *, device_type, Kokkos::MemoryTraits< Kokkos::Atomic >> verts_to_send_size_atomic, Kokkos::View< size_t *, device_type > recoloringSize, Kokkos::View< int *, device_type > rand, Kokkos::View< gno_t *, device_type > gid, Kokkos::View< gno_t *, device_type > ghost_degrees, bool recolor_degrees)
map_t::local_ordinal_type lno_t
typename Adapter::offset_t offset_t
void detectD1Conflicts(const size_t n_local, Kokkos::View< offset_t *, Kokkos::Device< ExecutionSpace, MemorySpace >> dist_offsets, Kokkos::View< lno_t *, Kokkos::Device< ExecutionSpace, MemorySpace >> dist_adjs, Kokkos::View< int *, Kokkos::Device< ExecutionSpace, MemorySpace >> femv_colors, Kokkos::View< lno_t *, Kokkos::Device< ExecutionSpace, MemorySpace >> boundary_verts_view, Kokkos::View< lno_t *, Kokkos::Device< ExecutionSpace, MemorySpace > > verts_to_recolor_view, Kokkos::View< int *, Kokkos::Device< ExecutionSpace, MemorySpace >, Kokkos::MemoryTraits< Kokkos::Atomic > > verts_to_recolor_size_atomic, Kokkos::View< lno_t *, Kokkos::Device< ExecutionSpace, MemorySpace > > verts_to_send_view, Kokkos::View< size_t *, Kokkos::Device< ExecutionSpace, MemorySpace >, Kokkos::MemoryTraits< Kokkos::Atomic > > verts_to_send_size_atomic, Kokkos::View< size_t *, Kokkos::Device< ExecutionSpace, MemorySpace > > recoloringSize, Kokkos::View< int *, Kokkos::Device< ExecutionSpace, MemorySpace > > rand, Kokkos::View< gno_t *, Kokkos::Device< ExecutionSpace, MemorySpace > > gid, Kokkos::View< gno_t *, Kokkos::Device< ExecutionSpace, MemorySpace > > ghost_degrees, bool recolor_degrees)
typename femv_t::device_type device_type
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
typename femv_t::host_view_type::device_type::execution_space host_exec
Defines the ColoringSolution class.
Defines the GraphModel interface.
A gathering of useful namespace methods.
typename Adapter::base_adapter_t base_adapter_t
typename device_type::execution_space execution_space
Tpetra::Map< lno_t, gno_t > map_t
typename Adapter::scalar_t scalar_t
typename device_type::memory_space memory_space
AlltoAll communication methods.