caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: paralell assignment problem
Date: 09 Feb 2005 04:08:10 +1100	[thread overview]
Message-ID: <1107882489.5022.175.camel@pelican.wigram> (raw)
In-Reply-To: <87y8dzi0ns.fsf-monnier+gmane.comp.lang.caml.inria@gnu.org>

On Wed, 2005-02-09 at 01:34, Stefan Monnier wrote:
> > Does anyone know how to solve the parallel assignment problem?
> > Name invented by me to describe this problem:
> 
> > x1,x2,x3..xn = e1,e2,e3 .. en
> 
> > where ei might contain the variables xj. (Note = here is assignment).
> 
> > The solution is a sequence of assignments involving
> > only xi, ei, and ti, where ti are temporaries introduced
> > to save the values of the expressions. For example,

Here's the algorithm I have implemented, I believe it works,
but I'm not sure it finds the minimal solution. The main
difficulty is in step 5.

1. Strip out equations of the form xi = xi since
   they don't do anything.

2. Create 3 lists: head, middle, and tail.

3. For each assignment in the working set:

  if the RHS does not depend on a variable in the working set, 
    prepend it to the tail
  else if no RHS in the working set depends on the LHS
    variable, prepend it to the head
  else add it to the middle

4. If we moved any assignment to the head or tail list,
   set the working set to the middle, and go back to step 3

5. The middle now has the property that for any assignment,
   there is at least one other assignent such that the RHS
   of one whch depends on the LHS variable of the other.

   So pick one assignment x = e out of the middle, 
   create a temporary variable t, prepend t = e
   to the head list and x = t to the tail list,
   set the working set to the remaining assignments
   of the middle. 

   If the working set is empty, the result is the reversed
   head list concatenated with the tail, otherwise
   go back to step 3


This algorithm (a) finds an equivalent set of serial assignments,
and (b) it is clearly locally minimal in the sense that
whenever it introduces a temporary in step 5,
there was no alternative but to do so.

However it isn't clear (to me) that just picking an arbitrary
assignment to split into two using a temporary
actually minimises the number of temporaries.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




  parent reply	other threads:[~2005-02-08 17:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-08  3:07 skaller
2005-02-08 14:34 ` Stefan Monnier
2005-02-08 16:02   ` [Caml-list] " skaller
2005-02-08 18:20     ` Stefan Monnier
2005-02-08 17:08   ` skaller [this message]
2005-02-08 18:33     ` Radu Grigore
2005-02-09  7:48       ` Radu Grigore
2005-02-09 10:11         ` skaller
2005-02-09  9:43       ` Radu Grigore
2005-02-09 11:19         ` Radu Grigore
2005-02-09 11:34         ` Pascal Zimmer
2005-02-09 13:53           ` skaller
2005-02-08 16:03 ` [Caml-list] " Florian Hars
2005-02-08 17:38   ` skaller
2005-02-08 16:29 ` Marcin 'Qrczak' Kowalczyk
2005-02-08 17:55   ` skaller
2005-02-08 18:32     ` Marcin 'Qrczak' Kowalczyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1107882489.5022.175.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).