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]]);
793 Tpetra::global_size_t dummy = Teuchos::OrdinalTraits
794 <Tpetra::global_size_t>::invalid();
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);