Hello there,
Consider the following code (fenics 2016.1), that allow to solve two probem in parallel, attributing a MPI communicator for each mesh:
(https://fenicsproject.org/qa/2682/solve-independent-equations-on-different-cores)
with mpirun -n 2 python program.py:
from dolfin import *
from mpi4py import MPI
# Communicator
mpi_comm = MPI.COMM_WORLD
# Rank
rank_process = mpi_comm.rank
# Create mesh: one for each process
# create a mesh with a given MPI communicator is the key
if rank_process==0:
mesh = UnitSquareMesh(mpi_comm_self(), 10, 10)
if rank_process==1:
mesh = UnitSquareMesh(mpi_comm_self(), 20, 20)
# Plot mesh
plot_title= 'MESH for the process: {value}'.format(value=rank_process)
plot(mesh, title=plot_title, interactive=True)
# Function space and functions
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
u_ = Function(V)
# Set source
if rank_process==0:
source = Constant(1)
if rank_process==1:
source = Constant(-1)
# Solve
solve(inner(grad(u), grad(v))*dx == source*v*dx, u_, bcs=DirichletBC(V, 0, "on_boundary"))
# Plot
plot(u_, title="Solution of the Proces {}".format(rank_process))
interactive()
Now, i would like that each problem (let's call them problem 1 and problem 2) use several process:
pseudo-code: of what i want to acheive:
mpirun - n NP python program.py
# Get number of DOF for each problem
DOF of probem 1
DOF of probem 2
# Attribute the number of process proportionally to the number of DOF
NP_for_problem1 = DOF of probem 1 / (DOF of probem 1 + DOF of probem 2) * NP
NP_for_problem2 = DOF of probem 2 / (DOF of probem 1 + DOF of probem 2) * NP
# Create mesh
# How to attribute multiple process to each mesh?
mesh_problem_1 = UnitSquareMesh( ??? ,10, 10)
mesh_problem_1 = UnitSquareMesh( ??? , 20, 20)
etc. until solve