Adding a Par construct to Python?

Albert van der Horst albert at spenarnc.xs4all.nl
Wed May 27 08:58:02 EDT 2009


In article <02204669$0$25303$c3e8da3 at news.astraweb.com>,
Steven D'Aprano  <steve at REMOVE-THIS-cybersource.com.au> wrote:
>On Sun, 17 May 2009 18:24:34 +0200, Diez B. Roggisch wrote:
>
>>> But reduce()? I can't see how you can parallelize reduce(). By its
>>> nature, it has to run sequentially: it can't operate on the nth item
>>> until it is operated on the (n-1)th item.
>>
>> That depends on the operation in question. Addition for example would
>> work.
>
>You'd think so, but you'd be wrong. You can't assume addition is always
>commutative.
>
>>>> reduce(operator.add, (1.0, 1e57, -1e57))
>0.0
>>>> reduce(operator.add, (1e57, -1e57, 1.0))
>1.0
>
>
>
>> My math-skills are a bit too rusty to qualify the exact nature of
>> the operation, commutativity springs to my mind.
>
>And how is reduce() supposed to know whether or not some arbitrary
>function is commutative?

Why would it or need it? A Python that understands the ``par''
keyword is supposed to know it can play some tricks with
optimizing reduce() if the specific function is commutative.

>--
>Steven

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list