1#ifndef _ZOLTAN2_2GHOSTLAYER_HPP_
2#define _ZOLTAN2_2GHOSTLAYER_HPP_
5#include <unordered_map>
22#include "Tpetra_Core.hpp"
23#include "Teuchos_RCP.hpp"
24#include "Tpetra_Import.hpp"
25#include "Tpetra_FEMultiVector.hpp"
27#include "KokkosKernels_Handle.hpp"
28#include "KokkosKernels_IOUtils.hpp"
29#include "KokkosGraph_Distance1Color.hpp"
30#include "KokkosGraph_Distance1ColorHandle.hpp"
40template <
typename Adapter>
50 using map_t = Tpetra::Map<lno_t,gno_t>;
52 using femv_t = Tpetra::FEMultiVector<femv_scalar_t, lno_t, gno_t>;
56 using host_exec =
typename Kokkos::View<device_type>::HostMirror::execution_space;
57 using host_mem =
typename Kokkos::View<device_type>::HostMirror::memory_space;
61 gettimeofday(&tp, NULL);
62 return ((
double) (tp.tv_sec) + 1e-6 * tp.tv_usec);
85 virtual void colorInterior(
const size_t nVtx,
86 Kokkos::View<lno_t*, device_type > adjs_view,
87 Kokkos::View<offset_t*,device_type > offset_view,
88 Teuchos::RCP<femv_t> femv,
89 Kokkos::View<lno_t*, device_type> vertex_list,
90 size_t vertex_list_size = 0,
91 bool recolor=
false) = 0;
94 virtual void colorInterior_serial(
const size_t nVtx,
95 typename Kokkos::View<lno_t*, device_type >::HostMirror adjs_view,
96 typename Kokkos::View<offset_t*,device_type >::HostMirror offset_view,
97 Teuchos::RCP<femv_t> femv,
98 typename Kokkos::View<lno_t*, device_type>::HostMirror vertex_list,
99 size_t vertex_list_size = 0,
100 bool recolor=
false) = 0;
193 Kokkos::View<offset_t*, device_type > dist_offsets_dev,
194 Kokkos::View<lno_t*, device_type > dist_adjs_dev,
195 Kokkos::View<int*,device_type > femv_colors,
196 Kokkos::View<lno_t*, device_type > boundary_verts_view,
201 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_recolor_size_atomic,
204 Kokkos::View<
size_t*,
206 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_send_size_atomic,
207 Kokkos::View<size_t*, device_type> recoloringSize,
214 bool recolor_degrees) = 0;
218 typename Kokkos::View<offset_t*, device_type >::HostMirror dist_offsets_host,
219 typename Kokkos::View<lno_t*, device_type >::HostMirror dist_adjs_host,
220 typename Kokkos::View<int*,device_type >::HostMirror femv_colors,
221 typename Kokkos::View<lno_t*, device_type >::HostMirror boundary_verts_view,
222 typename Kokkos::View<lno_t*,device_type>::HostMirror verts_to_recolor_view,
223 typename Kokkos::View<int*,device_type>::HostMirror verts_to_recolor_size_atomic,
224 typename Kokkos::View<lno_t*,device_type>::HostMirror verts_to_send_view,
225 typename Kokkos::View<size_t*,device_type>::HostMirror verts_to_send_size_atomic,
226 typename Kokkos::View<size_t*, device_type>::HostMirror recoloringSize,
227 typename Kokkos::View<int*, device_type>::HostMirror rand,
228 typename Kokkos::View<gno_t*,device_type>::HostMirror gid,
229 typename Kokkos::View<gno_t*,device_type>::HostMirror ghost_degrees,
230 bool recolor_degrees) = 0;
259 Kokkos::View<offset_t*, device_type> dist_offsets_dev,
260 Kokkos::View<lno_t*, device_type> dist_adjs_dev,
261 typename Kokkos::View<offset_t*, device_type>::HostMirror dist_offsets_host,
262 typename Kokkos::View<lno_t*, device_type>::HostMirror dist_adjs_host,
263 Kokkos::View<lno_t*, device_type>& boundary_verts,
266 Kokkos::View<
size_t*,
268 Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_send_size_atomic) = 0;
272 RCP<GraphModel<base_adapter_t> >
model;
273 RCP<Teuchos::ParameterList>
pl;
275 RCP<const Teuchos::Comm<int> >
comm;
348 void constructSecondGhostLayer(std::vector<gno_t>& ownedPlusGhosts,
349 const std::vector<int>& owners,
350 ArrayView<const gno_t> adjs,
351 ArrayView<const offset_t> offsets,
352 RCP<const map_t> mapOwned,
353 std::vector< gno_t>& adjs_2GL,
354 std::vector< offset_t>& offsets_2GL) {
358 std::vector<int> sendcounts(
comm->getSize(),0);
359 std::vector<size_t> sdispls(
comm->getSize()+1,0);
362 if(
verbose) std::cout<<
comm->getRank()<<
": building sendcounts\n";
363 for(
size_t i = 0; i < owners.size(); i++){
364 if(owners[i] !=
comm->getRank()&& owners[i] !=-1) sendcounts[owners[i]]++;
367 if(
verbose) std::cout<<
comm->getRank()<<
": building sdispls\n";
368 size_t sendcount = 0;
369 for(
int i = 1; i <
comm->getSize()+1; i++){
370 sdispls[i] = sdispls[i-1] + sendcounts[i-1];
371 sendcount += sendcounts[i-1];
374 if(
verbose) std::cout<<
comm->getRank()<<
": building idx\n";
375 std::vector<gno_t> idx(
comm->getSize(),0);
376 for(
int i = 0; i <
comm->getSize(); i++){
380 if(
verbose) std::cout<<
comm->getRank()<<
": building sendbuf\n";
382 std::vector<gno_t> sendbuf(sendcount,0);
383 for(
size_t i = offsets.size()-1; i < owners.size(); i++){
384 if(owners[i] !=
comm->getRank() && owners[i] != -1){
385 sendbuf[idx[owners[i]]++] = ownedPlusGhosts[i];
390 if(
verbose) std::cout<<
comm->getRank()<<
": requesting GIDs from owners\n";
391 Teuchos::ArrayView<int> sendcounts_view = Teuchos::arrayViewFromVector(sendcounts);
392 Teuchos::ArrayView<gno_t> sendbuf_view = Teuchos::arrayViewFromVector(sendbuf);
393 Teuchos::ArrayRCP<gno_t> recvbuf;
394 std::vector<int> recvcounts(
comm->getSize(),0);
395 Teuchos::ArrayView<int> recvcounts_view = Teuchos::arrayViewFromVector(recvcounts);
396 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, sendbuf_view, sendcounts_view, recvbuf, recvcounts_view);
398 if(
verbose) std::cout<<
comm->getRank()<<
": done communicating\n";
401 if(
verbose) std::cout<<
comm->getRank()<<
": building rdispls\n";
402 gno_t recvcounttotal = 0;
403 std::vector<int> rdispls(
comm->getSize()+1,0);
404 for(
size_t i = 1; i<recvcounts.size()+1; i++){
405 rdispls[i] = rdispls[i-1] + recvcounts[i-1];
406 recvcounttotal += recvcounts[i-1];
410 std::vector<offset_t> sendDegrees(recvcounttotal,0);
412 std::vector<int> adjsendcounts(
comm->getSize(),0);
413 if(
verbose) std::cout<<
comm->getRank()<<
": building adjacency counts\n";
414 for(
int i = 0; i <
comm->getSize(); i++){
415 adjsendcounts[i] = 0;
416 for(
int j = rdispls[i]; j < rdispls[i+1]; j++){
417 lno_t lid = mapOwned->getLocalElement(recvbuf[j]);
418 offset_t degree = offsets[lid+1] - offsets[lid];
419 sendDegrees[j] = degree;
421 adjsendcounts[i] += degree;
425 if(
verbose) std::cout<<
comm->getRank()<<
": sending degrees back to requestors\n";
426 Teuchos::ArrayView<offset_t> sendDegrees_view = Teuchos::arrayViewFromVector(sendDegrees);
427 Teuchos::ArrayRCP<offset_t> recvDegrees;
428 std::vector<int> recvDegreesCount(
comm->getSize(),0);
429 Teuchos::ArrayView<int> recvDegreesCount_view = Teuchos::arrayViewFromVector(recvDegreesCount);
430 Zoltan2::AlltoAllv<offset_t>(*
comm, *
env, sendDegrees_view, recvcounts_view, recvDegrees, recvDegreesCount_view);
434 if(
verbose) std::cout<<
comm->getRank()<<
": determining number of rounds necessary\n";
436 for(
int i = 0; i <
comm->getSize(); i++){
437 if(adjsendcounts[i]*
sizeof(
gno_t)/ INT_MAX > (
size_t)rounds){
438 rounds = (adjsendcounts[i]*
sizeof(
gno_t)/INT_MAX)+1;
444 Teuchos::reduceAll<int>(*
comm, Teuchos::REDUCE_MAX, 1, &rounds, &max_rounds);
446 if(
verbose) std::cout<<
comm->getRank()<<
": building per_proc sums\n";
448 std::vector<std::vector<uint64_t>> per_proc_round_adj_sums(max_rounds+1,std::vector<uint64_t>(
comm->getSize(),0));
449 std::vector<std::vector<uint64_t>> per_proc_round_vtx_sums(max_rounds+1,std::vector<uint64_t>(
comm->getSize(),0));
451 if(
verbose) std::cout<<
comm->getRank()<<
": filling per_proc sums\n";
453 for(
int proc_to_send = 0; proc_to_send <
comm->getSize(); proc_to_send++){
455 for(
size_t j = sdispls[proc_to_send]; j < sdispls[proc_to_send+1]; j++){
456 if((per_proc_round_adj_sums[curr_round][proc_to_send] + recvDegrees[j])*
sizeof(
gno_t) > INT_MAX){
459 per_proc_round_adj_sums[curr_round][proc_to_send] += recvDegrees[j];
460 per_proc_round_vtx_sums[curr_round][proc_to_send]++;
464 if(
verbose) std::cout<<
comm->getRank()<<
": building recv GID schedule\n";
470 std::vector<std::vector<std::vector<gno_t>>> recv_GID_per_proc_per_round(
471 max_rounds+1,std::vector<std::vector<gno_t>>(
472 comm->getSize(),std::vector<gno_t>(0)));
473 for(
int i = 0; i < max_rounds; i++){
474 for(
int j = 0; j <
comm->getSize(); j++){
475 recv_GID_per_proc_per_round[i][j] = std::vector<gno_t>(sendcounts[j],0);
479 if(
verbose) std::cout<<
comm->getRank()<<
": filling out recv GID schedule\n";
480 for(
int i = 0; i <
comm->getSize(); i++){
483 for(
size_t j = sdispls[i]; j < sdispls[i+1]; j++){
484 if(curr_idx > per_proc_round_vtx_sums[curr_round][i]){
488 recv_GID_per_proc_per_round[curr_round][i][curr_idx++] = j;
492 if(
verbose) std::cout<<
comm->getRank()<<
": reordering gids and degrees in the order they'll be received\n";
507 std::vector<gno_t> final_gid_vec(sendcount, 0);
508 std::vector<offset_t> final_degree_vec(sendcount,0);
509 gno_t reorder_idx = 0;
510 for(
int i = 0; i < max_rounds; i++){
511 for(
int j = 0; j <
comm->getSize(); j++){
512 for(
size_t k = 0; k < per_proc_round_vtx_sums[i][j]; k++){
513 final_gid_vec[reorder_idx] = sendbuf[recv_GID_per_proc_per_round[i][j][k]];
514 final_degree_vec[reorder_idx++] = recvDegrees[recv_GID_per_proc_per_round[i][j][k]];
522 bool reorganized =
false;
523 for(
size_t i = 0; i < sendcount; i++){
524 if(final_gid_vec[i] != sendbuf[i]) reorganized =
true;
530 if(!reorganized && (max_rounds > 1)) std::cout<<
comm->getRank()<<
": did not reorgainze GIDs, but probably should have\n";
531 if(reorganized && (max_rounds == 1)) std::cout<<
comm->getRank()<<
": reorganized GIDs, but probably should not have\n";
543 for (
size_t i = 0; i < sendcount; i++){
544 ownedPlusGhosts[i+offsets.size()-1] = final_gid_vec[i];
549 std::cout<<
comm->getRank()<<
": done remapping\n";
550 std::cout<<
comm->getRank()<<
": building ghost offsets\n";
553 std::vector<offset_t> ghost_offsets(sendcount+1,0);
554 for(
size_t i = 1; i < sendcount+1; i++){
555 ghost_offsets[i] = ghost_offsets[i-1] + final_degree_vec[i-1];
559 if(
verbose) std::cout<<
comm->getRank()<<
": going through the sending rounds\n";
561 std::vector<uint64_t> curr_idx_per_proc(
comm->getSize(),0);
562 for(
int i = 0; i <
comm->getSize(); i++) curr_idx_per_proc[i] = rdispls[i];
563 for(
int round = 0; round < max_rounds; round++){
565 std::vector<gno_t> send_adj;
566 std::vector<int> send_adj_counts(
comm->getSize(),0);
567 if(
verbose) std::cout<<
comm->getRank()<<
": round "<<round<<
", constructing send_adj\n";
569 for(
int curr_proc = 0; curr_proc <
comm->getSize(); curr_proc++){
570 uint64_t curr_adj_sum = 0;
572 while( curr_idx_per_proc[curr_proc] < (
size_t)rdispls[curr_proc+1]){
573 lno_t lid = mapOwned->getLocalElement(recvbuf[curr_idx_per_proc[curr_proc]++]);
577 if((curr_adj_sum + (offsets[lid+1]-offsets[lid]))*
sizeof(
gno_t) >= INT_MAX){
582 curr_adj_sum += (offsets[lid+1] - offsets[lid]);
583 for(
offset_t j = offsets[lid]; j < offsets[lid+1]; j++){
584 send_adj.push_back(adjs[j]);
588 send_adj_counts[curr_proc] = curr_adj_sum;
590 if(
verbose) std::cout<<
comm->getRank()<<
": round "<<round<<
", sending...\n";
592 Teuchos::ArrayView<gno_t> send_adjs_view = Teuchos::arrayViewFromVector(send_adj);
593 Teuchos::ArrayView<int> adjsendcounts_view = Teuchos::arrayViewFromVector(send_adj_counts);
594 Teuchos::ArrayRCP<gno_t> ghost_adjs;
595 uint64_t recv_adjs_count = 0;
596 for(
int i = 0; i <
comm->getSize(); i++){
597 recv_adjs_count += per_proc_round_adj_sums[round][i];
599 std::vector<int> adjrecvcounts(
comm->getSize(),0);
600 Teuchos::ArrayView<int> adjsrecvcounts_view = Teuchos::arrayViewFromVector(adjrecvcounts);
601 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, send_adjs_view, adjsendcounts_view, ghost_adjs, adjsrecvcounts_view);
605 adjs_2GL.push_back(ghost_adjs[i]);
608 if(
verbose) std::cout<<
comm->getRank()<<
": constructing offsets\n";
610 for(
size_t i = 0; i < sendcount+1; i++){
611 offsets_2GL.push_back(ghost_offsets[i]);
613 if(
verbose) std::cout<<
comm->getRank()<<
": done building 2nd ghost layer\n";
643 double doOwnedToGhosts(RCP<const map_t> mapOwnedPlusGhosts,
645 typename Kokkos::View<lno_t*,device_type>::HostMirror verts_to_send,
646 typename Kokkos::View<size_t*,device_type>::HostMirror verts_to_send_size,
647 Teuchos::RCP<femv_t> femv,
648 const std::unordered_map<
lno_t, std::vector<int>>& procs_to_send,
651 auto femvColors = femv->getLocalViewHost(Tpetra::Access::ReadWrite);
652 auto colors = subview(femvColors, Kokkos::ALL, 0);
654 int nprocs =
comm->getSize();
655 std::vector<int> sendcnts(
comm->getSize(), 0);
656 std::vector<gno_t> sdispls(
comm->getSize()+1, 0);
659 for(
size_t i = 0; i < verts_to_send_size(0); i++){
660 for(
size_t j = 0; j < procs_to_send.at(verts_to_send(i)).size(); j++){
661 sendcnts[procs_to_send.at(verts_to_send(i))[j]] += 2;
667 std::vector<int> sentcount(nprocs, 0);
669 for(
int i = 1; i <
comm->getSize()+1; i++){
670 sdispls[i] = sdispls[i-1] + sendcnts[i-1];
671 sendsize += sendcnts[i-1];
673 total_sent = sendsize;
674 std::vector<gno_t> sendbuf(sendsize,0);
679 for(
size_t i = 0; i < verts_to_send_size(0); i++){
680 std::vector<int> procs = procs_to_send.at(verts_to_send(i));
681 for(
size_t j = 0; j < procs.size(); j++){
682 size_t idx = sdispls[procs[j]] + sentcount[procs[j]];
683 sentcount[procs[j]] += 2;
684 sendbuf[idx++] = mapOwnedPlusGhosts->getGlobalElement(verts_to_send(i));
685 sendbuf[idx] = colors(verts_to_send(i));
689 Teuchos::ArrayView<int> sendcnts_view = Teuchos::arrayViewFromVector(sendcnts);
690 Teuchos::ArrayView<gno_t> sendbuf_view = Teuchos::arrayViewFromVector(sendbuf);
691 Teuchos::ArrayRCP<gno_t> recvbuf;
692 std::vector<int> recvcnts(
comm->getSize(), 0);
693 Teuchos::ArrayView<int> recvcnts_view = Teuchos::arrayViewFromVector(recvcnts);
697 double comm_total = 0.0;
698 double comm_temp =
timer();
700 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, sendbuf_view, sendcnts_view, recvbuf, recvcnts_view);
701 comm_total +=
timer() - comm_temp;
705 for(
int i = 0; i < recvcnts_view.size(); i++){
706 recvsize += recvcnts_view[i];
708 total_recvd = recvsize;
710 for(
int i = 0; i < recvsize; i+=2){
711 size_t lid = mapOwnedPlusGhosts->getLocalElement(recvbuf[i]);
712 colors(lid) = recvbuf[i+1];
721 const RCP<const base_adapter_t> &adapter_,
722 const RCP<Teuchos::ParameterList> &pl_,
723 const RCP<Environment> &env_,
724 const RCP<
const Teuchos::Comm<int> > &comm_)
726 verbose =
pl->get<
bool>(
"verbose",
false);
727 timing =
pl->get<
bool>(
"timing",
false);
735 ArrayView<const gno_t> vtxIDs;
736 ArrayView<StridedData<lno_t, scalar_t> > vwgts;
737 size_t nVtx =
model->getVertexList(vtxIDs, vwgts);
741 ArrayView<const gno_t> adjs;
743 ArrayView<const offset_t> offsets;
744 ArrayView<StridedData<lno_t, scalar_t> > ewgts;
745 model->getEdgeList(adjs, offsets, ewgts);
748 std::unordered_map<gno_t,lno_t> globalToLocal;
760 std::vector<gno_t> ownedPlusGhosts;
768 std::vector<int> owners;
771 for(
int i = 0; i < vtxIDs.size(); i++){
772 globalToLocal[vtxIDs[i]] = i;
773 ownedPlusGhosts.push_back(vtxIDs[i]);
774 owners.push_back(
comm->getRank());
782 std::vector<lno_t> local_adjs;
783 for(
int i = 0; i < adjs.size(); i++){
784 if(globalToLocal.count(adjs[i])==0){
785 ownedPlusGhosts.push_back(adjs[i]);
786 globalToLocal[adjs[i]] = vtxIDs.size()+nGhosts;
789 local_adjs.push_back(globalToLocal[adjs[i]]);
795 RCP<const map_t> mapOwned = rcp(
new map_t(dummy, vtxIDs, 0,
comm));
798 std::vector<gno_t> ghosts;
799 std::vector<int> ghostowners;
800 for(
size_t i = nVtx; i < nVtx+nGhosts; i++){
801 ghosts.push_back(ownedPlusGhosts[i]);
802 ghostowners.push_back(-1);
806 ArrayView<int> owningProcs = Teuchos::arrayViewFromVector(ghostowners);
807 ArrayView<const gno_t> gids = Teuchos::arrayViewFromVector(ghosts);
808 mapOwned->getRemoteIndexList(gids, owningProcs);
811 for(
size_t i = 0; i < ghostowners.size(); i++){
812 owners.push_back(ghostowners[i]);
833 std::vector< gno_t> first_layer_ghost_adjs;
834 std::vector< offset_t> first_layer_ghost_offsets;
835 constructSecondGhostLayer(ownedPlusGhosts,owners, adjs, offsets, mapOwned,
836 first_layer_ghost_adjs, first_layer_ghost_offsets);
840 globalToLocal.clear();
841 for(
size_t i = 0; i < ownedPlusGhosts.size(); i++){
842 globalToLocal[ownedPlusGhosts[i]] = i;
847 for(
int i = 0 ; i < adjs.size(); i++){
848 local_adjs[i] = globalToLocal[adjs[i]];
858 std::vector<lno_t> local_ghost_adjs;
859 for(
size_t i = 0; i< first_layer_ghost_adjs.size(); i++ ){
860 if(globalToLocal.count(first_layer_ghost_adjs[i]) == 0){
861 ownedPlusGhosts.push_back(first_layer_ghost_adjs[i]);
862 globalToLocal[first_layer_ghost_adjs[i]] = vtxIDs.size() + nGhosts + n2Ghosts;
865 local_ghost_adjs.push_back(globalToLocal[first_layer_ghost_adjs[i]]);
869 if(
verbose) std::cout<<
comm->getRank()<<
": constructing Tpetra map with copies\n";
870 dummy = Teuchos::OrdinalTraits <Tpetra::global_size_t>::invalid();
871 RCP<const map_t> mapWithCopies = rcp(
new map_t(dummy,
872 Teuchos::arrayViewFromVector(ownedPlusGhosts),
874 if(
verbose) std::cout<<
comm->getRank()<<
": done constructing map with copies\n";
876 using import_t = Tpetra::Import<lno_t, gno_t>;
877 Teuchos::RCP<import_t> importer = rcp(
new import_t(mapOwned,
879 if(
verbose) std::cout<<
comm->getRank()<<
": done constructing importer\n";
880 Teuchos::RCP<femv_t> femv = rcp(
new femv_t(mapOwned,
882 if(
verbose) std::cout<<
comm->getRank()<<
": done constructing femv\n";
886 std::vector<int> rand(ownedPlusGhosts.size());
887 for(
size_t i = 0; i < rand.size(); i++){
888 std::srand(ownedPlusGhosts[i]);
889 rand[i] = std::rand();
893 std::vector<int> ghostOwners2(ownedPlusGhosts.size() -nVtx);
894 std::vector<gno_t> ghosts2(ownedPlusGhosts.size() - nVtx);
895 for(
size_t i = nVtx; i < ownedPlusGhosts.size(); i++) ghosts2[i-nVtx] = ownedPlusGhosts[i];
896 Teuchos::ArrayView<int> owners2 = Teuchos::arrayViewFromVector(ghostOwners2);
897 Teuchos::ArrayView<const gno_t> ghostGIDs = Teuchos::arrayViewFromVector(ghosts2);
898 mapOwned->getRemoteIndexList(ghostGIDs,owners2);
899 if(
verbose) std::cout<<
comm->getRank()<<
": done getting ghost owners\n";
904 std::cout<<
comm->getRank()<<
": calculating 2GL stats...\n";
906 std::vector<int> sendcounts(
comm->getSize(),0);
907 std::vector<gno_t> sdispls(
comm->getSize()+1,0);
909 for(
int i = nGhosts; i < ghostGIDs.size(); i++){
910 if(owners2[i] !=
comm->getRank()&& owners2[i] !=-1) sendcounts[owners2[i]]++;
914 for(
int i = 1; i <
comm->getSize()+1; i++){
915 sdispls[i] = sdispls[i-1] + sendcounts[i-1];
916 sendcount += sendcounts[i-1];
918 std::vector<gno_t> idx(
comm->getSize(),0);
919 for(
int i = 0; i <
comm->getSize(); i++){
923 std::vector<gno_t> sendbuf(sendcount,0);
924 for(
size_t i = nGhosts; i < (size_t)ghostGIDs.size(); i++){
925 if(owners2[i] !=
comm->getRank() && owners2[i] != -1){
926 sendbuf[idx[owners2[i]]++] = ghostGIDs[i];
930 Teuchos::ArrayView<int> sendcounts_view = Teuchos::arrayViewFromVector(sendcounts);
931 Teuchos::ArrayView<gno_t> sendbuf_view = Teuchos::arrayViewFromVector(sendbuf);
932 Teuchos::ArrayRCP<gno_t> recvbuf;
933 std::vector<int> recvcounts(
comm->getSize(),0);
934 Teuchos::ArrayView<int> recvcounts_view = Teuchos::arrayViewFromVector(recvcounts);
935 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, sendbuf_view, sendcounts_view, recvbuf, recvcounts_view);
936 std::vector<int> is_bndry_send(recvbuf.size(),0);
939 for(
int i = 0; i < recvbuf.size(); i++){
940 size_t lid = mapWithCopies->getLocalElement(recvbuf[i]);
941 is_bndry_send[i] = 0;
943 for(
offset_t j = offsets[lid]; j < offsets[lid+1]; j++){
944 if((
size_t)local_adjs[j] >= nVtx) is_bndry_send[i] = 1;
947 for(
offset_t j = first_layer_ghost_offsets[lid]; j < first_layer_ghost_offsets[lid+1]; j++){
948 if((
size_t)local_ghost_adjs[j] >= nVtx) is_bndry_send[i] = 1;
954 Teuchos::ArrayView<int> is_bndry_send_view = Teuchos::arrayViewFromVector(is_bndry_send);
955 Teuchos::ArrayRCP<int> is_bndry_recv;
956 std::vector<int> bndry_recvcounts(
comm->getSize(),0);
957 Teuchos::ArrayView<int> bndry_recvcounts_view = Teuchos::arrayViewFromVector(bndry_recvcounts);
958 Zoltan2::AlltoAllv<int> (*
comm, *
env, is_bndry_send_view, recvcounts_view, is_bndry_recv, bndry_recvcounts_view);
961 int boundaryverts = 0;
962 for(
int i = 0; i < is_bndry_recv.size(); i++){
963 boundaryverts += is_bndry_recv[i];
966 std::cout<<
comm->getRank()<<
": "<<boundaryverts<<
" boundary verts out of "<<n2Ghosts<<
" verts in 2GL\n";
971 Teuchos::ArrayView<const lno_t> local_adjs_view = Teuchos::arrayViewFromVector(local_adjs);
975 Teuchos::ArrayView<const offset_t> ghost_offsets = Teuchos::arrayViewFromVector(first_layer_ghost_offsets);
976 Teuchos::ArrayView<const lno_t> ghost_adjacencies = Teuchos::arrayViewFromVector(local_ghost_adjs);
977 Teuchos::ArrayView<const int> rand_view = Teuchos::arrayViewFromVector(rand);
978 Teuchos::ArrayView<const gno_t> gid_view = Teuchos::arrayViewFromVector(ownedPlusGhosts);
982 Teuchos::ArrayView<const lno_t> exportLIDs = importer->getExportLIDs();
983 Teuchos::ArrayView<const int> exportPIDs = importer->getExportPIDs();
987 std::unordered_map<lno_t, std::vector<int>> procs_to_send;
988 for(
int i = 0; i < exportLIDs.size(); i++){
989 procs_to_send[exportLIDs[i]].push_back(exportPIDs[i]);
993 twoGhostLayer(nVtx, nVtx+nGhosts, local_adjs_view, offsets, ghost_adjacencies, ghost_offsets,
994 femv, gid_view, rand_view, owners2, mapWithCopies, procs_to_send);
997 ArrayRCP<int> colors = solution->getColorsRCP();
998 auto femvdata = femv->getData(0);
999 for(
size_t i=0; i<nVtx; i++){
1000 colors[i] = femvdata[i];
1060 const Teuchos::ArrayView<const lno_t>& adjs,
1061 const Teuchos::ArrayView<const offset_t>& offsets,
1062 const Teuchos::ArrayView<const lno_t>& ghost_adjs,
1063 const Teuchos::ArrayView<const offset_t>& ghost_offsets,
1064 const Teuchos::RCP<femv_t>& femv,
1065 const Teuchos::ArrayView<const gno_t>& gids,
1066 const Teuchos::ArrayView<const int>& rand,
1067 const Teuchos::ArrayView<const int>& ghost_owners,
1068 RCP<const map_t> mapOwnedPlusGhosts,
1069 const std::unordered_map<
lno_t, std::vector<int>>& procs_to_send){
1071 double total_time = 0.0;
1072 double interior_time = 0.0;
1073 double comm_time = 0.0;
1074 double comp_time = 0.0;
1075 double recoloring_time=0.0;
1076 double conflict_detection = 0.0;
1080 const int numStatisticRecordingRounds = 100;
1083 const size_t n_ghosts = rand.size() - n_local;
1089 std::vector<int> deg_send_cnts(
comm->getSize(),0);
1090 std::vector<gno_t> deg_sdispls(
comm->getSize()+1,0);
1091 for(
int i = 0; i < ghost_owners.size(); i++){
1092 deg_send_cnts[ghost_owners[i]]++;
1095 gno_t deg_sendsize = 0;
1096 std::vector<int> deg_sentcount(
comm->getSize(),0);
1097 for(
int i = 1; i <
comm->getSize()+1; i++){
1098 deg_sdispls[i] = deg_sdispls[i-1] + deg_send_cnts[i-1];
1099 deg_sendsize += deg_send_cnts[i-1];
1101 std::vector<gno_t> deg_sendbuf(deg_sendsize,0);
1102 for(
int i = 0; i < ghost_owners.size(); i++){
1103 size_t idx = deg_sdispls[ghost_owners[i]] + deg_sentcount[ghost_owners[i]];
1104 deg_sentcount[ghost_owners[i]]++;
1105 deg_sendbuf[idx] = mapOwnedPlusGhosts->getGlobalElement(i+n_local);
1107 Teuchos::ArrayView<int> deg_send_cnts_view = Teuchos::arrayViewFromVector(deg_send_cnts);
1108 Teuchos::ArrayView<gno_t> deg_sendbuf_view = Teuchos::arrayViewFromVector(deg_sendbuf);
1109 Teuchos::ArrayRCP<gno_t> deg_recvbuf;
1110 std::vector<int> deg_recvcnts(
comm->getSize(),0);
1111 Teuchos::ArrayView<int> deg_recvcnts_view = Teuchos::arrayViewFromVector(deg_recvcnts);
1112 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, deg_sendbuf_view, deg_send_cnts_view, deg_recvbuf, deg_recvcnts_view);
1117 for(
int i = 0; i < deg_recvbuf.size(); i++){
1118 lno_t lid = mapOwnedPlusGhosts->getLocalElement(deg_recvbuf[i]);
1119 deg_recvbuf[i] = offsets[lid+1] - offsets[lid];
1122 ArrayRCP<gno_t> ghost_degrees;
1123 Zoltan2::AlltoAllv<gno_t>(*
comm, *
env, deg_recvbuf(), deg_recvcnts_view, ghost_degrees, deg_send_cnts_view);
1126 Kokkos::View<gno_t*, device_type> ghost_degrees_dev(
"ghost degree view",ghost_degrees.size());
1127 typename Kokkos::View<gno_t*, device_type>::HostMirror ghost_degrees_host = Kokkos::create_mirror(ghost_degrees_dev);
1128 for(
int i = 0; i < ghost_degrees.size(); i++){
1129 lno_t lid = mapOwnedPlusGhosts->getLocalElement(deg_sendbuf[i]);
1130 ghost_degrees_host(lid-n_local) = ghost_degrees[i];
1132 Kokkos::deep_copy(ghost_degrees_dev, ghost_degrees_host);
1135 gno_t recvPerRound[numStatisticRecordingRounds];
1136 gno_t sentPerRound[numStatisticRecordingRounds];
1143 for(
size_t i = 0; i < n_local; i++){
1144 offset_t curr_degree = offsets[i+1] - offsets[i];
1145 if(curr_degree > local_max_degree){
1146 local_max_degree = curr_degree;
1149 Teuchos::reduceAll<int, offset_t>(*
comm, Teuchos::REDUCE_MAX,1, &local_max_degree, &global_max_degree);
1150 if(
comm->getRank() == 0 &&
verbose) std::cout<<
"Input has max degree "<<global_max_degree<<
"\n";
1152 if(
verbose) std::cout<<
comm->getRank()<<
": constructing Kokkos Views for initial coloring\n";
1156 Kokkos::View<offset_t*, device_type> offsets_dev(
"Host Offset View", offsets.size());
1157 typename Kokkos::View<offset_t*, device_type>::HostMirror offsets_host = Kokkos::create_mirror(offsets_dev);
1158 Kokkos::View<lno_t*, device_type> adjs_dev(
"Host Adjacencies View", adjs.size());
1159 typename Kokkos::View<lno_t*, device_type>::HostMirror adjs_host = Kokkos::create_mirror(adjs_dev);
1160 for(Teuchos_Ordinal i = 0; i < offsets.size(); i++) offsets_host(i) = offsets[i];
1161 for(Teuchos_Ordinal i = 0; i < adjs.size(); i++) adjs_host(i) = adjs[i];
1162 Kokkos::deep_copy(offsets_dev,offsets_host);
1163 Kokkos::deep_copy(adjs_dev, adjs_host);
1167 if(
verbose) std::cout<<
comm->getRank()<<
": constructing Kokkos Views for recoloring\n";
1171 Kokkos::View<offset_t*, device_type> dist_degrees_dev(
"Owned+Ghost degree view",rand.size());
1172 typename Kokkos::View<offset_t*, device_type>::HostMirror dist_degrees_host = Kokkos::create_mirror(dist_degrees_dev);
1177 for(Teuchos_Ordinal i = 0; i < offsets.size()-1; i++) dist_degrees_host(i) = offsets[i+1] - offsets[i];
1179 for(Teuchos_Ordinal i = 0; i < ghost_offsets.size()-1; i++) dist_degrees_host(i+n_local) = ghost_offsets[i+1] - ghost_offsets[i];
1181 for(Teuchos_Ordinal i = 0; i < ghost_adjs.size(); i++){
1183 if((
size_t)ghost_adjs[i] >= n_total ){
1184 dist_degrees_host(ghost_adjs[i])++;
1212 Kokkos::View<offset_t*, device_type> dist_offsets_dev(
"Owned+Ghost Offset view", rand.size()+1);
1213 typename Kokkos::View<offset_t*, device_type>::HostMirror dist_offsets_host = Kokkos::create_mirror(dist_offsets_dev);
1216 dist_offsets_host(0) = 0;
1218 for(Teuchos_Ordinal i = 1; i < rand.size()+1; i++){
1219 dist_offsets_host(i) = dist_degrees_host(i-1) + dist_offsets_host(i-1);
1220 total_adjs += dist_degrees_host(i-1);
1222 Kokkos::View<lno_t*, device_type> dist_adjs_dev(
"Owned+Ghost adjacency view", total_adjs);
1223 typename Kokkos::View<lno_t*, device_type>::HostMirror dist_adjs_host = Kokkos::create_mirror(dist_adjs_dev);
1228 for(Teuchos_Ordinal i = 0; i < rand.size(); i++){
1229 dist_degrees_host(i) = 0;
1232 for(Teuchos_Ordinal i = 0; i < adjs.size(); i++) dist_adjs_host(i) = adjs[i];
1233 for(Teuchos_Ordinal i = adjs.size(); i < adjs.size() + ghost_adjs.size(); i++) dist_adjs_host(i) = ghost_adjs[i-adjs.size()];
1237 for(Teuchos_Ordinal i = 0; i < ghost_offsets.size()-1; i++){
1239 for(
offset_t j = ghost_offsets[i]; j < ghost_offsets[i+1]; j++){
1241 if((
size_t)ghost_adjs[j] >= n_total){
1243 dist_adjs_host(dist_offsets_host(ghost_adjs[j]) + dist_degrees_host(ghost_adjs[j])) = i + n_local;
1246 dist_degrees_host(ghost_adjs[j])++;
1251 Kokkos::deep_copy(dist_degrees_dev,dist_degrees_host);
1252 Kokkos::deep_copy(dist_offsets_dev,dist_offsets_host);
1253 Kokkos::deep_copy(dist_adjs_dev, dist_adjs_host);
1256 Kokkos::View<size_t*, device_type> recoloringSize(
"Recoloring Queue Size",1);
1257 typename Kokkos::View<size_t*, device_type>::HostMirror recoloringSize_host = Kokkos::create_mirror(recoloringSize);
1258 recoloringSize_host(0) = 0;
1259 Kokkos::deep_copy(recoloringSize, recoloringSize_host);
1262 if(
verbose) std::cout<<
comm->getRank()<<
": constructing rand and GIDs views\n";
1263 Kokkos::View<int*, device_type> rand_dev(
"Random View", rand.size());
1264 typename Kokkos::View<int*, device_type>::HostMirror rand_host = Kokkos::create_mirror(rand_dev);
1265 for(Teuchos_Ordinal i = 0; i < rand.size(); i ++) rand_host(i) = rand[i];
1266 Kokkos::deep_copy(rand_dev,rand_host);
1269 Kokkos::View<gno_t*, device_type> gid_dev(
"GIDs", gids.size());
1270 typename Kokkos::View<gno_t*, device_type>::HostMirror gid_host = Kokkos::create_mirror(gid_dev);
1271 for(Teuchos_Ordinal i = 0; i < gids.size(); i++) gid_host(i) = gids[i];
1272 Kokkos::deep_copy(gid_dev,gid_host);
1278 Kokkos::View<lno_t*, device_type> boundary_verts_dev;
1280 if(
verbose) std::cout<<
comm->getRank()<<
": constructing communication and recoloring lists\n";
1286 Kokkos::View<lno_t*, device_type> verts_to_recolor_view(
"verts to recolor", rand.size());
1287 typename Kokkos::View<lno_t*, device_type>::HostMirror verts_to_recolor_host = create_mirror(verts_to_recolor_view);
1290 Kokkos::View<int*, device_type> verts_to_recolor_size(
"verts to recolor size",1);
1291 Kokkos::View<int*, device_type, Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_recolor_size_atomic = verts_to_recolor_size;
1292 typename Kokkos::View<int*, device_type>::HostMirror verts_to_recolor_size_host = create_mirror(verts_to_recolor_size);
1295 verts_to_recolor_size_host(0) = 0;
1297 Kokkos::deep_copy(verts_to_recolor_size, verts_to_recolor_size_host);
1304 Kokkos::View<lno_t*, device_type> verts_to_send_view(
"verts to send", n_local);
1305 typename Kokkos::View<lno_t*, device_type>::HostMirror verts_to_send_host = create_mirror(verts_to_send_view);
1308 Kokkos::View<size_t*, device_type> verts_to_send_size(
"verts to send size",1);
1309 Kokkos::View<size_t*, device_type, Kokkos::MemoryTraits<Kokkos::Atomic>> verts_to_send_size_atomic = verts_to_send_size;
1310 typename Kokkos::View<size_t*, device_type>::HostMirror verts_to_send_size_host = create_mirror(verts_to_send_size);
1312 verts_to_send_size_host(0) = 0;
1313 Kokkos::deep_copy(verts_to_send_size, verts_to_send_size_host);
1315 if(
verbose) std::cout<<
comm->getRank()<<
": Constructing the boundary\n";
1320 constructBoundary(n_local, dist_offsets_dev, dist_adjs_dev, dist_offsets_host, dist_adjs_host, boundary_verts_dev,
1321 verts_to_send_view, verts_to_send_size_atomic);
1326 bool use_vbbit = (global_max_degree < 6000);
1331 interior_time =
timer();
1332 total_time =
timer();
1334 this->colorInterior(n_local, adjs_dev, offsets_dev, femv,adjs_dev,0,use_vbbit);
1335 interior_time =
timer() - interior_time;
1336 comp_time = interior_time;
1342 Kokkos::View<int*,device_type> ghost_colors(
"ghost color backups", n_ghosts);
1345 if(
verbose) std::cout<<
comm->getRank()<<
": communicating\n";
1350 Kokkos::deep_copy(verts_to_send_host, verts_to_send_view);
1351 Kokkos::deep_copy(verts_to_send_size_host, verts_to_send_size);
1353 comm_time = doOwnedToGhosts(mapOwnedPlusGhosts,n_local,verts_to_send_host,verts_to_send_size_host,femv,procs_to_send,sent,recv);
1354 sentPerRound[0] = sent;
1355 recvPerRound[0] = recv;
1361 auto femvColors = femv->getLocalViewDevice(Tpetra::Access::ReadWrite);
1362 auto femv_colors = subview(femvColors, Kokkos::ALL, 0);
1363 Kokkos::parallel_for(n_ghosts, KOKKOS_LAMBDA(
const int& i){
1364 ghost_colors(i) = femv_colors(i+n_local);
1368 double temp =
timer();
1370 bool recolor_degrees = this->pl->template get<bool>(
"recolor_degrees",
false);
1371 if(
verbose) std::cout<<
comm->getRank()<<
": detecting conflicts\n";
1374 verts_to_send_size_host(0) = 0;
1375 verts_to_recolor_size_host(0) = 0;
1376 recoloringSize_host(0) = 0;
1377 Kokkos::deep_copy(verts_to_send_size, verts_to_send_size_host);
1378 Kokkos::deep_copy(verts_to_recolor_size, verts_to_recolor_size_host);
1379 Kokkos::deep_copy(recoloringSize, recoloringSize_host);
1381 detectConflicts(n_local, dist_offsets_dev, dist_adjs_dev, femv_colors, boundary_verts_dev,
1382 verts_to_recolor_view, verts_to_recolor_size_atomic, verts_to_send_view, verts_to_send_size_atomic,
1383 recoloringSize, rand_dev, gid_dev, ghost_degrees_dev, recolor_degrees);
1387 Kokkos::deep_copy(verts_to_send_host, verts_to_send_view);
1388 Kokkos::deep_copy(verts_to_send_size_host, verts_to_send_size);
1389 Kokkos::deep_copy(recoloringSize_host, recoloringSize);
1390 Kokkos::deep_copy(verts_to_recolor_size_host, verts_to_recolor_size);
1392 if(
comm->getSize() > 1){
1393 conflict_detection =
timer() - temp;
1394 comp_time += conflict_detection;
1397 if(
verbose) std::cout<<
comm->getRank()<<
": starting to recolor\n";
1399 double totalPerRound[numStatisticRecordingRounds];
1400 double commPerRound[numStatisticRecordingRounds];
1401 double compPerRound[numStatisticRecordingRounds];
1402 double recoloringPerRound[numStatisticRecordingRounds];
1403 double conflictDetectionPerRound[numStatisticRecordingRounds];
1404 uint64_t vertsPerRound[numStatisticRecordingRounds];
1405 uint64_t incorrectGhostsPerRound[numStatisticRecordingRounds];
1406 int distributedRounds = 1;
1407 totalPerRound[0] = interior_time + comm_time + conflict_detection;
1408 recoloringPerRound[0] = 0;
1409 commPerRound[0] = comm_time;
1410 compPerRound[0] = interior_time + conflict_detection;
1411 conflictDetectionPerRound[0] = conflict_detection;
1412 recoloringPerRound[0] = 0;
1413 vertsPerRound[0] = 0;
1414 incorrectGhostsPerRound[0]=0;
1415 typename Kokkos::View<int*, device_type>::HostMirror ghost_colors_host;
1416 typename Kokkos::View<lno_t*, device_type>::HostMirror boundary_verts_host;
1417 size_t serial_threshold = this->pl->template get<int>(
"serial_threshold",0);
1419 size_t totalConflicts = 0;
1420 size_t localConflicts = recoloringSize_host(0);
1421 Teuchos::reduceAll<int,size_t>(*
comm, Teuchos::REDUCE_SUM, 1, &localConflicts, &totalConflicts);
1422 bool done = !totalConflicts;
1423 if(
comm->getSize()==1) done =
true;
1430 if(recoloringSize_host(0) < serial_threshold)
break;
1431 if(distributedRounds < numStatisticRecordingRounds) {
1432 vertsPerRound[distributedRounds] = verts_to_recolor_size_host(0);
1436 double recolor_temp =
timer();
1438 if(verts_to_recolor_size_host(0) > 0){
1439 this->colorInterior(femv_colors.size(), dist_adjs_dev, dist_offsets_dev,femv,verts_to_recolor_view,verts_to_recolor_size_host(0),use_vbbit);
1442 if(distributedRounds < numStatisticRecordingRounds){
1443 recoloringPerRound[distributedRounds] =
timer() - recolor_temp;
1444 recoloring_time += recoloringPerRound[distributedRounds];
1445 comp_time += recoloringPerRound[distributedRounds];
1446 compPerRound[distributedRounds] = recoloringPerRound[distributedRounds];
1447 totalPerRound[distributedRounds] = recoloringPerRound[distributedRounds];
1449 double recoloring_round_time =
timer() - recolor_temp;
1450 recoloring_time += recoloring_round_time;
1451 comp_time += recoloring_round_time;
1458 Kokkos::parallel_for(n_ghosts, KOKKOS_LAMBDA(
const int& i){
1459 femv_colors(i+n_local) = ghost_colors(i);
1467 femvColors =
decltype(femvColors)();
1468 femv_colors =
decltype(femv_colors)();
1469 double curr_comm_time = doOwnedToGhosts(mapOwnedPlusGhosts,n_local,verts_to_send_host,verts_to_send_size_host,femv,procs_to_send,sent,recv);
1470 comm_time += curr_comm_time;
1472 if(distributedRounds < numStatisticRecordingRounds){
1473 commPerRound[distributedRounds] = curr_comm_time;
1474 recvPerRound[distributedRounds] = recv;
1475 sentPerRound[distributedRounds] = sent;
1476 totalPerRound[distributedRounds] += commPerRound[distributedRounds];
1483 femvColors = femv->getLocalViewDevice(Tpetra::Access::ReadWrite);
1484 femv_colors = subview(femvColors, Kokkos::ALL, 0);
1485 Kokkos::parallel_for(n_ghosts, KOKKOS_LAMBDA(
const int& i){
1486 ghost_colors(i) = femv_colors(i+n_local);
1493 verts_to_send_size_host(0) = 0;
1494 verts_to_recolor_size_host(0) = 0;
1495 recoloringSize_host(0) = 0;
1496 Kokkos::deep_copy(verts_to_send_size, verts_to_send_size_host);
1497 Kokkos::deep_copy(verts_to_recolor_size, verts_to_recolor_size_host);
1498 Kokkos::deep_copy(recoloringSize, recoloringSize_host);
1501 double detection_temp =
timer();
1503 detectConflicts(n_local, dist_offsets_dev, dist_adjs_dev,femv_colors, boundary_verts_dev,
1504 verts_to_recolor_view, verts_to_recolor_size_atomic, verts_to_send_view, verts_to_send_size_atomic,
1505 recoloringSize, rand_dev, gid_dev, ghost_degrees_dev, recolor_degrees);
1508 Kokkos::deep_copy(verts_to_send_host, verts_to_send_view);
1509 Kokkos::deep_copy(verts_to_send_size_host, verts_to_send_size);
1511 Kokkos::deep_copy(verts_to_recolor_size_host, verts_to_recolor_size);
1512 Kokkos::deep_copy(recoloringSize_host, recoloringSize);
1514 if(distributedRounds < numStatisticRecordingRounds){
1515 conflictDetectionPerRound[distributedRounds] =
timer() - detection_temp;
1516 conflict_detection += conflictDetectionPerRound[distributedRounds];
1517 compPerRound[distributedRounds] += conflictDetectionPerRound[distributedRounds];
1518 totalPerRound[distributedRounds] += conflictDetectionPerRound[distributedRounds];
1519 comp_time += conflictDetectionPerRound[distributedRounds];
1521 double conflict_detection_round_time =
timer() - detection_temp;
1522 conflict_detection += conflict_detection_round_time;
1523 comp_time += conflict_detection_round_time;
1526 distributedRounds++;
1527 size_t localDone = recoloringSize_host(0);
1528 size_t globalDone = 0;
1529 Teuchos::reduceAll<int,size_t>(*
comm, Teuchos::REDUCE_SUM, 1, &localDone, &globalDone);
1539 if(recoloringSize_host(0) > 0 || !done){
1540 ghost_colors_host = Kokkos::create_mirror_view_and_copy(
host_mem(),ghost_colors,
"ghost_colors host mirror");
1541 boundary_verts_host = Kokkos::create_mirror_view_and_copy(
host_mem(),boundary_verts_dev,
"boundary_verts host mirror");
1547 femvColors =
decltype(femvColors)();
1548 femv_colors =
decltype(femv_colors)();
1549 while(recoloringSize_host(0) > 0 || !done){
1550 auto femvColors_host = femv->getLocalViewHost(Tpetra::Access::ReadWrite);
1551 auto colors_host = subview(femvColors_host, Kokkos::ALL, 0);
1552 if(distributedRounds < numStatisticRecordingRounds){
1553 vertsPerRound[distributedRounds] = recoloringSize_host(0);
1555 if(
verbose) std::cout<<
comm->getRank()<<
": starting to recolor, serial\n";
1558 double recolor_temp =
timer();
1559 if(verts_to_recolor_size_host(0) > 0){
1560 this->colorInterior_serial(colors_host.size(), dist_adjs_host, dist_offsets_host, femv,
1561 verts_to_recolor_host, verts_to_recolor_size_host(0),
true);
1563 if(distributedRounds < numStatisticRecordingRounds){
1564 recoloringPerRound[distributedRounds] =
timer() - recolor_temp;
1565 recoloring_time += recoloringPerRound[distributedRounds];
1566 comp_time += recoloringPerRound[distributedRounds];
1567 compPerRound[distributedRounds] = recoloringPerRound[distributedRounds];
1568 totalPerRound[distributedRounds] = recoloringPerRound[distributedRounds];
1570 double recoloring_serial_round_time =
timer() - recolor_temp;
1571 recoloring_time += recoloring_serial_round_time;
1572 comp_time += recoloring_serial_round_time;
1577 for(
size_t i = 0; i < n_ghosts; i++){
1578 colors_host(i+n_local) = ghost_colors_host(i);
1581 double curr_comm_time = doOwnedToGhosts(mapOwnedPlusGhosts, n_local,verts_to_send_host, verts_to_send_size_host, femv, procs_to_send, sent,recv);
1582 comm_time += curr_comm_time;
1584 if(distributedRounds < numStatisticRecordingRounds){
1585 commPerRound[distributedRounds] = curr_comm_time;
1586 recvPerRound[distributedRounds] = recv;
1587 sentPerRound[distributedRounds] = sent;
1588 totalPerRound[distributedRounds] += commPerRound[distributedRounds];
1593 for(
size_t i = 0; i < n_ghosts; i++){
1594 ghost_colors_host(i) = colors_host(i+n_local);
1598 double detection_temp =
timer();
1601 verts_to_recolor_size_host(0) = 0;
1602 verts_to_send_size_host(0) = 0;
1603 recoloringSize_host(0) = 0;
1606 verts_to_recolor_host, verts_to_recolor_size_host, verts_to_send_host, verts_to_send_size_host,
1607 recoloringSize_host, rand_host, gid_host, ghost_degrees_host, recolor_degrees);
1611 if(distributedRounds < numStatisticRecordingRounds){
1612 conflictDetectionPerRound[distributedRounds] =
timer() - detection_temp;
1613 conflict_detection += conflictDetectionPerRound[distributedRounds];
1614 compPerRound[distributedRounds] += conflictDetectionPerRound[distributedRounds];
1615 totalPerRound[distributedRounds] += conflictDetectionPerRound[distributedRounds];
1616 comp_time += conflictDetectionPerRound[distributedRounds];
1618 double conflict_detection_serial_round_time =
timer() - detection_temp;
1619 conflict_detection += conflict_detection_serial_round_time;
1620 comp_time += conflict_detection_serial_round_time;
1623 size_t globalDone = 0;
1624 size_t localDone = recoloringSize_host(0);
1625 Teuchos::reduceAll<int,size_t>(*
comm, Teuchos::REDUCE_SUM, 1, &localDone, &globalDone);
1626 distributedRounds++;
1630 total_time =
timer() - total_time;
1633 uint64_t localBoundaryVertices = 0;
1634 for(
size_t i = 0; i < n_local; i++){
1635 for(
offset_t j = offsets[i]; j < offsets[i+1]; j++){
1636 if((
size_t)adjs[j] >= n_local){
1637 localBoundaryVertices++;
1643 if(
comm->getRank() == 0) printf(
"did %d rounds of distributed coloring\n", distributedRounds);
1644 uint64_t totalVertsPerRound[numStatisticRecordingRounds];
1645 uint64_t totalBoundarySize = 0;
1646 uint64_t totalIncorrectGhostsPerRound[numStatisticRecordingRounds];
1647 double finalTotalPerRound[numStatisticRecordingRounds];
1648 double maxRecoloringPerRound[numStatisticRecordingRounds];
1649 double minRecoloringPerRound[numStatisticRecordingRounds];
1650 double finalCommPerRound[numStatisticRecordingRounds];
1651 double finalCompPerRound[numStatisticRecordingRounds];
1652 double finalConflictDetectionPerRound[numStatisticRecordingRounds];
1653 gno_t finalRecvPerRound[numStatisticRecordingRounds];
1654 gno_t finalSentPerRound[numStatisticRecordingRounds];
1655 for(
int i = 0; i < numStatisticRecordingRounds; i++){
1656 totalVertsPerRound[i] = 0;
1657 finalTotalPerRound[i] = 0.0;
1658 maxRecoloringPerRound[i] = 0.0;
1659 minRecoloringPerRound[i] = 0.0;
1660 finalCommPerRound[i] = 0.0;
1661 finalCompPerRound[i] = 0.0;
1662 finalConflictDetectionPerRound[i] = 0.0;
1663 finalRecvPerRound[i] = 0;
1664 finalSentPerRound[i] = 0;
1666 Teuchos::reduceAll<int,uint64_t>(*
comm, Teuchos::REDUCE_SUM,1,&localBoundaryVertices, &totalBoundarySize);
1667 Teuchos::reduceAll<int,uint64_t>(*
comm, Teuchos::REDUCE_SUM,numStatisticRecordingRounds,vertsPerRound,totalVertsPerRound);
1668 Teuchos::reduceAll<int,uint64_t>(*
comm, Teuchos::REDUCE_SUM,numStatisticRecordingRounds,incorrectGhostsPerRound,totalIncorrectGhostsPerRound);
1669 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,numStatisticRecordingRounds,totalPerRound, finalTotalPerRound);
1670 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,numStatisticRecordingRounds,recoloringPerRound,maxRecoloringPerRound);
1671 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MIN,numStatisticRecordingRounds,recoloringPerRound,minRecoloringPerRound);
1672 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,numStatisticRecordingRounds,commPerRound,finalCommPerRound);
1673 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,numStatisticRecordingRounds,compPerRound,finalCompPerRound);
1674 Teuchos::reduceAll<int,double>(*
comm,
1675 Teuchos::REDUCE_MAX,numStatisticRecordingRounds,conflictDetectionPerRound,finalConflictDetectionPerRound);
1676 Teuchos::reduceAll<int,gno_t> (*
comm, Teuchos::REDUCE_SUM,numStatisticRecordingRounds,recvPerRound,finalRecvPerRound);
1677 Teuchos::reduceAll<int,gno_t> (*
comm, Teuchos::REDUCE_SUM,numStatisticRecordingRounds,sentPerRound,finalSentPerRound);
1678 printf(
"Rank %d: boundary size: %ld\n",
comm->getRank(),localBoundaryVertices);
1679 if(
comm->getRank() == 0) printf(
"Total boundary size: %ld\n",totalBoundarySize);
1680 for(
int i = 0; i < std::min((
int)distributedRounds,numStatisticRecordingRounds); i++){
1681 printf(
"Rank %d: recolor %ld vertices in round %d\n",
comm->getRank(), vertsPerRound[i],i);
1682 printf(
"Rank %d: sentbuf had %lld entries in round %d\n",
comm->getRank(), sentPerRound[i],i);
1683 if(
comm->getRank()==0){
1684 printf(
"recolored %ld vertices in round %d\n",totalVertsPerRound[i], i);
1685 printf(
"%ld inconsistent ghosts in round %d\n",totalIncorrectGhostsPerRound[i],i);
1686 printf(
"total time in round %d: %f\n",i,finalTotalPerRound[i]);
1687 printf(
"recoloring time in round %d: %f\n",i,maxRecoloringPerRound[i]);
1688 printf(
"min recoloring time in round %d: %f\n",i,minRecoloringPerRound[i]);
1689 printf(
"conflict detection time in round %d: %f\n",i,finalConflictDetectionPerRound[i]);
1690 printf(
"comm time in round %d: %f\n",i,finalCommPerRound[i]);
1691 printf(
"recvbuf size in round %d: %lld\n",i,finalRecvPerRound[i]);
1692 printf(
"sendbuf size in round %d: %lld\n",i,finalSentPerRound[i]);
1693 printf(
"comp time in round %d: %f\n",i,finalCompPerRound[i]);
1697 double global_total_time = 0.0;
1698 double global_recoloring_time = 0.0;
1699 double global_min_recoloring_time = 0.0;
1700 double global_conflict_detection=0.0;
1701 double global_comm_time=0.0;
1702 double global_comp_time=0.0;
1703 double global_interior_time=0.0;
1704 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&total_time,&global_total_time);
1705 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&recoloring_time,&global_recoloring_time);
1706 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MIN,1,&recoloring_time,&global_min_recoloring_time);
1707 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&conflict_detection,&global_conflict_detection);
1708 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&comm_time,&global_comm_time);
1709 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&comp_time,&global_comp_time);
1710 Teuchos::reduceAll<int,double>(*
comm, Teuchos::REDUCE_MAX,1,&interior_time,&global_interior_time);
1713 if(
comm->getRank()==0){
1714 printf(
"Total Time: %f\n",global_total_time);
1715 printf(
"Interior Time: %f\n",global_interior_time);
1716 printf(
"Recoloring Time: %f\n",global_recoloring_time);
1717 printf(
"Min Recoloring Time: %f\n",global_min_recoloring_time);
1718 printf(
"Conflict Detection Time: %f\n",global_conflict_detection);
1719 printf(
"Comm Time: %f\n",global_comm_time);
1720 printf(
"Comp Time: %f\n",global_comp_time);
1726template <
typename Adapter>
1727void AlgTwoGhostLayer<Adapter>::buildModel(
modelFlag_t &flags){
1731 this->model = rcp(
new GraphModel<base_adapter_t>(this->adapter, this->env,
1732 this->comm, flags));
AlltoAll communication methods.
Defines the ColoringSolution class.
Defines the GraphModel interface.
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t,...
A gathering of useful namespace methods.
Tpetra::Map<>::memory_space memory_space
typename Kokkos::View< device_type >::HostMirror::execution_space host_exec
Tpetra::Map<>::device_type device_type
Tpetra::Map<>::execution_space execution_space
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)=0
typename Adapter::base_adapter_t base_adapter_t
void twoGhostLayer(const size_t n_local, const size_t n_total, const Teuchos::ArrayView< const lno_t > &adjs, const Teuchos::ArrayView< const offset_t > &offsets, const Teuchos::ArrayView< const lno_t > &ghost_adjs, const Teuchos::ArrayView< const offset_t > &ghost_offsets, const Teuchos::RCP< femv_t > &femv, const Teuchos::ArrayView< const gno_t > &gids, const Teuchos::ArrayView< const int > &rand, const Teuchos::ArrayView< const int > &ghost_owners, RCP< const map_t > mapOwnedPlusGhosts, const std::unordered_map< lno_t, std::vector< int > > &procs_to_send)
typename Adapter::gno_t gno_t
typename Adapter::scalar_t scalar_t
typename Adapter::offset_t offset_t
Tpetra::FEMultiVector< femv_scalar_t, lno_t, gno_t > femv_t
void color(const RCP< ColoringSolution< Adapter > > &solution)
Coloring method.
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)=0
typename Kokkos::View< device_type >::HostMirror::memory_space host_mem
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_view, typename Kokkos::View< int *, device_type >::HostMirror verts_to_recolor_size_atomic, typename Kokkos::View< lno_t *, device_type >::HostMirror verts_to_send_view, typename Kokkos::View< size_t *, device_type >::HostMirror verts_to_send_size_atomic, 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)=0
RCP< Teuchos::ParameterList > pl
RCP< GraphModel< base_adapter_t > > model
RCP< const base_adapter_t > adapter
AlgTwoGhostLayer(const RCP< const base_adapter_t > &adapter_, const RCP< Teuchos::ParameterList > &pl_, const RCP< Environment > &env_, const RCP< const Teuchos::Comm< int > > &comm_)
typename Adapter::lno_t lno_t
Tpetra::Map< lno_t, gno_t > map_t
RCP< const Teuchos::Comm< int > > comm
Algorithm defines the base class for all algorithms.
The class containing coloring solution.
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
Created by mbenlioglu on Aug 31, 2020.
Tpetra::global_size_t global_size_t
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
@ DETAILED_STATUS
sub-steps, each method's entry and exit
@ REMOVE_SELF_EDGES
algorithm requires no self edges