Subject: [Ffc] FFC vs. SFC

From: [email-masked]
Date: Mon, 21 Jun 2010 15:42:29 +0200

Hi, just portet SFC to dolfin-dev and ufl-dev and made some simple
comparisons with FFC. I
don't know exactly how representative these are, but I thought I'd try to
compare
them for fun.

I have used the following code:

from dolfin import *
import time

for compiler in ["ffc", "sfc"]:

    for N in [200, 400, 800]:

        parameters["form_compiler"]["name"]=compiler
        if compiler == "ffc":
            parameters["form_compiler"]["optimize"] = True
            parameters ["form_compiler"]["cpp_optimize"] = True

        mesh = UnitSquare(N, N)
        V = FunctionSpace(mesh, "CG", 1)

        P=6
        U = Function(V)
        energy = U**6*(U*U + inner(grad(U), grad(U)))*dx

        v = TestFunction(V)
        u = TrialFunction(V)

        F = derivative(energy, U, v)
        J = derivative(F, U, u)

        print ""
        print "First time"
        print ""
        t0 = time.time()
        A = assemble(J)
        t1 = time.time()
        print "First time for ", compiler, " was ", t1 - t0

        print ""
        print "Second time"
        print ""
        t0 = time.time()
        A = assemble(J)
        t1 = time.time()

        print "Second time for ", compiler, " was ", t1 - t0

With these options SFC is about 3 times faster than FFC. How should I
optimize FFC ?

Kent

---

From: Kristian Oelgaard <[email-masked]>
Date: Mon, 21 Jun 2010 23:05:54 +0200

I tried to run the code against the dev versions of FEniCS and got the
following error after successfully finishing the FFC part:

Traceback (most recent call last):
  File "demo.py", line 15, in <module>
    V = FunctionSpace(mesh, "CG", 1)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/function/functionspace.py",
line 230, in __init__
    FunctionSpaceBase.__init__(self, mesh, element)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/function/functionspace.py",
line 44, in __init__
    ufc_element, ufc_dofmap = jit(self._ufl_element)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/compilemodules/jit.py",
line 44, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/compilemodules/jit.py",
line 87, in jit
    p = form_compiler.default_parameters()
AttributeError: 'module' object has no attribute 'default_parameters'

Kristian

On 21 June 2010 15:42,  <[email-masked]> wrote:
> _______________________________________________
> Mailing list: https://launchpad.net/~ffc
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ffc
> More help   : https://help.launchpad.net/ListHelp
>

---

From: Kent Andre <[email-masked]>
Date: Mon, 21 Jun 2010 23:16:28 +0200

Strange. I used dorsal to compile the dev versions of the various
packages. Dolfin, ffc, and sfc are only a few days old. 

But do you have any suggestions for how to optimize the FFC generated
code ? I have used quadrature here, tensor representation is not good
in this application. 

Kent

---

From: Kristian Oelgaard <[email-masked]>
Date: Mon, 21 Jun 2010 23:29:40 +0200

> code ? I have used quadrature here, tensor representation is not good

It looks like quadrature optimisations are already switched on, but
you can try the other optimisations:

# 1
parameters["form_compiler"]["optimize"] = True
parameters["form_compiler"]["eliminate_zeros"] = True
parameters["form_compiler"]["precompute_ip_const"] = True

# 2
parameters["form_compiler"]["optimize"] = True
parameters["form_compiler"]["eliminate_zeros"] = True
parameters["form_compiler"]["precompute_basis_const"] = True

also try without the

parameters["form_compiler"]["eliminate_zeros"] = True

option.

Kristian

---

From: "Garth N. Wells" <[email-masked]>
Date: Mon, 21 Jun 2010 22:35:14 -0400

On 21/06/10 17:29, Kristian Oelgaard wrote:
> On 21 June 2010 23:16, Kent Andre<[email-masked]>  wrote:
>>
> It looks like quadrature optimisations are already switched on,

. . . if the latest versions of ffc-dev and dolfin-dev are installed. 
There was a change in how the compiler options are passed.

Garth

> but
>>>    File "demo.py", line 15, in<module>
>>> On 21 June 2010 15:42,<[email-masked]>  wrote:
>>>>

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 22 Jun 2010 11:40:53 +0200

> packages. Dolfin, ffc, and sfc are only a few days old.

I removed fenics-syfi and cloned a new one, then I got a little
further but crashed on swiginac, I removed the python-swiginac 1.5.1-2
which I got through synaptic and had Dorsal install swiginac 1.5.1
(thank you Dorsal!) after which the demo.py file ran without
complaints.

Kristian

---

From: Harish Narayanan <[email-masked]>
Date: Tue, 22 Jun 2010 13:02:25 +0200

> (thank you Dorsal!) after which the demo.py file ran without

(You're welcome!)

Harish

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 22 Jun 2010 13:04:27 +0200

> code ? I have used quadrature here, tensor representation is not good

I had a look at the generated code from FFC and SyFi
(which by the way is a real pain when PyDOLFIN is involved)

and realised that your comparison is not fair.
FFC uses the UFL algorithm estimate_total_polynomial_degree() to
compute the quadrature_degree.
SFC uses (in this case) the UFL algorithm estimate_quadrature_degree()
which is less conservative.

This results in FFC using 25 integration points to compute the
integral while SFC just uses 3.

If you use the option:

parameters ["form_compiler"]["quadrature_degree"] = "2"

the comparison is _more_ fair and the numbers are almost the same.
SFC still uses 3 points, while FFC now uses 4 points which leads to my
answer to your first question:
"How should I optimize FFC?" :)

https://blueprints.launchpad.net/ffc/+spec/simplex-quadrature

Kristian

---

From: Johannes Ring <[email-masked]>
Date: Tue, 22 Jun 2010 13:07:45 +0200

> (thank you Dorsal!) after which the demo.py file ran without

What was the problem with python-swiginac? I'm maintaining the package
in Debian so I would be interested to know about any problems with it
(also in Ubuntu).

Johannes

---

From: Anders Logg <[email-masked]>
Date: Tue, 22 Jun 2010 13:15:08 +0200

> https://blueprints.launchpad.net/ffc/+spec/simplex-quadrature

I think either Andy Terrel or Peter Brune mentioned having worked out
some code for computing more efficient quadrature on simplices. There
was some discussion on adding that either to FIAT or FFC.

What ever happened to that?

--
Anders

---

From: [email-masked]
Date: Tue, 22 Jun 2010 13:17:27 +0200

> https://blueprints.launchpad.net/ffc/+spec/simplex-quadrature

Thanks! I get results that are really close to each other now.

Kent

---

From: Kristian Oelgaard <[email-masked]>
Date: Tue, 22 Jun 2010 13:19:04 +0200

> in Debian so I would be interested to know about any problems with it

I got the error:

Traceback (most recent call last):
  File "demo.py", line 16, in <module>
    V = FunctionSpace(mesh, "CG", 1)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/function/functionspace.py",
line 230, in __init__
    FunctionSpaceBase.__init__(self, mesh, element)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/function/functionspace.py",
line 44, in __init__
    ufc_element, ufc_dofmap = jit(self._ufl_element)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/compilemodules/jit.py",
line 44, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/home/oelgaard/software/fenics/dolfin/local/lib/python2.6/site-packages/dolfin/compilemodules/jit.py",
line 103, in jit
    return jit_compile(form, parameters=p, common_cell=common_cell)
  File "/home/oelgaard/software/fenics/fenics-syfi/local/lib/python2.6/site-packages/sfc/jit.py",
line 149, in jit
    hfilenames, cfilenames = generate_code(ufl_elements + formdatas,
None, parameters)
  File "/home/oelgaard/software/fenics/fenics-syfi/local/lib/python2.6/site-packages/sfc/codegeneration/codegeneration.py",
line 348, in generate_code
    erep = ElementRepresentation(e, quad_rule, options, element_reps,
common_cell)
  File "/home/oelgaard/software/fenics/fenics-syfi/local/lib/python2.6/site-packages/sfc/representation/elementrepresentation.py",
line 165, in __init__
    self.cell = UFCCell(self.polygon)
  File "/home/oelgaard/software/fenics/fenics-syfi/local/lib/python2.6/site-packages/sfc/geometry/UFCCell.py",
line 82, in __init__
    self.vertices        = [matrix(self.nsd, 1, polygon.vertex(i)) for
i in range(self.num_vertices)]
  File "/usr/lib/pymodules/python2.6/swiginac.py", line 1542, in __init__
    this = _swiginac.new_matrix(*args)
ValueError: Cannot convert type to ex.

It looks like we need to update some modules to work with the latest swiginac.

Kristian

---

From: Johannes Ring <[email-masked]>
Date: Tue, 22 Jun 2010 13:22:59 +0200

> It looks like we need to update some modules to work with the latest swiginac.

OK, thanks.

Johannes

---

From: Andy Ray Terrel <[email-masked]>
Date: Tue, 22 Jun 2010 09:05:44 -0500

> What ever happened to that?

The only fast quadrature I was working on was for the BCR wavelet
rules for Calderon Zygmund operators.  Rob has some recent stuff on
fast quadrature using Bernstein basis.  I'm not sure what Peter might
have been doing.

The local expert on quadrature at TACC, tells me the fastest schemes
for quadrature for simplices is Grundmann-Möller for lower orders (<
20 ish) and the standard conical product for higher orders.

@article{grundmann:282,
author = {Axel Grundmann and H. M. M\"{o}ller},
collaboration = {},
title = {Invariant Integration Formulas for the $n$-Simplex by
Combinatorial Methods},
publisher = {SIAM},
year = {1978},
journal = {SIAM Journal on Numerical Analysis},
volume = {15},
number = {2},
pages = {282-290},
url = {http://link.aip.org/link/?SNA/15/282/1},
doi = {10.1137/0715019}
}

>
> --
> Anders
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAkwgmzsACgkQTuwUCDsYZdGcqwCgh1QCnNr0Jr1a2mcxDqheCpZ0
> ItkAn36nLWyr2RDO6pqgF4PX753ItHaU
> =HnEK
> -----END PGP SIGNATURE-----
>

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 22 Jun 2010 08:31:17 -0700

On 22/06/10 07:05, Andy Ray Terrel wrote:
> On Tue, Jun 22, 2010 at 6:15 AM, Anders Logg<[email-masked]>  wrote:

I've pasted the above into

     https://blueprints.launchpad.net/ffc/+spec/simplex-quad

Garth

---

From: Andy Ray Terrel <[email-masked]>
Date: Tue, 22 Jun 2010 11:18:32 -0500

>    https://blueprints.launchpad.net/ffc/+spec/simplex-quad

I added a few more notes and links on the blueprint.

-- Andy

---

From: Peter Brune <[email-masked]>
Date: Tue, 29 Jun 2010 21:57:43 -0500

I implemented the Grundmann-Möller rules for some general dimensional FEM
stuff a while back.  My observations were along these lines also.  The other
issue is that they are not going to behave as nicely against some arbitrary
function; I forget exactly how the lebesgue constants work out, but it isn't
necessarily as good as the conical rules. The conical rules also tended to
win at low-order in 2D; it was 3D and above where the more elegant rules
tended to win.

My previous declaration that this should be done got stuck in an FFC/FIAT
limbo.

- Peter

On Tue, Jun 22, 2010 at 11:18 AM, Andy Ray Terrel <[email-masked]>wrote:

> >>> Mailing list: https://launchpad.net/~ffc<https://launchpad.net/%7Effc>
> >>> Unsubscribe : https://launchpad.net/~ffc<https://launchpad.net/%7Effc>
> >> Mailing list: https://launchpad.net/~ffc <https://launchpad.net/%7Effc>
> >> Unsubscribe : https://launchpad.net/~ffc <https://launchpad.net/%7Effc>
> > Mailing list: https://launchpad.net/~ffc <https://launchpad.net/%7Effc>
> > Unsubscribe : https://launchpad.net/~ffc <https://launchpad.net/%7Effc>
> Mailing list: https://launchpad.net/~ffc <https://launchpad.net/%7Effc>
> Unsubscribe : https://launchpad.net/~ffc <https://launchpad.net/%7Effc>