My code is like this! I just want to solve two problems parallelly!
from dolfin import *
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)
if(rank==0):
g = Expression('sin(pi*x[0])*sin(pi*x[1])',pi = np.pi )
f = Expression('2*pi*pi*sin(pi*x[0])*sin(pi*x[1])',pi = np.pi)
elif(rank==1):
g = Expression('exp(-ll*(x[0]-0.5) )+exp(ll*(x[0]-0.5))',ll=20.0 )
f = Expression('-ll*ll*exp(-ll*(x[0]-0.5))-ll*ll*exp(ll*(x[0]-0.5))',ll=20.0)
class Boundary(SubDomain):
def inside(self,x,on_boundary):
return on_boundary
bc = DirichletBC(V, g, Boundary())
a = inner(grad(u), grad(v))*dx
L = f*v*dx
A = assemble( a )
b = assemble( L )
bc.apply(A,b)
u = Function(V)
solve(A,u.vector(),b)
plot(u)
interactive()
And I run it like this: mpirun -np 2 python myprogram.py
Thanks!