Consider running following script with mpirun -n 2 python3 test.py
:
import numpy as np
import dolfin as df
N = 400
comm = df.MPI.comm_world
mesh = df.UnitSquareMesh(comm, N, N)
P1 = df.FiniteElement('Lagrange', mesh.ufl_cell(), 1)
R = df.FiniteElement('Real', mesh.ufl_cell(), 0)
ME = df.FunctionSpace(mesh, P1*R)
a0 = df.interpolate(df.Expression('x[0] + x[1]', degree=1), ME.sub(0).collapse())
print('comm.rank =', comm.rank, 'len(a0) =', len(a0.vector()))
b0 = df.Function(ME.sub(1).collapse())
print('comm.rank =', comm.rank, 'len(b0) =', len(b0.vector()))
if len(b0.vector()) > 0:
b0.vector()[:] = np.array([1.0])
On my laptop it shows 2 processors being utitized 100% for a long time. Can someone cross-check this?
Process 0: Time elapsed before last instruction = 1.143418 s
Process 1: Time elapsed before last instruction = 1.143401 s
Process 0: Last instruction = 0.000019 s
Process 1: Last instruction = Forever
Now:
Process 0: Time elapsed before last instruction = 1.133295
Process 1: Time elapsed before last instruction = 1.133376
Process 0: Last instruction : 0.000107
Process 1: Last instruction : 0.000107
Process 0: B norm = 1.000000
Process 1: B norm = 1.000000
import dolfin as df
with df.Timer() as t:
N = 400
comm = df.MPI.comm_world
mesh = df.UnitSquareMesh(comm, N, N)
P1 = df.FiniteElement('Lagrange', mesh.ufl_cell(), 1)
R = df.FiniteElement('Real', mesh.ufl_cell(), 0)
ME = df.FunctionSpace(mesh, P1*R)
a0 = df.interpolate(df.Expression('x[0] + x[1]', degree=1), ME.sub(0).collapse())
b0 = df.Function(ME.sub(1).collapse())
df.info("Temps elapsed before last instruction = %f" %t.elapsed()[0])
with df.Timer() as t:
vec = b0.vector()
values = vec.get_local()
values[:] = 1.0
vec.set_local(values)
vec.apply('insert')
df.info("Last instruction : %f" %t.elapsed()[0])
df.info("B norm = %f" %df.norm(b0))
Enjoy!
1 Like