364#if defined(DEAL_II_WITH_TBB) && !defined(DEAL_II_TBB_WITH_ONEAPI)
371 tbb::empty_task *root =
372 new (tbb::task::allocate_root()) tbb::empty_task;
373 root->set_ref_count(
evens + 1);
374 std::vector<partition::PartitionWork *> worker(
n_workers);
375 std::vector<partition::PartitionWork *> blocked_worker(
379 worker_compr->set_ref_count(1);
380 for (
unsigned int j = 0; j <
evens; ++j)
384 worker[j] =
new (root->allocate_child())
386 worker[j]->set_ref_count(2);
387 blocked_worker[j - 1]->
dummy =
388 new (worker[j]->allocate_child()) tbb::empty_task;
389 tbb::task::spawn(*blocked_worker[j - 1]);
393 worker[j] =
new (worker_compr->allocate_child())
395 worker[j]->set_ref_count(2);
397 new (worker[j]->allocate_child())
399 tbb::task::spawn(*worker_dist);
403 blocked_worker[j] =
new (worker[j]->allocate_child())
410 worker[
evens] =
new (worker[j]->allocate_child())
415 tbb::task::spawn(*worker[
evens]);
419 tbb::empty_task *child =
420 new (worker[j]->allocate_child()) tbb::empty_task();
421 tbb::task::spawn(*child);
426 root->wait_for_all();
427 root->destroy(*root);
443 tbb::empty_task *root =
444 new (tbb::task::allocate_root()) tbb::empty_task;
445 root->set_ref_count(
evens + 1);
450 std::vector<color::PartitionWork *> worker(
n_workers);
451 std::vector<color::PartitionWork *> blocked_worker(
453 unsigned int worker_index = 0, slice_index = 0;
454 int spawn_index_child = -2;
457 worker_compr->set_ref_count(1);
458 for (
unsigned int part = 0;
463 worker[worker_index] =
464 new (worker_compr->allocate_child())
470 worker[worker_index] =
new (root->allocate_child())
479 worker[worker_index]->set_ref_count(1);
481 worker[worker_index] =
482 new (worker[worker_index - 1]->allocate_child())
488 worker[worker_index]->set_ref_count(2);
491 blocked_worker[(part - 1) / 2]->dummy =
492 new (worker[worker_index]->allocate_child())
495 if (spawn_index_child == -1)
496 tbb::task::spawn(*blocked_worker[(part - 1) / 2]);
499 Assert(spawn_index_child >= 0,
501 tbb::task::spawn(*worker[spawn_index_child]);
503 spawn_index_child = -2;
508 new (worker[worker_index]->allocate_child())
510 tbb::task::spawn(*worker_dist);
518 blocked_worker[part / 2] =
519 new (worker[worker_index - 1]->allocate_child())
527 blocked_worker[part / 2]->set_ref_count(1);
528 worker[worker_index] =
new (
529 blocked_worker[part / 2]->allocate_child())
538 spawn_index_child = -1;
547 worker[worker_index]->set_ref_count(1);
550 worker[worker_index] =
551 new (worker[worker_index - 1]->allocate_child())
557 spawn_index_child = worker_index;
562 tbb::empty_task *
final =
563 new (worker[worker_index - 1]->allocate_child())
565 tbb::task::spawn(*
final);
566 spawn_index_child = worker_index - 1;
572 tbb::task::spawn(*worker[spawn_index_child]);
574 root->wait_for_all();
575 root->destroy(*root);
588 tbb::empty_task *root =
589 new (tbb::task::allocate_root()) tbb::empty_task;
590 root->set_ref_count(2);
592 new (root->allocate_child())
594 tbb::empty_task::spawn(*worker);
595 root->wait_for_all();
596 root->destroy(*root);
795 const std::vector<unsigned int> &cells_with_comm,
796 const unsigned int dofs_per_cell,
797 const bool categories_are_hp,
798 const std::vector<unsigned int> &cell_vectorization_categories,
799 const bool cell_vectorization_categories_strict,
800 const std::vector<unsigned int> &parent_relation,
801 std::vector<unsigned int> &renumbering,
802 std::vector<unsigned char> &incompletely_filled_vectorization)
833 unsigned int n_categories = 1;
835 if (cell_vectorization_categories.empty() ==
false)
840 std::set<unsigned int> used_categories;
842 used_categories.insert(cell_vectorization_categories[i]);
843 std::vector<unsigned int> used_categories_vector(
844 used_categories.size());
846 for (
const auto &it : used_categories)
847 used_categories_vector[n_categories++] = it;
850 const unsigned int index =
851 std::lower_bound(used_categories_vector.begin(),
852 used_categories_vector.end(),
853 cell_vectorization_categories[i]) -
854 used_categories_vector.begin();
856 tight_category_map[i] =
index;
863 std::vector<std::vector<unsigned int>> renumbering_category(n_categories);
865 renumbering_category[tight_category_map[i]].push_back(i);
867 if (cell_vectorization_categories_strict ==
false && n_categories > 1)
868 for (
unsigned int j = n_categories - 1; j > 0; --j)
870 unsigned int lower_index = j - 1;
871 while ((renumbering_category[j].size() % n_lanes) != 0u)
873 while (((renumbering_category[j].size() % n_lanes) != 0u) &&
874 !renumbering_category[lower_index].empty())
876 renumbering_category[j].push_back(
877 renumbering_category[lower_index].back());
878 renumbering_category[lower_index].pop_back();
880 if (lower_index == 0)
891 std::vector<unsigned int> temporary_numbering;
893 (n_lanes - 1) * n_categories);
894 const unsigned int n_cells_per_parent =
895 std::count(parent_relation.begin(), parent_relation.end(), 0);
896 std::vector<unsigned int> category_size;
897 for (
unsigned int j = 0; j < n_categories; ++j)
899 std::vector<std::pair<unsigned int, unsigned int>> grouped_cells;
900 std::vector<unsigned int> other_cells;
901 for (
const unsigned int cell : renumbering_category[j])
902 if (parent_relation.empty() ||
904 other_cells.push_back(cell);
906 grouped_cells.emplace_back(parent_relation[cell], cell);
909 std::sort(grouped_cells.begin(), grouped_cells.end());
910 std::vector<unsigned int> n_cells_per_group;
911 unsigned int length = 0;
912 for (
unsigned int i = 0; i < grouped_cells.size(); ++i, ++length)
913 if (i > 0 && grouped_cells[i].
first != grouped_cells[i - 1].
first)
915 n_cells_per_group.push_back(length);
919 n_cells_per_group.push_back(length);
924 auto group_it = grouped_cells.begin();
925 for (
const unsigned int length : n_cells_per_group)
926 if (length < n_cells_per_parent)
927 for (
unsigned int j = 0; j < length; ++j)
928 other_cells.push_back((group_it++)->second);
934 for (
unsigned int j = 0; j < length; ++j)
935 temporary_numbering.push_back((group_it++)->second);
939 std::sort(other_cells.begin(), other_cells.end());
940 temporary_numbering.insert(temporary_numbering.end(),
944 while (temporary_numbering.size() % n_lanes != 0)
947 category_size.push_back(temporary_numbering.size());
951 std::vector<bool> batch_with_comm(temporary_numbering.size() / n_lanes,
953 std::vector<unsigned int> temporary_numbering_inverse(
n_active_cells);
954 for (
unsigned int i = 0; i < temporary_numbering.size(); ++i)
956 temporary_numbering_inverse[temporary_numbering[i]] = i;
957 for (
const unsigned int cell : cells_with_comm)
958 batch_with_comm[temporary_numbering_inverse[cell] / n_lanes] =
true;
964 std::vector<std::array<unsigned int, 3>> batch_order;
965 std::vector<std::array<unsigned int, 3>> batch_order_comm;
966 for (
unsigned int i = 0; i < temporary_numbering.size(); i += n_lanes)
968 unsigned int max_index = 0;
969 for (
unsigned int j = 0; j < n_lanes; ++j)
971 max_index =
std::max(temporary_numbering[i + j], max_index);
972 const unsigned int category_hp =
974 std::upper_bound(category_size.begin(), category_size.end(), i) -
975 category_size.begin() :
977 const std::array<unsigned int, 3> next{{category_hp, max_index, i}};
978 if (batch_with_comm[i / n_lanes])
979 batch_order_comm.emplace_back(next);
981 batch_order.emplace_back(next);
984 std::sort(batch_order.begin(), batch_order.end());
985 std::sort(batch_order_comm.begin(), batch_order_comm.end());
992 std::vector<unsigned int> blocks;
995 if (batch_order.empty())
996 std::swap(batch_order_comm, batch_order);
999 blocks = {0,
static_cast<unsigned int>(batch_order.size())};
1004 const unsigned int comm_begin = batch_order.size() / 2;
1005 batch_order.insert(batch_order.begin() + comm_begin,
1006 batch_order_comm.begin(),
1007 batch_order_comm.end());
1008 const unsigned int comm_end = comm_begin + batch_order_comm.size();
1009 const unsigned int end = batch_order.size();
1010 blocks = {0, comm_begin, comm_end, end};
1014 std::vector<std::array<unsigned int, 2>> tight_category_map_ghost;
1016 if (cell_vectorization_categories.empty() ==
false)
1020 std::set<unsigned int> used_categories;
1022 used_categories.insert(
1025 std::vector<unsigned int> used_categories_vector(
1026 used_categories.size());
1028 for (
const auto &it : used_categories)
1029 used_categories_vector[n_categories++] = it;
1031 std::vector<unsigned int> counters(n_categories, 0);
1035 const unsigned int index =
1037 used_categories_vector.begin(),
1038 used_categories_vector.end(),
1040 used_categories_vector.begin();
1042 tight_category_map_ghost.emplace_back(
1043 std::array<unsigned int, 2>{{
index, i}});
1046 if (categories_are_hp || cell_vectorization_categories_strict)
1051 for (
unsigned int i = 0; i < counters.size(); ++i)
1052 if (counters[i] % n_lanes != 0)
1053 for (
unsigned int j = counters[i] % n_lanes; j < n_lanes; ++j)
1054 tight_category_map_ghost.emplace_back(
1055 std::array<unsigned int, 2>{
1056 {i, numbers::invalid_unsigned_int}});
1058 std::sort(tight_category_map_ghost.begin(),
1059 tight_category_map_ghost.end());
1063 const unsigned int n_cell_batches = batch_order.size();
1064 const unsigned int n_ghost_batches =
1065 ((tight_category_map_ghost.empty() ? n_ghost_cells :
1066 tight_category_map_ghost.size()) +
1069 incompletely_filled_vectorization.resize(n_cell_batches +
1072 cell_partition_data.clear();
1073 cell_partition_data.resize(1, 0);
1075 renumbering.clear();
1076 renumbering.resize(n_active_cells + n_ghost_cells,
1079 unsigned int counter = 0;
1080 for (
unsigned int block = 0; block < blocks.size() - 1; ++block)
1082 const unsigned int grain_size =
1083 std::max((2048U / dofs_per_cell) / 8 * 4, 2U);
1084 for (
unsigned int k = blocks[block]; k < blocks[block + 1];
1086 cell_partition_data.push_back(
1087 std::min(k + grain_size, blocks[block + 1]));
1088 partition_row_index[block + 1] = cell_partition_data.size() - 1;
1091 for (
unsigned int k = blocks[block]; k < blocks[block + 1]; ++k)
1093 const unsigned int pos = batch_order[k][2];
1095 for (; j < n_lanes && temporary_numbering[pos + j] !=
1098 renumbering[counter++] = temporary_numbering[pos + j];
1100 incompletely_filled_vectorization[k] = j;
1106 if (tight_category_map_ghost.empty())
1108 for (
unsigned int cell = 0; cell < n_ghost_cells; ++cell)
1109 renumbering[n_active_cells + cell] = n_active_cells + cell;
1111 if ((n_ghost_cells % n_lanes) != 0u)
1112 incompletely_filled_vectorization.back() = n_ghost_cells % n_lanes;
1116 for (
unsigned int k = 0, ptr = 0; k < n_ghost_batches;
1117 ++k, ptr += n_lanes)
1122 j < n_lanes && (ptr + j < tight_category_map_ghost.size()) &&
1123 (tight_category_map_ghost[ptr + j][1] !=
1126 renumbering[counter++] =
1127 n_active_cells + tight_category_map_ghost[ptr + j][1];
1130 incompletely_filled_vectorization[n_cell_batches + k] = j;
1136 cell_partition_data.push_back(n_cell_batches + n_ghost_batches);
1137 partition_row_index.back() = cell_partition_data.size() - 1;
1140 std::vector<unsigned int> renumber_cpy(renumbering);
1141 std::sort(renumber_cpy.begin(), renumber_cpy.end());
1142 for (
unsigned int i = 0; i < renumber_cpy.size(); ++i)
1150 TaskInfo::initial_setup_blocks_tasks(
1151 const std::vector<unsigned int> &boundary_cells,
1152 std::vector<unsigned int> &renumbering,
1153 std::vector<unsigned char> &incompletely_filled_vectorization)
1155 const unsigned int n_cell_batches =
1156 (n_active_cells + vectorization_length - 1) / vectorization_length;
1157 const unsigned int n_ghost_slots =
1158 (n_ghost_cells + vectorization_length - 1) / vectorization_length;
1159 incompletely_filled_vectorization.resize(n_cell_batches + n_ghost_slots);
1160 if (n_cell_batches * vectorization_length > n_active_cells)
1161 incompletely_filled_vectorization[n_cell_batches - 1] =
1162 vectorization_length -
1163 (n_cell_batches * vectorization_length - n_active_cells);
1164 if (n_ghost_slots * vectorization_length > n_ghost_cells)
1165 incompletely_filled_vectorization[n_cell_batches + n_ghost_slots - 1] =
1166 vectorization_length -
1167 (n_ghost_slots * vectorization_length - n_ghost_cells);
1169 std::vector<unsigned int> reverse_numbering(
1171 for (
unsigned int j = 0; j < boundary_cells.size(); ++j)
1172 reverse_numbering[boundary_cells[j]] = j;
1173 unsigned int counter = boundary_cells.size();
1174 for (
unsigned int j = 0; j < n_active_cells; ++j)
1176 reverse_numbering[j] = counter++;
1181 for (
unsigned int j = n_active_cells; j < n_active_cells + n_ghost_cells;
1183 renumbering.push_back(j);
1187 cell_partition_data.clear();
1188 cell_partition_data.push_back(0);
1191 const unsigned int n_macro_boundary_cells =
1192 (boundary_cells.size() + vectorization_length - 1) /
1193 vectorization_length;
1194 cell_partition_data.push_back(
1195 (n_cell_batches - n_macro_boundary_cells) / 2);
1196 cell_partition_data.push_back(cell_partition_data[1] +
1197 n_macro_boundary_cells);
1201 cell_partition_data.push_back(n_cell_batches);
1202 cell_partition_data.push_back(cell_partition_data.back() + n_ghost_slots);
1203 partition_row_index.resize(n_procs > 1 ? 4 : 2);
1204 partition_row_index[0] = 0;
1205 partition_row_index[1] = 1;
1208 partition_row_index[2] = 2;
1209 partition_row_index[3] = 3;
1244 TaskInfo::make_thread_graph_partition_color(
1246 std::vector<unsigned int> &renumbering,
1247 std::vector<unsigned char> &irregular_cells,
1250 const unsigned int n_cell_batches = *(cell_partition_data.end() - 2);
1251 if (n_cell_batches == 0)
1256 unsigned int partition = 0, counter = 0;
1261 make_connectivity_cells_to_blocks(irregular_cells,
1270 std::vector<unsigned int> cell_partition(n_blocks,
1275 std::vector<unsigned int> partition_list(n_blocks, 0);
1276 std::vector<unsigned int> partition_color_list(n_blocks, 0);
1279 std::vector<unsigned int> partition_size(2, 0);
1285 unsigned int cluster_size = 1;
1288 make_partitioning(connectivity,
1296 make_coloring_within_partitions_pre_blocked(connectivity,
1301 partition_color_list);
1303 partition_list = renumbering;
1308 std::vector<unsigned int> sorted_pc_list(partition_color_list);
1309 std::sort(sorted_pc_list.begin(), sorted_pc_list.end());
1310 for (
unsigned int i = 0; i < sorted_pc_list.size(); ++i)
1317 std::vector<unsigned int> block_start(n_cell_batches + 1);
1318 std::vector<unsigned char> irregular(n_cell_batches);
1320 unsigned int mcell_start = 0;
1322 for (
unsigned int block = 0; block < n_blocks; ++block)
1324 block_start[block + 1] = block_start[block];
1325 for (
unsigned int mcell = mcell_start;
1326 mcell <
std::min(mcell_start + block_size, n_cell_batches);
1329 unsigned int n_comp = (irregular_cells[mcell] > 0) ?
1330 irregular_cells[mcell] :
1331 vectorization_length;
1332 block_start[block + 1] += n_comp;
1335 mcell_start += block_size;
1338 unsigned int counter_macro = 0;
1339 unsigned int block_size_last =
1340 n_cell_batches - block_size * (n_blocks - 1);
1341 if (block_size_last == 0)
1342 block_size_last = block_size;
1344 unsigned int tick = 0;
1345 for (
unsigned int block = 0; block < n_blocks; ++block)
1347 unsigned int present_block = partition_color_list[block];
1348 for (
unsigned int cell = block_start[present_block];
1349 cell < block_start[present_block + 1];
1351 renumbering[counter++] = partition_list[cell];
1352 unsigned int this_block_size =
1353 (present_block == n_blocks - 1) ? block_size_last : block_size;
1357 if (cell_partition_data[tick] == block)
1358 cell_partition_data[tick++] = counter_macro;
1360 for (
unsigned int j = 0; j < this_block_size; ++j)
1361 irregular[counter_macro++] =
1362 irregular_cells[present_block * block_size + j];
1365 cell_partition_data.back() = counter_macro;
1367 irregular_cells.swap(irregular);
1374 std::vector<unsigned int> sorted_renumbering(renumbering);
1375 std::sort(sorted_renumbering.begin(), sorted_renumbering.end());
1376 for (
unsigned int i = 0; i < sorted_renumbering.size(); ++i)
1391 TaskInfo::make_thread_graph(
1392 const std::vector<unsigned int> &cell_active_fe_index,
1394 std::vector<unsigned int> &renumbering,
1395 std::vector<unsigned char> &irregular_cells,
1398 const unsigned int n_cell_batches = *(cell_partition_data.end() - 2);
1399 if (n_cell_batches == 0)
1407 make_connectivity_cells_to_blocks(irregular_cells,
1409 connectivity_blocks);
1411 unsigned int n_blocks = 0;
1412 if (scheme == partition_color ||
1414 n_blocks = this->n_blocks;
1416 n_blocks = n_active_cells;
1421 std::vector<unsigned int> cell_partition(n_blocks,
1427 std::vector<unsigned int> partition_list(n_blocks, 0);
1428 std::vector<unsigned int> partition_2layers_list(n_blocks, 0);
1431 std::vector<unsigned int> partition_size(2, 0);
1433 unsigned int partition = 0;
1439 unsigned int cluster_size = 1;
1440 if (scheme == partition_partition)
1441 cluster_size = block_size * vectorization_length;
1444 if (scheme == partition_color || scheme == color)
1445 make_partitioning(connectivity_blocks,
1452 make_partitioning(connectivity,
1460 if (scheme == partition_partition)
1464 make_partitioning_within_partitions_post_blocked(
1466 cell_active_fe_index,
1473 partition_2layers_list,
1476 else if (scheme == partition_color || scheme == color)
1478 make_coloring_within_partitions_pre_blocked(connectivity_blocks,
1483 partition_2layers_list);
1489 std::vector<unsigned int> sorted_pc_list(partition_2layers_list);
1490 std::sort(sorted_pc_list.begin(), sorted_pc_list.end());
1491 for (
unsigned int i = 0; i < sorted_pc_list.size(); ++i)
1497 std::vector<unsigned int> renumbering_in(n_active_cells, 0);
1498 renumbering_in.swap(renumbering);
1499 if (scheme == partition_partition)
1504 for (
unsigned int j = 0; j < renumbering.size(); ++j)
1505 renumbering[j] = renumbering_in[partition_2layers_list[j]];
1507 for (
unsigned int i = 0; i < n_ghost_cells; ++i)
1508 renumbering.push_back(i + n_active_cells);
1514 std::vector<unsigned int> block_start(n_cell_batches + 1);
1515 std::vector<unsigned char> irregular(n_cell_batches);
1517 unsigned int counter = 0;
1518 unsigned int mcell_start = 0;
1520 for (
unsigned int block = 0; block < n_blocks; ++block)
1522 block_start[block + 1] = block_start[block];
1523 for (
unsigned int mcell = mcell_start;
1524 mcell <
std::min(mcell_start + block_size, n_cell_batches);
1527 unsigned int n_comp = (irregular_cells[mcell] > 0) ?
1528 irregular_cells[mcell] :
1529 vectorization_length;
1530 block_start[block + 1] += n_comp;
1533 mcell_start += block_size;
1536 unsigned int counter_macro = 0;
1537 unsigned int block_size_last =
1538 n_cell_batches - block_size * (n_blocks - 1);
1539 if (block_size_last == 0)
1540 block_size_last = block_size;
1542 unsigned int tick = 0;
1543 for (
unsigned int block = 0; block < n_blocks; ++block)
1545 unsigned int present_block = partition_2layers_list[block];
1546 for (
unsigned int cell = block_start[present_block];
1547 cell < block_start[present_block + 1];
1549 renumbering[counter++] = renumbering_in[cell];
1550 unsigned int this_block_size =
1551 (present_block == n_blocks - 1) ? block_size_last : block_size;
1555 if (cell_partition_data[tick] == block)
1556 cell_partition_data[tick++] = counter_macro;
1558 for (
unsigned int j = 0; j < this_block_size; ++j)
1559 irregular[counter_macro++] =
1560 irregular_cells[present_block * block_size + j];
1563 cell_partition_data.back() = counter_macro;
1565 irregular_cells.swap(irregular);
1571 std::vector<unsigned int> sorted_renumbering(renumbering);
1572 std::sort(sorted_renumbering.begin(), sorted_renumbering.end());
1573 for (
unsigned int i = 0; i < sorted_renumbering.size(); ++i)
1580 update_task_info(partition);
1698 TaskInfo::make_partitioning_within_partitions_post_blocked(
1700 const std::vector<unsigned int> &cell_active_fe_index,
1701 const unsigned int partition,
1702 const unsigned int cluster_size,
1704 const std::vector<unsigned int> &cell_partition,
1705 const std::vector<unsigned int> &partition_list,
1706 const std::vector<unsigned int> &partition_size,
1707 std::vector<unsigned int> &partition_partition_list,
1708 std::vector<unsigned char> &irregular_cells)
1710 const unsigned int n_cell_batches = *(cell_partition_data.end() - 2);
1711 const unsigned int n_ghost_slots =
1712 *(cell_partition_data.end() - 1) - n_cell_batches;
1715 std::vector<unsigned int> neighbor_list;
1718 std::vector<unsigned int> neighbor_neighbor_list;
1720 std::vector<unsigned int> renumbering(n_active_cells);
1722 irregular_cells.back() = 0;
1723 irregular_cells.resize(n_active_cells + n_ghost_slots);
1725 unsigned int max_fe_index = 0;
1726 for (
const unsigned int fe_index : cell_active_fe_index)
1727 max_fe_index =
std::max(fe_index, max_fe_index);
1729 Assert(!hp_bool || cell_active_fe_index.size() == n_active_cells,
1733 unsigned int n_cell_batches_before = 0;
1739 std::vector<unsigned int> cell_partition_l2(
1741 partition_row_index.clear();
1742 partition_row_index.resize(partition + 1, 0);
1743 cell_partition_data.resize(1, 0);
1745 unsigned int counter = 0;
1746 unsigned int missing_macros;
1747 for (
unsigned int part = 0; part < partition; ++part)
1749 neighbor_neighbor_list.resize(0);
1750 neighbor_list.resize(0);
1752 unsigned int partition_l2 = 0;
1753 unsigned int start_up = partition_size[part];
1754 unsigned int partition_counter = 0;
1757 if (neighbor_list.empty())
1760 partition_counter = 0;
1761 for (
unsigned int j = start_up;
1762 j < partition_size[part + 1];
1764 if (cell_partition[partition_list[j]] == part &&
1765 cell_partition_l2[partition_list[j]] ==
1770 partition_counter = 1;
1774 cell_partition_l2[partition_list[start_up]] =
1776 neighbor_neighbor_list.push_back(
1777 partition_list[start_up]);
1778 partition_partition_list[counter++] =
1779 partition_list[start_up];
1786 partition_counter = 0;
1787 for (
const unsigned int neighbor : neighbor_list)
1789 Assert(cell_partition[neighbor] == part,
1791 Assert(cell_partition_l2[neighbor] == partition_l2 - 1,
1793 auto neighbor_it = connectivity.
begin(neighbor);
1794 const auto end_it = connectivity.
end(neighbor);
1795 for (; neighbor_it != end_it; ++neighbor_it)
1797 if (cell_partition[neighbor_it->column()] == part &&
1798 cell_partition_l2[neighbor_it->column()] ==
1801 cell_partition_l2[neighbor_it->column()] =
1803 neighbor_neighbor_list.push_back(
1804 neighbor_it->column());
1805 partition_partition_list[counter++] =
1806 neighbor_it->column();
1807 ++partition_counter;
1812 if (partition_counter > 0)
1814 int index_before = neighbor_neighbor_list.size(),
1815 index = index_before;
1820 std::vector<unsigned int> remaining_per_cell_batch(
1822 std::vector<std::vector<unsigned int>>
1823 renumbering_fe_index;
1826 if (hp_bool ==
true)
1828 renumbering_fe_index.resize(max_fe_index + 1);
1829 for (cell = counter - partition_counter;
1833 renumbering_fe_index
1834 [cell_active_fe_index.empty() ?
1836 cell_active_fe_index
1837 [partition_partition_list[cell]]]
1838 .push_back(partition_partition_list[cell]);
1841 for (
unsigned int j = 0; j < max_fe_index + 1; ++j)
1843 remaining_per_cell_batch[j] =
1844 renumbering_fe_index[j].size() %
1845 vectorization_length;
1846 if (remaining_per_cell_batch[j] != 0)
1849 ((renumbering_fe_index[j].size() +
1850 vectorization_length - 1) /
1851 vectorization_length);
1856 remaining_per_cell_batch.resize(1);
1857 remaining_per_cell_batch[0] =
1858 partition_counter % vectorization_length;
1860 partition_counter / vectorization_length;
1861 if (remaining_per_cell_batch[0] != 0)
1868 cluster_size - (missing_macros % cluster_size);
1871 while (missing_macros > 0 || filled ==
false)
1875 index = neighbor_neighbor_list.size();
1876 if (
index == index_before)
1878 if (missing_macros != 0)
1880 neighbor_neighbor_list.resize(0);
1885 index_before =
index;
1888 unsigned int additional =
1889 neighbor_neighbor_list[
index];
1900 for (; neighbor != end; ++neighbor)
1902 if (cell_partition[neighbor->
column()] == part &&
1903 cell_partition_l2[neighbor->
column()] ==
1906 unsigned int this_index = 0;
1907 if (hp_bool ==
true)
1909 cell_active_fe_index.empty() ?
1911 cell_active_fe_index[neighbor
1918 if (missing_macros > 0 ||
1919 remaining_per_cell_batch[this_index] > 0)
1921 cell_partition_l2[neighbor->
column()] =
1923 neighbor_neighbor_list.push_back(
1925 if (hp_bool ==
true)
1926 renumbering_fe_index[this_index]
1927 .push_back(neighbor->
column());
1928 partition_partition_list[counter] =
1931 ++partition_counter;
1932 if (remaining_per_cell_batch
1933 [this_index] == 0 &&
1936 remaining_per_cell_batch[this_index]++;
1937 if (remaining_per_cell_batch
1939 vectorization_length)
1941 remaining_per_cell_batch[this_index] =
1944 if (missing_macros == 0)
1947 for (
unsigned int fe_ind = 0;
1948 fe_ind < max_fe_index + 1;
1950 if (remaining_per_cell_batch
1960 if (hp_bool ==
true)
1965 cell = counter - partition_counter;
1966 for (
unsigned int j = 0; j < max_fe_index + 1; ++j)
1968 for (
const unsigned int jj :
1969 renumbering_fe_index[j])
1970 renumbering[cell++] = jj;
1971 if (renumbering_fe_index[j].size() %
1972 vectorization_length !=
1974 irregular_cells[renumbering_fe_index[j].size() /
1975 vectorization_length +
1976 n_cell_batches_before] =
1977 renumbering_fe_index[j].size() %
1978 vectorization_length;
1979 n_cell_batches_before +=
1980 (renumbering_fe_index[j].size() +
1981 vectorization_length - 1) /
1982 vectorization_length;
1983 renumbering_fe_index[j].resize(0);
1988 n_cell_batches_before +=
1989 partition_counter / vectorization_length;
1990 if (partition_counter % vectorization_length != 0)
1992 irregular_cells[n_cell_batches_before] =
1993 partition_counter % vectorization_length;
1994 ++n_cell_batches_before;
1998 cell_partition_data.push_back(n_cell_batches_before);
2001 neighbor_list = neighbor_neighbor_list;
2002 neighbor_neighbor_list.resize(0);
2004 partition_row_index[part + 1] =
2005 partition_row_index[part] + partition_l2;
2008 if (hp_bool ==
true)
2010 partition_partition_list.swap(renumbering);
2019 TaskInfo::make_coloring_within_partitions_pre_blocked(
2021 const unsigned int partition,
2022 const std::vector<unsigned int> &cell_partition,
2023 const std::vector<unsigned int> &partition_list,
2024 const std::vector<unsigned int> &partition_size,
2025 std::vector<unsigned int> &partition_color_list)
2027 const unsigned int n_cell_batches = *(cell_partition_data.end() - 2);
2028 std::vector<unsigned int> cell_color(n_blocks, n_cell_batches);
2029 std::vector<bool> color_finder;
2031 partition_row_index.resize(partition + 1);
2032 cell_partition_data.clear();
2033 unsigned int color_counter = 0, index_counter = 0;
2034 for (
unsigned int part = 0; part < partition; ++part)
2036 partition_row_index[part] = index_counter;
2037 unsigned int max_color = 0;
2038 for (
unsigned int k = partition_size[part];
2039 k < partition_size[part + 1];
2042 unsigned int cell = partition_list[k];
2043 unsigned int n_neighbors = connectivity.
row_length(cell);
2047 color_finder.resize(n_neighbors + 1);
2048 for (
unsigned int j = 0; j <= n_neighbors; ++j)
2049 color_finder[j] =
true;
2051 connectivity.
begin(cell),
2052 end = connectivity.
end(cell);
2053 for (; neighbor != end; ++neighbor)
2057 if (cell_partition[neighbor->
column()] == part &&
2058 cell_color[neighbor->
column()] <= n_neighbors)
2059 color_finder[cell_color[neighbor->
column()]] =
false;
2062 cell_color[cell] = 0;
2063 while (color_finder[cell_color[cell]] ==
false)
2065 if (cell_color[cell] > max_color)
2066 max_color = cell_color[cell];
2071 for (
unsigned int color = 0; color <= max_color; ++color)
2073 cell_partition_data.push_back(color_counter);
2075 for (
unsigned int k = partition_size[part];
2076 k < partition_size[part + 1];
2079 unsigned int cell = partition_list[k];
2080 if (cell_color[cell] == color)
2082 partition_color_list[color_counter++] = cell;
2087 cell_partition_data.push_back(n_blocks);
2088 partition_row_index[partition] = index_counter;
2096 const unsigned int cluster_size,
2097 std::vector<unsigned int> &cell_partition,
2098 std::vector<unsigned int> &partition_list,
2099 std::vector<unsigned int> &partition_size,
2100 unsigned int &partition)
const
2109 std::vector<unsigned int> neighbor_list;
2112 std::vector<unsigned int> neighbor_neighbor_list;
2122 unsigned int counter = 0;
2123 unsigned int start_nonboundary =
2124 cell_partition_data.size() == 5 ?
2125 vectorization_length *
2126 (cell_partition_data[2] - cell_partition_data[1]) :
2129 const unsigned int n_cell_batches = *(cell_partition_data.end() - 2);
2130 if (n_cell_batches == 0)
2132 if (scheme == color)
2133 start_nonboundary = n_cell_batches;
2134 if (scheme == partition_color ||
2136 start_nonboundary = ((start_nonboundary + block_size - 1) / block_size);
2137 unsigned int n_blocks;
2138 if (scheme == partition_color ||
2140 n_blocks = this->n_blocks;
2142 n_blocks = n_active_cells;
2144 if (start_nonboundary > n_blocks)
2145 start_nonboundary = n_blocks;
2148 unsigned int start_up = 0;
2150 unsigned int remainder = cluster_size;
2158 if (start_nonboundary > 0)
2160 for (
unsigned int cell = 0; cell < start_nonboundary; ++cell)
2162 const unsigned int cell_nn = cell;
2163 cell_partition[cell_nn] = partition;
2164 neighbor_list.push_back(cell_nn);
2165 partition_list[counter++] = cell_nn;
2166 partition_size.back()++;
2168 start_nonboundary = 0;
2169 remainder -= (start_nonboundary % cluster_size);
2170 if (remainder == cluster_size)
2177 cell_partition[start_up] = partition;
2178 neighbor_list.push_back(start_up);
2179 partition_list[counter++] = start_up;
2180 partition_size.back()++;
2183 if (remainder == cluster_size)
2186 int index_before = neighbor_list.size(),
index = index_before,
2188 while (remainder > 0)
2190 if (
index == index_stop)
2192 index = neighbor_list.size();
2193 if (
index == index_before)
2195 neighbor_list.resize(0);
2198 index_stop = index_before;
2199 index_before =
index;
2202 unsigned int additional = neighbor_list[
index];
2204 connectivity.
begin(additional),
2206 connectivity.
end(additional);
2207 for (; neighbor != end; ++neighbor)
2209 if (cell_partition[neighbor->
column()] ==
2212 partition_size.back()++;
2213 cell_partition[neighbor->
column()] = partition;
2214 neighbor_list.push_back(neighbor->
column());
2215 partition_list[counter++] = neighbor->
column();
2223 while (neighbor_list.size() > 0)
2228 unsigned int partition_counter = 0;
2231 partition_size.push_back(partition_size.back());
2235 for (
const unsigned int cell : neighbor_list)
2237 Assert(cell_partition[cell] == partition - 1,
2239 auto neighbor = connectivity.
begin(cell);
2240 const auto end = connectivity.
end(cell);
2241 for (; neighbor != end; ++neighbor)
2243 if (cell_partition[neighbor->column()] ==
2246 partition_size.back()++;
2247 cell_partition[neighbor->column()] = partition;
2251 neighbor_neighbor_list.push_back(neighbor->column());
2252 partition_list[counter++] = neighbor->column();
2253 ++partition_counter;
2257 remainder = cluster_size - (partition_counter % cluster_size);
2258 if (remainder == cluster_size)
2261 int index_before = neighbor_neighbor_list.size(),
2262 index = index_before;
2263 while (remainder > 0)
2265 if (
index == index_stop)
2267 index = neighbor_neighbor_list.size();
2268 if (
index == index_before)
2270 neighbor_neighbor_list.resize(0);
2273 index_stop = index_before;
2274 index_before =
index;
2277 unsigned int additional = neighbor_neighbor_list[
index];
2281 end = connectivity.
end(
2283 for (; neighbor != end; ++neighbor)
2285 if (cell_partition[neighbor->
column()] ==
2288 partition_size.back()++;
2289 cell_partition[neighbor->
column()] = partition;
2290 neighbor_neighbor_list.push_back(neighbor->
column());
2291 partition_list[counter++] = neighbor->
column();
2299 neighbor_list = neighbor_neighbor_list;
2300 neighbor_neighbor_list.resize(0);
2306 for (
unsigned int j = start_up; j < n_blocks; ++j)
2312 remainder = cluster_size;