Assembly time

Asked by Dupront

Hello,

Here is a very simple case that consists in imposing a
displacement on the top of a cube.
I want to measure the assembly phase time.

But depending on how I proceed I have different values.
If I use the method assemble_systeme(), I get:

(1)
 Summary of timings | Average time Total time Reps
  -------------------------------------------------------------
  Assemble system | 0.74892 0.74892 1

With the method solve and the option "symmetric=True", I get:

(2)
  Summary of timings | Average time Total time Reps
  -------------------------------------------------------------
  Assemble system | 0.59774 0.59774 1

Finally with the method solve and without the option "symmetric=True", I get:

(3)
  Summary of timings | Average time Total time Reps
  -------------------------------------------------------------
  Assemble cells | 0.1642 0.3284 2

Here I would have 2 questions:
  1- why do I get different times in case (1) and (2) ?
  2- what is "Assemble cells" compare to "Assemble system" ?
     Why not the "Assemble system" time here too ?

Also I noticed that there is no diffence if I use or not
the -O2 compilation option.
I was expecting a "big" difference.

I am using ubuntu 12.04

Thank a lot for any help.

************************
************************

from dolfin import *

# Form compiler options
parameters["form_compiler"]["cpp_optimize"] = True
#parameters["form_compiler"]["cpp_optimize_flags"] = "-O2"
ffc_options = {"optimize": True,
               "eliminate_zeros": True,
               "precompute_basis_const": True,
               "precompute_ip_const": True,}
parameters ["form_compiler"]["quadrature_degree"] = 1

# Create mesh and define function space
mesh = UnitCube(20,20,20)
V = VectorFunctionSpace(mesh, "CG", 1)

# Sub domain for DBC
up, down = compile_subdomains(["(fabs(x[2] - 1.0) < DOLFIN_EPS) && on_boundary",
                               "(fabs(x[2]) < DOLFIN_EPS) && on_boundary"])
origine = compile_subdomains(["fabs(x[0])< DOLFIN_EPS && fabs(x[1])< DOLFIN_EPS && fabs(x[2])< DOLFIN_EPS && on_boundary",])
unit = compile_subdomains(["fabs(x[0])< DOLFIN_EPS && fabs(x[1]-1.) < DOLFIN_EPS && fabs(x[2])< DOLFIN_EPS && on_boundary",])

# Define Dirichlet boundary
e_zero = Expression("0.0",)
e_deltaZ = Expression("-0.05",)

bcXorigine = DirichletBC(V.sub(0), e_zero, origine)
bcYorigine = DirichletBC(V.sub(1), e_zero, origine)
bcXunit = DirichletBC(V.sub(0), e_zero, unit)
bcZd = DirichletBC(V.sub(2), e_zero, down)
bcZu = DirichletBC(V.sub(2), e_deltaZ, up)

# Define variational problem
v = TestFunction(V)
u = TrialFunction(V)
f = Constant((0.0, 0.0, 0.0))

# Material constants
Em = 100000.000000
nu = 0.300000

mu = Constant(Em / (2*(1 + nu))) # Lame's constants
lmbda = Constant(Em * nu / ((1 + nu) * (1 - 2 * nu)))

def sigma(v):
  return 2.0*mu*sym(grad(v)) + lmbda*tr(sym(grad(v)))*Identity(v.cell().d)

a = inner(grad(v), sigma(u))*dx
L = inner(v, f)*dx

# Set up boundary conditions
bcs = [bcXorigine, bcYorigine, bcXunit, bcZd, bcZu]

# Compute solution

assembling_only = True
A, b = None, None
if assembling_only:
  A, b = assemble_system(a, L, bcs, )
  #A.str(True)
else:
  solver_params={"symmetric": True}
  solver_params.update({"linear_solver" : "lu",})
  u = Function(V)
  solve(a == L, u, bcs, solver_parameters=solver_params,
               form_compiler_parameters=ffc_options)

  # Save solution to VTK format
  #ofile_name = os.path.join(storage_path,"T-1-1-1-O1-Hooke-iteratif-C-L.pvd")
  #vtk_file = File(ofile_name)
  #vtk_file << u

# times
list_timings()

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

On 06/14/2012 02:21 PM, Dupront wrote:
> New question #200420 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/200420
>
> Hello,
>
> Here is a very simple case that consists in imposing a
> displacement on the top of a cube.
> I want to measure the assembly phase time.
>
> But depending on how I proceed I have different values.
> If I use the method assemble_systeme(), I get:
>
> (1)
> Summary of timings | Average time Total time Reps
> -------------------------------------------------------------
> Assemble system | 0.74892 0.74892 1
>
> With the method solve and the option "symmetric=True", I get:
>
> (2)
> Summary of timings | Average time Total time Reps
> -------------------------------------------------------------
> Assemble system | 0.59774 0.59774 1
>
> Finally with the method solve and without the option "symmetric=True", I get:
>
> (3)
> Summary of timings | Average time Total time Reps
> -------------------------------------------------------------
> Assemble cells | 0.1642 0.3284 2
>
> Here I would have 2 questions:
> 1- why do I get different times in case (1) and (2) ?

Add form_compiler_parameters=ffc_options to assemble_systems or remove
it from solve and you will get the same timings for the symmetric cases.

The difference between assemble_system and the two assemble_cell calls
are that within assemble_system are the bc applied, where in the
assemble_cell case they are applied outside the assemble, and hence not
accounted for in the timings.

johan

> 2- what is "Assemble cells" compare to "Assemble system" ?
> Why not the "Assemble system" time here too ?
>
>
> Also I noticed that there is no diffence if I use or not
> the -O2 compilation option.
> I was expecting a "big" difference.
>
> I am using ubuntu 12.04
>
> Thank a lot for any help.
>
>
> ************************
> ************************
>
> from dolfin import *
>
>
> # Form compiler options
> parameters["form_compiler"]["cpp_optimize"] = True
> #parameters["form_compiler"]["cpp_optimize_flags"] = "-O2"
> ffc_options = {"optimize": True,
> "eliminate_zeros": True,
> "precompute_basis_const": True,
> "precompute_ip_const": True,}
> parameters ["form_compiler"]["quadrature_degree"] = 1
>
> # Create mesh and define function space
> mesh = UnitCube(20,20,20)
> V = VectorFunctionSpace(mesh, "CG", 1)
>
> # Sub domain for DBC
> up, down = compile_subdomains(["(fabs(x[2] - 1.0)< DOLFIN_EPS)&& on_boundary",
> "(fabs(x[2])< DOLFIN_EPS)&& on_boundary"])
> origine = compile_subdomains(["fabs(x[0])< DOLFIN_EPS&& fabs(x[1])< DOLFIN_EPS&& fabs(x[2])< DOLFIN_EPS&& on_boundary",])
> unit = compile_subdomains(["fabs(x[0])< DOLFIN_EPS&& fabs(x[1]-1.)< DOLFIN_EPS&& fabs(x[2])< DOLFIN_EPS&& on_boundary",])
>
> # Define Dirichlet boundary
> e_zero = Expression("0.0",)
> e_deltaZ = Expression("-0.05",)
>
> bcXorigine = DirichletBC(V.sub(0), e_zero, origine)
> bcYorigine = DirichletBC(V.sub(1), e_zero, origine)
> bcXunit = DirichletBC(V.sub(0), e_zero, unit)
> bcZd = DirichletBC(V.sub(2), e_zero, down)
> bcZu = DirichletBC(V.sub(2), e_deltaZ, up)
>
> # Define variational problem
> v = TestFunction(V)
> u = TrialFunction(V)
> f = Constant((0.0, 0.0, 0.0))
>
> # Material constants
> Em = 100000.000000
> nu = 0.300000
>
> mu = Constant(Em / (2*(1 + nu))) # Lame's constants
> lmbda = Constant(Em * nu / ((1 + nu) * (1 - 2 * nu)))
>
> def sigma(v):
> return 2.0*mu*sym(grad(v)) + lmbda*tr(sym(grad(v)))*Identity(v.cell().d)
>
> a = inner(grad(v), sigma(u))*dx
> L = inner(v, f)*dx
>
> # Set up boundary conditions
> bcs = [bcXorigine, bcYorigine, bcXunit, bcZd, bcZu]
>
> # Compute solution
>
> assembling_only = True
> A, b = None, None
> if assembling_only:
> A, b = assemble_system(a, L, bcs, )
> #A.str(True)
> else:
> solver_params={"symmetric": True}
> solver_params.update({"linear_solver" : "lu",})
> u = Function(V)
> solve(a == L, u, bcs, solver_parameters=solver_params,
> form_compiler_parameters=ffc_options)
>
> # Save solution to VTK format
> #ofile_name = os.path.join(storage_path,"T-1-1-1-O1-Hooke-iteratif-C-L.pvd")
> #vtk_file = File(ofile_name)
> #vtk_file<< u
>
> # times
> list_timings()
>
>
>

Can you help with this problem?

Provide an answer of your own, or ask Dupront for more information if necessary.

To post a message you must log in.