Re: OON: going from sequential to parallel through polymorphism

From: Bruno Haible (haible@ilog.fr)
Date: Mon Sep 28 1998 - 10:54:20 EST


Eric NOULARD <Eric.Noulard@prism.uvsq.fr> writes:
>
> 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.
> ...
> 2) As far as I know this problem is a "multiple dispatch problem".
>
> 3) Does anyone know a OO langage that handles multiple dispatch
> directly? Someone told me about OO Lisp but was unable to
> explain me how it was done.

Yes, it is a classical multiple dispatch problem. All OO Lisps
(CLOS, Eulisp, IsLisp, Talk, Dylan, ...) implement it. Typically used
implementation techniques for a method with signature (class1 class2 class3)
are similar to one of these:

  - Cascaded lookup: You take the class of the first argument, use it as
    index in a table, returning a table. Then you take the class of the
    second argument, use it as lookup index in the returned table. Then
    the third's argument class, when used as an index, finally returns the
    effective method to be executed.

  - Tuple hashing: You take the triple consisting of the three classes of
    the three arguments and use it as an index into a hash table (where
    the hash code is a mix of the hash codes of the three classes).

If your problem is symmetric in all arguments, you can take advantage of
a function `most-specific-common-superclass' defined by:

   Matrix, Matrix -> Matrix
   Matrix, DMatrix -> Matrix
   DMatrix, Matrix -> Matrix
   DMatrix, DMatrix -> DMatrix

then you define the AXPY function like this:

  (defun AXPY (arg1 arg2 arg3)
    (dispatching-AXPY (most-specific-common-superclass arg1 arg2 arg3)
                      arg1 arg2 arg3))

  (defmethod dispatching-AXPY ((class (eql <Matrix>)) arg1 arg2 arg3)
    ; here the code where all arguments are known to be of type Matrix
  )

  (defmethod dispatching-AXPY ((class (eql <DMatrix>)) arg1 arg2 arg3)
    ; here the code where all arguments are known to be of type DMatrix
  )

As you can see, the function `dispatching-AXPY' is dispatching on one argument
only, and therefore suitable for being implemented in C++.

----------------------------------------------------------------------------
Bruno Haible net: <haible@ilog.fr>
ILOG S.A. tel: +33 1 4908 3585
9, rue de Verdun - BP 85 fax: +33 1 4908 3510
94253 Gentilly Cedex url: http://www.ilog.fr/
France url: http://www.ilog.com/



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