From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0B775BC8C for ; Wed, 9 Feb 2005 12:19:18 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j19BJHR5013538 for ; Wed, 9 Feb 2005 12:19:17 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA28765 for ; Wed, 9 Feb 2005 12:19:17 +0100 (MET) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.194]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j19BJGIm029720 for ; Wed, 9 Feb 2005 12:19:16 +0100 Received: by rproxy.gmail.com with SMTP id i8so1237337rne for ; Wed, 09 Feb 2005 03:19:15 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=heojCnLXi9JHLEznAgvjsolEOD0qLsfzHuxDthc7dgZSrNuiQ1yObham79yH/8x86vul1HaVYnU4wCtNN3yxUhkFAX+KiKYyOp1GkD2EYQGkFKGS7HfyGY6vONHig9R1/a86w/+/L+z5EBn5+hy96xQ5hhdqyqiKouqTrntWMGE= Received: by 10.38.164.36 with SMTP id m36mr250757rne; Wed, 09 Feb 2005 03:19:15 -0800 (PST) Received: by 10.38.65.58 with HTTP; Wed, 9 Feb 2005 03:19:15 -0800 (PST) Message-ID: <7f8e92aa05020903191f26af4e@mail.gmail.com> Date: Wed, 9 Feb 2005 13:19:15 +0200 From: Radu Grigore Reply-To: Radu Grigore To: skaller@users.sourceforge.net Subject: Re: [Caml-list] Re: paralell assignment problem Cc: Stefan Monnier , caml-list In-Reply-To: <7f8e92aa050209014322b561e@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <1107832025.13571.260.camel@pelican.wigram> <87y8dzi0ns.fsf-monnier+gmane.comp.lang.caml.inria@gnu.org> <1107882489.5022.175.camel@pelican.wigram> <7f8e92aa05020810335ab052e0@mail.gmail.com> <7f8e92aa050209014322b561e@mail.gmail.com> X-Miltered: at concorde with ID 4209F1B5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4209F1B4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 computed:01 sub-optimal:01 wrote:01 ...:98 expression:01 algorithm:01 algorithm:01 expressions:03 approaches:03 problem:05 problem:05 radu:05 radu:05 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On Wed, 9 Feb 2005 11:43:34 +0200, Radu Grigore wrote: > 1. hold the original value of a variable > 2. hold the result of an expression and write it later to the destination > > Point (1) requires one extra assignment, while point (2) requires two > extra assignments. The effect is however the same: one of the > variable's value can be computed as soon as desired. Therefore we will > only use (1). [NOTE that your approach used (2) and hence is clearly > sub-optimal]. One more mistake. Both approaches introduce _one_ extra assignment and the algorithm described subsequently is independent on the choice of (1) or (2). For the problem: a = b+c b = c c = a+b The algorithm says: introduce a temporary for c, and the order is c, a, b. With choice (1) the solution is the one I already wrote. With choice (2) it is: // compute temporaries t = a+b // compute c, a, b (skip c because we have temporary, this is what I missed) a = b+c b = c // use temporaries c = t ... for a total of 4 assignments (same as with choice 1). This is better than the 5 assignments given by your algorithm and it does NOT depend on breaking the rule about using temporaries only to save results of expressions (but not initial values). -- regards, radu http://rgrig.idilis.ro/