Deprecated function PETScWrappers::VectorBase::ratio()

32 views
Skip to first unread message

Feimi Yu

unread,
May 12, 2018, 12:02:14 AM5/12/18
to deal.II User Group
Hi,

I'm currently using the ratio function for PETSc vectors to compute vector inverse in my parallel code. However, 
it looks like that ratio() is deprecated. I know there is a potential floating point exception due to the
undefined behavior when the denominator vector contains zero (because PETSc's corresponding function does not
check that I guess?). I would like to know if there would be a substitute or new version of this function after it
is completely removed.

Thanks!
Feimi

Bruno Turcksin

unread,
May 14, 2018, 8:47:34 AM5/14/18
to deal.II User Group
Feimi,

There is no substitute for this function. The reason it was deprecated is because we are trying to get a unified minimal interface for all our vector classes. The idea is to make it easy to switch between different vector classes. In the process, we have deprecated functions that were not implemented for all the vector classes. However, I do no expect this particular function to be removed any time soon.

Best,

Bruno

Wolfgang Bangerth

unread,
May 14, 2018, 10:23:12 AM5/14/18
to dea...@googlegroups.com
Feimi,
I don't think there is a replacement function. You will have to write this
operation as a loop over the (locally owned) elements of a vector.

The vector classes have a large interface that has many member functions that
are difficult to implement if one wants to add new vector classes (for example
interfaces to other libraries). A few years ago we went through the existing
interfaces and tries to classify what are the important functions and which
ones could be removed. We then tried to separate functions into those that
provide element access (i.e., that are specific to a particular *basis* for
the vector space) and ones that just represent abstract vector space concepts
like addition, multiplication by a scalar, dot product, etc. The two abstract
base classes that represent this are ReadWriteVector and VectorSpaceVector.

The ratio() function does not fit this pattern. Taking the ratio of two
vectors is not a vector-space operation but instead depends on a particular
basis. On the other hand, it is an operation that is applied to all elements
of a vector at the same time. It is also a rather uncommon operation (your
particular use notwithstanding). So we decided that we should probably just
get rid of it. It is, after all, easy enough to implement by hand.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Feimi Yu

unread,
May 14, 2018, 11:43:49 AM5/14/18
to deal.II User Group
Hi Bruno,

Thanks for the reply! I got the idea. I will try to write my own loop to realize this function.

Thanks!
Feimi

Feimi Yu

unread,
May 14, 2018, 11:52:35 AM5/14/18
to deal.II User Group
Hi Wolfgang,

Thank you for the detailed explanation! Actually what I want to do is to evaluate
the inverse of a lumped diagonal matrix to mimic the matrix inverse. Anyway, I
will write my own loop to avoid using ratio(). Thanks again!

Feimi

Wolfgang Bangerth

unread,
May 14, 2018, 7:47:16 PM5/14/18
to dea...@googlegroups.com
On 05/14/2018 11:52 PM, Feimi Yu wrote:
>
> Thank you for the detailed explanation! Actually what I want to do is to evaluate
> the inverse of a lumped diagonal matrix to mimic the matrix inverse.

I see. Since floating point division is *so much more expensive* than floating
point multiplication, it is probably worth computing the inverse of the
diagonal elements once at the beginning, and then only multiplying (instead of
dividing) by this vector repeatedly. This can be done with the scale()
function, which is not deprecated.

Feimi Yu

unread,
May 15, 2018, 11:47:02 AM5/15/18
to deal.II User Group
Oh, yes. Sorry I did not say it clearly. What I did is using an identity vector whose
elements are all ones and ratio that with the original lumped vector to get the inverse.
Then I use it in the mmult(), which can take a diagonal vector.

Thanks!
Feimi
Reply all
Reply to author
Forward
0 new messages