Using num_threads in fenics

Dear sir,

how to speed up the running time/parallelization in feincs by using fenics parameters. I tried with the following code but it is showing an error.

parameters["allow_extrapolation"] = True # for mesh mappings
parameters["form_compiler"]["optimize"] = True # optimise compiler pg 167 fenics boo
Traceback (most recent call last):
  File "try.py", line 8, in <module>
    parameters["num_threads"] = 6 # invoke multi-thread parallel support
RuntimeError: Parameter num_threads not found in Parameters object

error is

sorry sir I missed first line of code

parameters["num_threads"] = 6 # invoke multi-thread parallel support

Concurrent processing with threads was removed a long time ago, circa 2014 I believe.

Parallelism in FEniCS is achieved by partitioning problems to MPI processes. E.g. running a script in the following manner will employ 4 MPI processes:

mpirun -np 4 python3 demo_poisson.py
2 Likes

Thank you for your reply.

I used

mpirun -np 4 python3 demo_poisson.py  to run the code but its showing in different output with four processor                          
 Process 0: Solving linear variational problem.
Process 3: Solving linear variational problem.
Process 1: Solving linear variational problem.
Process 2: Solving linear variational problem.

That is the expected behavior. When you run in parallel, every task is divided between processes, so the output shows which task each process is doing. If you don’t want to see a lot of outputs, you can use something like this at the begining of your code:

# MPI parameters
comm = MPI.comm_world
rank = MPI.rank(comm)

# Sets log level for parallel runs
set_log_level(LogLevel.ERROR)
if rank == 0: set_log_level(LogLevel.PROGRESS)

For further information about the log level see this old but very useful post.

2 Likes

Thank you for your reply.

no change in output even after using provided code above. still am getting four output.