Does FEniCS support batched solving?

I have a problem where I want to solve a PDE on multiple inputs. For example, suppose we have the Poisson equation (copied below from docs):

from fenics import *

# Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)

def boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u_D, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)

But I wish to feed in a batch of f, for example 100 different values, and solve the PDE for those inputs. Currently, I’m doing this by iterating sequentially over the 100 values. I have already tried using multiprocessing, but this is not compatible with autograd. Is there no way of feeding in an input with a batch dimension? In the end FEniCS is carrying out linear algebra, and implementations normally have support for this kind of thing.

Hi G.K,

Thank you for your message. An internal loop would be sequential. I wish to carry out the FEM with batched operations to make it much more efficient for processing multiple inputs. Does FEniCS support batched linear algebra?

Apologies for not being clearer.

Best,

Jacob

You can use ProcessPoolExecutors: concurrent.futures — Launching parallel tasks — Python 3.9.4 documentation
In turn this would create a mesh for each thread and solve the problems in parallel

Thanks for the suggestion. However, as mentioned in the post, I can’t use multiprocessing as it is not compatible with autograd.