How to visualize which part of mesh is with which processor
In our research we come across many high scale problem which need to be solved, and it is very important that the approach should be efficient. One of the way by which we can run a program parallelly. In our lab we commonly use Python language and FEniCS for computation.
How to do parallelization for loop in python with MPI is well explained in “” Blog.
This post will give you the answer for the next step i.e, how to visualise which part of mesh is with which processor. This can be easily done using the Mesh Function command in FEniCS.
I have explained this using a simple example.
- A rectangular mesh (.msh) is generated using Gmsh.
- Using “meshio-convert”, convert the .msh file to .xdmf file.
- We can identify the processor number by first getting a handle to the world communicator by using command.
comm = MPI.COMM_WORLD
- Then get the rank of the processor by using the command
rank = comm.Get_rank()
- The .xdmf file is imported in the FEniCS code.
mesh = Mesh() with XDMFFile("rectangle.xdmf") as infile: infile.read(mesh)
- A mesh function is created for the mesh.
mf =MeshFunction("size_t", mesh, 2)
- Mark the mesh function with the allotted rank of the processor.
- Then we can write the mesh function in a xdmf file, which can be viewed using the Paraview.
xdmf = XDMFFile("output" + ".xdmf") xdmf.write(mf) xdmf.close()
- You can run the script using the command :
mpirun -np 2 python3 test.py
In this command “2” indicates the number of processor you are using to solve the problem.
- When the same script is using 6 processors to solve the problem using the command:
mpirun -np 6 python3 test.py