892 &pack_callbacks_fixed,
894 &pack_callbacks_variable)
896 Assert(src_data_fixed.size() == 0,
897 ExcMessage(
"Previously packed data has not been released yet!"));
900 const unsigned int n_callbacks_fixed = pack_callbacks_fixed.size();
901 const unsigned int n_callbacks_variable = pack_callbacks_variable.size();
905 variable_size_data_stored = (n_callbacks_variable > 0);
911 std::vector<unsigned int> cell_sizes_variable_cumulative(
912 n_callbacks_variable);
926 std::vector<std::vector<std::vector<char>>> packed_fixed_size_data(
927 cell_relations.size());
928 std::vector<std::vector<std::vector<char>>> packed_variable_size_data(
929 variable_size_data_stored ? cell_relations.size() : 0);
937 auto cell_rel_it = cell_relations.cbegin();
938 auto data_cell_fixed_it = packed_fixed_size_data.begin();
939 auto data_cell_variable_it = packed_variable_size_data.begin();
940 for (; cell_rel_it != cell_relations.cend(); ++cell_rel_it)
942 const auto &dealii_cell = cell_rel_it->first;
943 const auto &cell_status = cell_rel_it->second;
964 for (
unsigned int c = 0;
965 c < GeometryInfo<dim>::max_children_per_cell;
967 Assert(dealii_cell->child(c)->is_active(),
989 const unsigned int n_fixed_size_data_sets_on_cell =
993 spacedim>::CELL_INVALID) ?
995 ((variable_size_data_stored ? 1 : 0) + n_callbacks_fixed));
996 data_cell_fixed_it->resize(n_fixed_size_data_sets_on_cell);
999 auto data_fixed_it = data_cell_fixed_it->begin();
1012 spacedim>::CELL_INVALID)
1015 for (
auto callback_it = pack_callbacks_fixed.cbegin();
1016 callback_it != pack_callbacks_fixed.cend();
1017 ++callback_it, ++data_fixed_it)
1019 *data_fixed_it = (*callback_it)(dealii_cell, cell_status);
1026 if (variable_size_data_stored)
1028 const unsigned int n_variable_size_data_sets_on_cell =
1033 n_callbacks_variable);
1034 data_cell_variable_it->resize(
1035 n_variable_size_data_sets_on_cell);
1037 auto callback_it = pack_callbacks_variable.cbegin();
1038 auto data_variable_it = data_cell_variable_it->begin();
1039 auto sizes_variable_it =
1040 cell_sizes_variable_cumulative.begin();
1041 for (; callback_it != pack_callbacks_variable.cend();
1042 ++callback_it, ++data_variable_it, ++sizes_variable_it)
1045 (*callback_it)(dealii_cell, cell_status);
1049 *sizes_variable_it = data_variable_it->size();
1053 std::partial_sum(cell_sizes_variable_cumulative.begin(),
1054 cell_sizes_variable_cumulative.end(),
1055 cell_sizes_variable_cumulative.begin());
1062 data_fixed_it->resize(n_callbacks_variable *
1063 sizeof(
unsigned int));
1064 for (
unsigned int i = 0; i < n_callbacks_variable; ++i)
1065 std::memcpy(&(data_fixed_it->at(i *
sizeof(
unsigned int))),
1066 &(cell_sizes_variable_cumulative.at(i)),
1067 sizeof(
unsigned int));
1074 Assert(data_fixed_it == data_cell_fixed_it->end(),
1078 ++data_cell_fixed_it;
1083 if (variable_size_data_stored)
1084 ++data_cell_variable_it;
1101 std::vector<unsigned int> local_sizes_fixed(
1102 1 + n_callbacks_fixed + (variable_size_data_stored ? 1 : 0));
1103 for (
const auto &data_cell : packed_fixed_size_data)
1105 if (data_cell.size() == local_sizes_fixed.size())
1107 auto sizes_fixed_it = local_sizes_fixed.begin();
1108 auto data_fixed_it = data_cell.cbegin();
1109 for (; data_fixed_it != data_cell.cend();
1110 ++data_fixed_it, ++sizes_fixed_it)
1112 *sizes_fixed_it = data_fixed_it->size();
1120 for (
auto data_cell_fixed_it = packed_fixed_size_data.cbegin();
1121 data_cell_fixed_it != packed_fixed_size_data.cend();
1122 ++data_cell_fixed_it)
1124 Assert((data_cell_fixed_it->size() == 1) ||
1125 (data_cell_fixed_it->size() == local_sizes_fixed.size()),
1132 std::vector<unsigned int> global_sizes_fixed(local_sizes_fixed.size());
1134 this->mpi_communicator,
1135 global_sizes_fixed);
1139 sizes_fixed_cumulative.resize(global_sizes_fixed.size());
1140 std::partial_sum(global_sizes_fixed.begin(),
1141 global_sizes_fixed.end(),
1142 sizes_fixed_cumulative.begin());
1147 if (variable_size_data_stored)
1149 src_sizes_variable.reserve(packed_variable_size_data.size());
1150 for (
const auto &data_cell : packed_variable_size_data)
1152 int variable_data_size_on_cell = 0;
1154 for (
const auto &data : data_cell)
1155 variable_data_size_on_cell += data.size();
1157 src_sizes_variable.push_back(variable_data_size_on_cell);
1164 const unsigned int expected_size_fixed =
1165 cell_relations.size() * sizes_fixed_cumulative.back();
1166 const unsigned int expected_size_variable =
1167 std::accumulate(src_sizes_variable.begin(),
1168 src_sizes_variable.end(),
1169 std::vector<int>::size_type(0));
1173 src_data_fixed.reserve(expected_size_fixed);
1174 for (
const auto &data_cell_fixed : packed_fixed_size_data)
1178 for (
const auto &data_fixed : data_cell_fixed)
1179 std::move(data_fixed.begin(),
1181 std::back_inserter(src_data_fixed));
1187 if ((data_cell_fixed.size() == 1) &&
1188 (sizes_fixed_cumulative.size() > 1))
1190 const std::size_t bytes_skipped =
1191 sizes_fixed_cumulative.back() - sizes_fixed_cumulative.front();
1193 src_data_fixed.insert(src_data_fixed.end(),
1195 static_cast<char>(-1));
1201 if (variable_size_data_stored)
1203 src_data_variable.reserve(expected_size_variable);
1204 for (
const auto &data_cell : packed_variable_size_data)
1208 for (
const auto &data : data_cell)
1209 std::move(data.begin(),
1211 std::back_inserter(src_data_variable));
1217 Assert(src_data_variable.size() == expected_size_variable,
1263 const
unsigned int handle,
1264 const
std::function<
1267 const
boost::iterator_range<
std::vector<
char>::const_iterator> &)>
1268 &unpack_callback)
const
1274 const bool callback_variable_transfer = (handle % 2 == 0);
1275 const unsigned int callback_index = handle / 2;
1281 Assert(sizes_fixed_cumulative.size() > 0,
1283 if (cell_relations.size() > 0)
1285 Assert(dest_data_fixed.size() > 0,
1289 std::vector<char>::const_iterator dest_data_it;
1290 std::vector<char>::const_iterator dest_sizes_cell_it;
1300 if (callback_variable_transfer)
1313 const unsigned int offset_variable_data_sizes =
1314 sizes_fixed_cumulative[sizes_fixed_cumulative.size() - 2];
1321 dest_sizes_cell_it = dest_data_fixed.cbegin() +
1322 offset_variable_data_sizes +
1323 callback_index *
sizeof(
unsigned int);
1326 dest_data_it = dest_data_variable.cbegin();
1333 offset = sizes_fixed_cumulative[callback_index];
1334 size = sizes_fixed_cumulative[callback_index + 1] - offset;
1335 data_increment = sizes_fixed_cumulative.back();
1341 if (cell_relations.begin() != cell_relations.end())
1342 dest_data_it = dest_data_fixed.cbegin() + offset;
1346 auto cell_rel_it = cell_relations.begin();
1347 auto dest_sizes_it = dest_sizes_variable.cbegin();
1348 for (; cell_rel_it != cell_relations.end(); ++cell_rel_it)
1350 const auto &dealii_cell = cell_rel_it->first;
1351 const auto &cell_status = cell_rel_it->second;
1353 if (callback_variable_transfer)
1357 data_increment = *dest_sizes_it;
1361 spacedim>::CELL_INVALID)
1366 if (callback_index == 0)
1369 std::memcpy(&offset,
1370 &(*(dest_sizes_cell_it -
sizeof(
unsigned int))),
1371 sizeof(
unsigned int));
1374 &(*dest_sizes_cell_it),
1375 sizeof(
unsigned int));
1382 dest_data_it += offset;
1383 data_increment -= offset;
1388 if (cell_rel_it != cell_relations.end() - 1)
1389 dest_sizes_cell_it += sizes_fixed_cumulative.back();
1393 switch (cell_status)
1396 spacedim>::CELL_PERSIST:
1398 spacedim>::CELL_COARSEN:
1399 unpack_callback(dealii_cell,
1401 boost::make_iterator_range(dest_data_it,
1402 dest_data_it + size));
1406 spacedim>::CELL_REFINE:
1407 unpack_callback(dealii_cell->parent(),
1409 boost::make_iterator_range(dest_data_it,
1410 dest_data_it + size));
1414 spacedim>::CELL_INVALID:
1423 if (cell_rel_it != cell_relations.end() - 1)
1424 dest_data_it += data_increment;
1433 const
unsigned int global_first_cell,
1434 const
unsigned int global_num_cells,
1435 const
std::
string &filename)
const
1437#ifdef DEAL_II_WITH_MPI
1442 Assert(sizes_fixed_cumulative.size() > 0,
1447 const unsigned int bytes_per_cell = sizes_fixed_cumulative.back();
1453 const std::string fname_fixed = std::string(filename) +
"_fixed.data";
1456 int ierr = MPI_Info_create(&info);
1460 ierr = MPI_File_open(mpi_communicator,
1461 fname_fixed.c_str(),
1462 MPI_MODE_CREATE | MPI_MODE_WRONLY,
1467 ierr = MPI_File_set_size(fh, 0);
1471 ierr = MPI_Barrier(mpi_communicator);
1473 ierr = MPI_Info_free(&info);
1486 sizes_fixed_cumulative.data(),
1487 sizes_fixed_cumulative.size(),
1494 const MPI_Offset size_header =
1495 sizes_fixed_cumulative.size() *
sizeof(
unsigned int);
1499 const MPI_Offset my_global_file_position =
1501 static_cast<MPI_Offset
>(global_first_cell) * bytes_per_cell;
1505 my_global_file_position,
1506 src_data_fixed.data(),
1507 src_data_fixed.size(),
1512 ierr = MPI_File_close(&fh);
1521 if (variable_size_data_stored)
1523 const std::string fname_variable =
1524 std::string(filename) +
"_variable.data";
1527 int ierr = MPI_Info_create(&info);
1531 ierr = MPI_File_open(mpi_communicator,
1532 fname_variable.c_str(),
1533 MPI_MODE_CREATE | MPI_MODE_WRONLY,
1538 ierr = MPI_File_set_size(fh, 0);
1542 ierr = MPI_Barrier(mpi_communicator);
1544 ierr = MPI_Info_free(&info);
1549 const MPI_Offset my_global_file_position =
1550 static_cast<MPI_Offset
>(global_first_cell) *
sizeof(
unsigned int);
1555 static_cast<std::size_t
>(
1556 std::numeric_limits<int>::max()),
1561 my_global_file_position,
1562 src_sizes_variable.data(),
1563 src_sizes_variable.size(),
1572 const std::uint64_t size_on_proc = src_data_variable.size();
1573 std::uint64_t prefix_sum = 0;
1574 ierr = MPI_Exscan(&size_on_proc,
1582 const MPI_Offset my_global_file_position =
1583 static_cast<MPI_Offset
>(global_num_cells) *
sizeof(
unsigned int) +
1589 my_global_file_position,
1590 src_data_variable.data(),
1591 src_data_variable.size(),
1597 ierr = MPI_File_close(&fh);
1601 (void)global_first_cell;
1602 (void)global_num_cells;
1614 const
unsigned int global_first_cell,
1615 const
unsigned int global_num_cells,
1616 const
unsigned int local_num_cells,
1617 const
std::
string &filename,
1618 const
unsigned int n_attached_deserialize_fixed,
1619 const
unsigned int n_attached_deserialize_variable)
1621#ifdef DEAL_II_WITH_MPI
1626 Assert(dest_data_fixed.size() == 0,
1627 ExcMessage(
"Previously loaded data has not been released yet!"));
1629 variable_size_data_stored = (n_attached_deserialize_variable > 0);
1635 const std::string fname_fixed = std::string(filename) +
"_fixed.data";
1638 int ierr = MPI_Info_create(&info);
1642 ierr = MPI_File_open(
1643 mpi_communicator, fname_fixed.c_str(), MPI_MODE_RDONLY, info, &fh);
1646 ierr = MPI_Info_free(&info);
1653 sizes_fixed_cumulative.resize(1 + n_attached_deserialize_fixed +
1654 (variable_size_data_stored ? 1 : 0));
1658 sizes_fixed_cumulative.data(),
1659 sizes_fixed_cumulative.size(),
1665 const unsigned int bytes_per_cell = sizes_fixed_cumulative.back();
1666 dest_data_fixed.resize(
static_cast<size_t>(local_num_cells) *
1670 const MPI_Offset size_header =
1671 sizes_fixed_cumulative.size() *
sizeof(
unsigned int);
1675 const MPI_Offset my_global_file_position =
1677 static_cast<MPI_Offset
>(global_first_cell) * bytes_per_cell;
1680 my_global_file_position,
1681 dest_data_fixed.data(),
1682 dest_data_fixed.size(),
1688 ierr = MPI_File_close(&fh);
1695 if (variable_size_data_stored)
1697 const std::string fname_variable =
1698 std::string(filename) +
"_variable.data";
1701 int ierr = MPI_Info_create(&info);
1705 ierr = MPI_File_open(
1706 mpi_communicator, fname_variable.c_str(), MPI_MODE_RDONLY, info, &fh);
1709 ierr = MPI_Info_free(&info);
1713 dest_sizes_variable.resize(local_num_cells);
1715 const MPI_Offset my_global_file_position_sizes =
1716 static_cast<MPI_Offset
>(global_first_cell) *
sizeof(
unsigned int);
1720 my_global_file_position_sizes,
1721 dest_sizes_variable.data(),
1722 dest_sizes_variable.size(),
1730 const std::uint64_t size_on_proc =
1731 std::accumulate(dest_sizes_variable.begin(),
1732 dest_sizes_variable.end(),
1735 std::uint64_t prefix_sum = 0;
1736 ierr = MPI_Exscan(&size_on_proc,
1744 const MPI_Offset my_global_file_position =
1745 static_cast<MPI_Offset
>(global_num_cells) *
sizeof(
unsigned int) +
1748 dest_data_variable.resize(size_on_proc);
1752 my_global_file_position,
1753 dest_data_variable.data(),
1754 dest_data_variable.size(),
1759 ierr = MPI_File_close(&fh);
1763 (void)global_first_cell;
1764 (void)global_num_cells;
1765 (void)local_num_cells;
1767 (void)n_attached_deserialize_fixed;
1768 (void)n_attached_deserialize_variable;