UFL

Using sym() results in overhead

Bug #868255 reported by Gerd Wachsmuth
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UFL
Invalid
Low
Unassigned

Bug Description

If I use the function sym() to assemble a form containing the symmetric part of a matrix, the (1,1)-element of the matrix gets represented as "2*A[1,1]/2" or "(A[1,1]+A[1,1])/2". This induces overhead when assembling the FE matrices.

For instance, compiling

element = TensorElement("CG", triangle, 1)
A = Coefficient(element)
B = Coefficient(element)

a = sqrt(inner(sym(A),sym(B)))*dx

with ffc (optimization turned on with -O), the header file contains something like "(F0 + F0)/2.000000000000000*(F1 + F1)/2.000000000000000".

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

Won't fix for 1.0.

Could possibly be fixed locally by specifying each matrix entry separately.

In general, optimizations like this are not done in UFL for good reasons,
UFL is really careful about not modifying the input expressions.

In the future, this particular case ((n*x)/n) _may_ be a candidate for
automatic simplification, along with other similar cases.

Have you actually profiled code with and without this though?
I would half expect (or hope) that the optimizing C++ compiler picked this up.

Changed in ufl:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Gerd Wachsmuth (gerd-wachsmuth) wrote :

No, I didn't do any profilings.

Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) wrote : Re: [Bug 868255] Re: Using sym() results in overhead

On 5 October 2011 14:12, Gerd Wachsmuth
<email address hidden> wrote:
> No, I didn't do any profilings.

This bug should probably be filed in FFC instead, but please support
any 'overhead' claims with at least some simple profiling.

The fix to optimise expressions inside operators like 'sqrt', 'ln',
'sin' etc. is non-trivial in the current quadrature implementation and
will not be addressed before 1.0 is released.

> --
> You received this bug notification because you are subscribed to UFL.
> https://bugs.launchpad.net/bugs/868255
>
> Title:
>  Using sym() results in overhead
>
> Status in Unified Form Language:
>  Confirmed
>
> Bug description:
>  If I use the function sym() to assemble a form containing the
>  symmetric part of a matrix, the (1,1)-element of the matrix gets
>  represented as "2*A[1,1]/2" or "(A[1,1]+A[1,1])/2". This induces
>  overhead when assembling the FE matrices.
>
>  For instance, compiling
>
>  element = TensorElement("CG", triangle, 1)
>  A = Coefficient(element)
>  B = Coefficient(element)
>
>  a = sqrt(inner(sym(A),sym(B)))*dx
>
>  with ffc (optimization turned on with -O), the header file contains
>  something like "(F0 + F0)/2.000000000000000*(F1 +
>  F1)/2.000000000000000".
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ufl/+bug/868255/+subscriptions
>

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

This is not really a bug, there will always be cases that are not represented optimally. As mentioned above, simplifications like this may or may not be improved in the future, but they are not bugs.

Changed in ufl:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.