Using weight with parmetis partitioner

Hello,
In version 0.9 of C++ Dolfinx, I could not find a way to perform load balancing on a mesh using weights per cell, as proposed by the Parmetis API.

I just want to check that I didn’t miss the right solution, as I did what I wanted anyway with the following C++ code :

header

CPP with a partial copy of partitioners.cpp (only the modified part is shown).


and before calling parmetis

which can be used as follow:

// weights computed above the way you want
const auto partitioner = dolfinx::graph::parmetis::partitionerWithWeight(weights);
auto cell_part= dolfinx::mesh::create_cell_partitioner(dolfinx::mesh::GhostMode::none,partitioner);
// here some code to provides correct arguments to create_mesh
auto new_mesh = dolfinx::mesh::create_mesh(......., cell_part);

This is not safe, as the weights and function returned by partitionerWithWeight must be used with the same mesh dual graph. However, it is quick to implement and safe in my context. In future, it might be interesting to add edge dual graph weights, optional arguments, and Python exposure, unless this approach is deemed too insecure.

Thanks in advance

Oops! Sorry, I didn’t provide the correct code snapshot showing how UBVEC is modified to cope with ncon > 1. The correct version, which allows for multiple weights per cell, can be found below.

In general, it is adviced to wrap code with 3x` encapsulation, i.e.

```c++
// check ....
if (num_local_nodes * nb_weights != weights.size())
{
   ...
}
```

as one can then copy the code.

As I am not an expert in the ParMetis interface, I would rely on input from others on this, @nate @IgorBaratta ?:slight_smile: