Parallell distribution of Real function space vector

Asked by Martin Sandve Alnæs

Hi, I'm trying to fix an issue which involves evaluating a Real function in parallell. This can be done by just picking values from the vector, but who owns these dofs? Everyone? Can I just use get_local or should I use gather? And should any of these work from python? I'm getting signature errors from the swig layers in both attempts here:

    def test_real_function_vector_gather(self):
        import numpy
        c = Function(R)
        c.assign(Constant(2.34))

        values = numpy.zeros(1, dtype='d')
        vec = c.vector()

        # Gather value directly from vector in a parallell safe way
        indices = numpy.zeros(1, dtype='i')
        vec.gather(values, indices)

This gives:
TypeError: in method 'GenericVector_gather', argument 2 of type 'dolfin::GenericVector &'

    def test_real_function_vector_getlocal(self):
        import numpy
        c = Function(R)
        c.assign(Constant(2.34))

        values = numpy.zeros(1, dtype='d')
        vec = c.vector()

        # Get value directly from local vector
        vec.get_local(values)

        self.assertEqual(float(values[0]), 2.34)

This gives:
NotImplementedError: Wrong number or type of arguments for overloaded function 'GenericVector_get_local'.
  Possible C/C++ prototypes are:
    dolfin::GenericVector::get_local(double *,dolfin::uint,dolfin::uint const *) const
    dolfin::GenericVector::get_local(std::vector< double > &) const

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On Thu, Nov 8, 2012 at 9:21 AM, Martin Sandve Alnæs
<email address hidden> wrote:
> New question #213657 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/213657
>
> Hi, I'm trying to fix an issue which involves evaluating a Real function in parallell. This can be done by just picking values from the vector, but who owns these dofs? Everyone? Can I just use get_local or should I use gather?

Global dofs are owned by process 0 (although this is not guaranteed in
the future).

There are some efficiency issues with having global dofs in parallel
that should probably be looked at in the future.

>And should any of these work from python? I'm getting signature errors from the swig layers in both attempts here:
>
> def test_real_function_vector_gather(self):
> import numpy
> c = Function(R)
> c.assign(Constant(2.34))
>
> values = numpy.zeros(1, dtype='d')
> vec = c.vector()
>
> # Gather value directly from vector in a parallell safe way
> indices = numpy.zeros(1, dtype='i')
> vec.gather(values, indices)
>

I don't know if gather has been tested from Python.

> This gives:
> TypeError: in method 'GenericVector_gather', argument 2 of type 'dolfin::GenericVector &'
>
>
> def test_real_function_vector_getlocal(self):
> import numpy
> c = Function(R)
> c.assign(Constant(2.34))
>
> values = numpy.zeros(1, dtype='d')
> vec = c.vector()
>
> # Get value directly from local vector
> vec.get_local(values)
>

Just do

    values = vec.get_local()

Garth

> self.assertEqual(float(values[0]), 2.34)
>
> This gives:
> NotImplementedError: Wrong number or type of arguments for overloaded function 'GenericVector_get_local'.
> Possible C/C++ prototypes are:
> dolfin::GenericVector::get_local(double *,dolfin::uint,dolfin::uint const *) const
> dolfin::GenericVector::get_local(std::vector< double > &) const
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

--
Garth N. Wells
Department of Engineering, University of Cambridge
http://www.eng.cam.ac.uk/~gnw20

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#2

If the global dofs are owned by processor 0, will
  values = vec.get_local()
be safe from all processors? The value here should be the same everywhere.

Revision history for this message
Garth Wells (garth-wells) said :
#3

On Thu, Nov 8, 2012 at 9:50 AM, Martin Sandve Alnæs
<email address hidden> wrote:
> Question #213657 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/213657
>
> Status: Answered => Open
>
> Martin Sandve Alnæs is still having a problem:
> If the global dofs are owned by processor 0, will
> values = vec.get_local()
> be safe from all processors? The value here should be the same everywhere.
>

The call is safe, but only 'values' on process 0 will hold the value
of the global dof.

Garth

> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#4

Thanks, got it right now:

        indices = numpy.zeros(1, dtype='uintc')
        values = vec.gather(indices)
        return float(values[0])

This makes the float(Function(R)) unit tests you disabled work in parallell.