Instantiation problem for Utilities::MPI::sum (const ArrayView< const T > &values, const MPI_Comm &mpi_communicator, const ArrayView< T > &sums)

20 views
Skip to first unread message

Feimi Yu

unread,
Jan 27, 2020, 1:42:18 PM1/27/20
to deal.II User Group
Hi,

I was trying to use the the function Utilities::MPI::sum (const ArrayView< const T > &values, const MPI_Comm &mpi_communicator, const ArrayView< T > &sums)
for an std::vector<int>. I created an ArrayView<int> to pack the vector and passed it into this function. However, the compiler keeps telling me:

undefined reference to 'void dealii::Utilities::MPI::sum<dealii::ArrayView<int>, dealii::ArrayView<int> >(dealii::ArrayView<int> const&, ompi_communicator_t* const&, dealii::ArrayView<int>&)'

I checked base/mpi.inst.in and cmake/config/template-arguments.in. Int type should be included in the instantiation list, but I could not figure out why this does not work for me.

Thanks!
Feimi

Jean-Paul Pelteret

unread,
Jan 28, 2020, 1:53:35 AM1/28/20
to dea...@googlegroups.com
Dear Feimi,

On first glance, it looks like the object you send in as the first argument to this function has the wrong type. The function expects an ArrayView< const int >, but you are passing it an ArrayView< int >. That’s the first thing that I spotted, but hopefully its just this that’s an issue for you.

I hope that this helps.
Best,
Jean-Paul

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/9763685b-f159-4689-a913-dced4c642dc1%40googlegroups.com.

Feimi Yu

unread,
Jan 28, 2020, 11:23:39 AM1/28/20
to deal.II User Group
Hi Jean-Paul,

Thanks for your reply!

Yes, I did try passing an ArrayView<const int>, with no luck. I was told the same undefined reference thing.

Feimi

On Tuesday, January 28, 2020 at 1:53:35 AM UTC-5, Jean-Paul Pelteret wrote:
Dear Feimi,

On first glance, it looks like the object you send in as the first argument to this function has the wrong type. The function expects an ArrayView< const int >, but you are passing it an ArrayView< int >. That’s the first thing that I spotted, but hopefully its just this that’s an issue for you.

I hope that this helps.
Best,
Jean-Paul
On 27 Jan 2020, at 19:42, Feimi Yu <yuf...@gmail.com> wrote:

Hi,

I was trying to use the the function Utilities::MPI::sum (const ArrayView< const T > &values, const MPI_Comm &mpi_communicator, const ArrayView< T > &sums)
for an std::vector<int>. I created an ArrayView<int> to pack the vector and passed it into this function. However, the compiler keeps telling me:

undefined reference to 'void dealii::Utilities::MPI::sum<dealii::ArrayView<int>, dealii::ArrayView<int> >(dealii::ArrayView<int> const&, ompi_communicator_t* const&, dealii::ArrayView<int>&)'

I checked base/mpi.inst.in and cmake/config/template-arguments.in. Int type should be included in the instantiation list, but I could not figure out why this does not work for me.

Thanks!
Feimi


--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dea...@googlegroups.com.

Feimi Yu

unread,
Jan 28, 2020, 11:40:03 AM1/28/20
to deal.II User Group
I uploaded a minimal code to reproduce the problem I encountered.

Thanks!
Feimi
arrayview_sum.cpp

Bruno Turcksin

unread,
Jan 28, 2020, 12:09:38 PM1/28/20
to deal.II User Group
Feimi,

You need to have two different ArrayView. It won't work with a single ArrayView. The input one (values) need to be an ArrayView<const int> and the output one (sum) an ArrayView<int>.

Best,

Bruno

Feimi Yu

unread,
Jan 28, 2020, 12:57:15 PM1/28/20
to deal.II User Group
Hi Bruno,

Thanks for your reply!
That's not true. The input and output arrays may be the same as described in the documentation. The template instatiation error does not check whether they are the same, either.
In addition, two different arrays give the same error.

Feimi

Daniel Arndt

unread,
Jan 28, 2020, 1:43:57 PM1/28/20
to dea...@googlegroups.com
Feimi,

it's picking the wrong overload.

Utilities::MPI::sum(local_vector, mpi_communicator, local_vector);

works as well as

Utilities::MPI::sum<int>(my_view, mpi_communicator, my_view);

Best,
Daniel



--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/e35102aa-3f62-4371-8cb6-474ea4c5fd69%40googlegroups.com.

Feimi Yu

unread,
Jan 28, 2020, 2:19:36 PM1/28/20
to deal.II User Group
Hi Daniel,

Thanks for the solution!

From my understanding, it's picking

template<typename T, typename U>
void sum(const T &values, const MPI_Comm &mpi_communicator, U &sums)

instead of

template<typename T>
void sum(const ArrayView<const T> &values, const MPI_Comm & mpi_communicator, const ArrayView<T> & sums)

And that's why it is complaining that "<ArrayView<int const>, ArrayView<int>>" is not instantiated for the first one. Am I correct?
Now I understand that directly passing the vector works. And to have the second one working, I need to explicitly tell the compiler which one to use, like:

Utilities::MPI::sum<int>(my_view, mpi_communicator, my_view);

Just tested with that and it compiled & ran normally.

Thanks!
Feimi
To unsubscribe from this group and stop receiving emails from it, send an email to dea...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages