Re: OON: going from sequential to parallel through polymorphism

From: Alan B. Williams (william@ca.sandia.gov)
Date: Mon Sep 28 1998 - 12:54:06 EST


At 04:46 PM 9/28/98 +0200, Eric NOULARD wrote:
...
>
> A trouble comes to bring parallelism through inheritance
>and polymorphism.
>
>Let's say our developper has built a class:
>
> Itmethod(Matrix* A, Matrix* X, Matrix* Y)
>
>whose method:
>
> Itmethod::compute()
>
> {
> Y -> axpy(A,X);
> }
>
>uses the Matrix method:
>
> Matrix::apxy(Matrix* A, Matrix* Y)
>which computes the AXPY operation Y = A*X +Y.
>
>If we derive a distributed matrix class DMatrix from Matrix
>and we pass it to Itmethod, polymorphism will takes place
>for the call to axpy(...) on Y in method Itmethod::compute()
>but we won't be able to overload this method correctly since
>A and X has been upcasted into Matrix* in Itmethod.
>In fact we wanted to overload:
>
> Matrix::apxy(Matrix* A, Matrix* Y)
>in
> DMatrix::axpy(DMatrix* A, DMatrix* Y)
>
>which is not a proper overload.
>

The answer is to do something like this:

DMatrix::axpy(Matrix* A, Matrix* Y)

Which will work fine if your base Matrix class has some data
access functionality, but gets a little more complicated otherwise.
i.e., in the execution of the parallel axpy, you will need to
retrieve data from A and Y. In the ISIS++ linear solver library
(http://z.ca.sandia.gov/isis), the iterative linear solvers accept
base-class arguments (in C++) Matrix &A, Vector &x, Vector &b,
which at run-time may be parallel implementations.
All the solver needs is something like:

   A.vectorMultiply(p, q); //p and q are Vectors

In our case the arguments are vectors, for which data access is
a lot simpler than for matrices. Putting data access in a Matrix
base class is a bad idea.

What you could do instead is add a query function to your Matrix
class so that inside the axpy function you query A and Y to see if
they are the same type (or some compatible type) as 'this' and if
so, they return a pointer to the derived-class interface that supports
the DMatrix data access functions. If at run-time they are not
compatible instantiations, then you're in trouble anyway, because
your parallel axpy is going to be a nightmare.

Alan



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:06 EST