Skip to content
Snippets Groups Projects
Commit ade3d9ad authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Attempt to write some simple mesh dispatcher

Data structure my have to be reworked
parent 3d6ca051
No related branches found
No related tags found
1 merge request!11Feature/mpi
......@@ -141,90 +141,151 @@ ErrorHandler(const std::string& filename,
;
}
template <int Dimension>
void GmshReader::_dispatch()
class MeshDispatcher
{
using ConnectivityType = Connectivity<Dimension>;
using Rd = TinyVector<Dimension>;
using MeshType = Mesh<ConnectivityType>;
if (not m_mesh) {
std::shared_ptr<ConnectivityType> connectivity(new ConnectivityType({},{},{}));
NodeValue<Rd> xr;
m_mesh = std::shared_ptr<IMesh>(new MeshType(connectivity, xr));
}
const MeshType& mesh = static_cast<const MeshType&>(*m_mesh);
public:
using MeshType = Mesh<Connectivity<Dimension>>;
CSRGraph mesh_graph = mesh.cellToCellGraph();
private:
const MeshType& m_mesh;
using CellListToSendByProc = std::vector<Array<const CellId>>;
const CellListToSendByProc m_cell_list_to_send_by_proc;
const int reader_rank
= [&]() {
Array<int> parts = allGather(static_cast<int>(mesh.numberOfCells()));
std::set<int> part_set;
for (size_t i=0; i<parts.size(); ++i) {
if (parts[i] != 0) { part_set.insert(i); }
}
if (part_set.size() != 1) {
perr() << "mesh should be read by one processor\n";
}
return *begin(part_set);
} ();
Array<int> m_nb_cell_to_send_by_proc;
Array<int> m_nb_cell_to_recv_by_proc;
pout() << "Mesh read by process " << rang::style::bold << reader_rank << rang::style::reset << '\n';
const CellListToSendByProc
_buildCellListToSend() const
{
CSRGraph mesh_graph = m_mesh.cellToCellGraph();
Partitioner P;
Array<int> cell_new_owner = P.partition(mesh_graph);
const std::vector<Array<const CellId>> cell_to_send_by_proc
= [&] () {
std::vector<std::vector<CellId>> cell_vector_to_send_by_proc(commSize());
for (size_t i=0; i<cell_new_owner.size(); ++i) {
cell_vector_to_send_by_proc[cell_new_owner[i]].push_back(CellId{i});
}
std::vector<Array<const CellId>> cell_to_send_by_proc(commSize());
std::vector<Array<const CellId>> cell_list_to_send_by_proc(commSize());
for (size_t i=0; i<commSize(); ++i) {
cell_to_send_by_proc[i] = convert_to_array(cell_vector_to_send_by_proc[i]);
cell_list_to_send_by_proc[i] = convert_to_array(cell_vector_to_send_by_proc[i]);
}
return std::move(cell_to_send_by_proc);
} ();
return std::move(cell_list_to_send_by_proc);
}
const auto& cell_number = mesh.connectivity().cellNumber();
const std::vector<Array<const int>> cell_number_to_send_by_proc
= [&] () {
std::vector<Array<const int>> cell_number_to_send_by_proc(commSize());
Array<int> _buildNbCellToSend()
{
Array<int> nb_cell_to_send_by_proc(commSize());
for (size_t i=0; i<commSize(); ++i) {
const Array<const CellId>& cell_list = cell_to_send_by_proc[i];
Array<int> cell_number_list(cell_list.size());
nb_cell_to_send_by_proc[i] = m_cell_list_to_send_by_proc[i].size();
}
return nb_cell_to_send_by_proc;
}
public:
template<typename DataType>
std::vector<Array<std::remove_const_t<DataType>>>
exchange(const CellValue<DataType>& cell_value) const
{
using MutableDataType = std::remove_const_t<DataType>;
std::vector<Array<DataType>> cell_value_to_send_by_proc(commSize());
for (size_t i=0; i<commSize(); ++i) {
const Array<const CellId>& cell_list = m_cell_list_to_send_by_proc[i];
Array<MutableDataType> cell_value_list(cell_list.size());
parallel_for (cell_list.size(), PASTIS_LAMBDA(const CellId& cell_id) {
cell_number_list[cell_id] = cell_number[cell_list[cell_id]];
cell_value_list[cell_id] = cell_value[cell_list[cell_id]];
});
cell_number_to_send_by_proc[i] = cell_number_list;
cell_value_to_send_by_proc[i] = cell_value_list;
}
return std::move(cell_number_to_send_by_proc);
} ();
Array<int> nb_cell_to_send_by_proc(commSize());
std::vector<Array<MutableDataType>> recv_cell_value_by_proc(commSize());
for (size_t i=0; i<commSize(); ++i) {
nb_cell_to_send_by_proc[i] = cell_to_send_by_proc[i].size();
recv_cell_value_by_proc[i] = Array<MutableDataType>(m_nb_cell_to_recv_by_proc[i]);
}
Array<int> nb_cell_to_recv_by_proc = allToAll(nb_cell_to_send_by_proc);
::exchange(cell_value_to_send_by_proc, recv_cell_value_by_proc);
return std::move(recv_cell_value_by_proc);
}
const size_t new_cell_number
= mesh.numberOfCells()
+ Sum(nb_cell_to_recv_by_proc)
- Sum(nb_cell_to_send_by_proc);
[[deprecated]]
const CellListToSendByProc& cell_list_to_send_by_proc() const
{
return m_cell_list_to_send_by_proc;
}
std::vector<Array<int>> recv_cell_number_by_proc(commSize());
for (size_t i=0; i<commSize(); ++i) {
recv_cell_number_by_proc[i] = Array<int>(nb_cell_to_recv_by_proc[i]);
MeshDispatcher(const MeshType& mesh)
: m_mesh(mesh),
m_cell_list_to_send_by_proc(_buildCellListToSend()),
m_nb_cell_to_send_by_proc(_buildNbCellToSend()),
m_nb_cell_to_recv_by_proc(allToAll(m_nb_cell_to_send_by_proc))
{
;
}
exchange(cell_number_to_send_by_proc, recv_cell_number_by_proc);
MeshDispatcher(const MeshDispatcher&) = delete;
~MeshDispatcher() = default;
};
template <int Dimension>
void GmshReader::_dispatch()
{
using ConnectivityType = Connectivity<Dimension>;
using Rd = TinyVector<Dimension>;
using MeshType = Mesh<ConnectivityType>;
if (not m_mesh) {
std::shared_ptr<ConnectivityType> connectivity(new ConnectivityType({},{},{}));
NodeValue<Rd> xr;
m_mesh = std::shared_ptr<IMesh>(new MeshType(connectivity, xr));
}
const MeshType& mesh = static_cast<const MeshType&>(*m_mesh);
MeshDispatcher<Dimension> dispatcher(mesh);
std::vector<Array<int>> recv_cell_number_by_proc
= dispatcher.exchange(mesh.connectivity().cellNumber());
std::vector<Array<CellType>> recv_cell_type_by_proc
= dispatcher.exchange(mesh.connectivity().cellType());
// const std::vector<Array<const CellId>>& cell_to_send_by_proc
// = dispatcher.cell_list_to_send_by_proc();
// Array<int> nb_cell_to_send_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// nb_cell_to_send_by_proc[i] = cell_to_send_by_proc[i].size();
// }
// Array<int> nb_cell_to_recv_by_proc = allToAll(nb_cell_to_send_by_proc);
// const auto& cell_number = mesh.connectivity().cellNumber();
// const std::vector<Array<const int>> cell_number_to_send_by_proc
// = [&] () {
// std::vector<Array<const int>> cell_number_to_send_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// const Array<const CellId>& cell_list = cell_to_send_by_proc[i];
// Array<int> cell_number_list(cell_list.size());
// parallel_for (cell_list.size(), PASTIS_LAMBDA(const CellId& cell_id) {
// cell_number_list[cell_id] = cell_number[cell_list[cell_id]];
// });
// cell_number_to_send_by_proc[i] = cell_number_list;
// }
// return std::move(cell_number_to_send_by_proc);
// } ();
// std::vector<Array<int>> recv_cell_number_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// recv_cell_number_by_proc[i] = Array<int>(nb_cell_to_recv_by_proc[i]);
// }
// exchange(cell_number_to_send_by_proc, recv_cell_number_by_proc);
// std::vector<Array<CellType>> cell_type_to_send_by_proc
// = [&] () {
......@@ -250,6 +311,12 @@ void GmshReader::_dispatch()
// barrier();
}
// const size_t new_cell_number
// = mesh.numberOfCells()
// + Sum(nb_cell_to_recv_by_proc)
// - Sum(nb_cell_to_send_by_proc);
Messenger::destroy();
std::exit(0);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment