dolfinx icon indicating copy to clipboard operation
dolfinx copied to clipboard

Replace edge_maps in refinement with AdjacencyList

Open jorgensd opened this issue 2 years ago • 3 comments

When computing refinement data, we currently create a std::map from the local edge numbers to the processes sharing that edge (https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/refinement/utils.h#L38-L39) In turn we use this map multiple times, with map.find(), which has logarithmic complexity; https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/refinement/plaza.cpp#L645 https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/refinement/plaza.cpp#L87-L88 https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/refinement/utils.cpp#L256-L257

I wonder if it would be faster to use an AdjacencyList<std::int32_t> which has num_local_edges as number of nodes, and each link containing the neighborhood ranks. Then every find would be replaced with:

auto map_it = shared_edges.links(local_edge)
if (!map_it.empty())
{
   // Do something...
}

Any thoughts @garth-wells ?

jorgensd avatar Mar 30 '22 10:03 jorgensd

In general, anything that replaces a std::map with a O(1) lookup and contiguous memory is good. The main question is probably how to compute the data efficiently in the first place.

garth-wells avatar Mar 30 '22 14:03 garth-wells

This is a good idea, let's do it once the current work on MeshTag refinement is in main.

chrisrichardson avatar Mar 30 '22 16:03 chrisrichardson