Adding a Par construct to Python?

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Fri Jun 5 07:25:51 EDT 2009


In message <77as23F1fhj3uU1 at mid.uni-berlin.de>, 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. My math-skills are a bit too rusty to qualify the exact nature of
> the operation, commutativity springs to my mind.

Associativity:

    ((A op B) op C) = (A op (B op C))

So for example

   A op B op C op D

could be grouped into

  (A op B) op (C op D)

and the two parenthesized subexpressions evaluated concurrently. But this 
would only give you a speedup that was logarithmic in the number of op's.




More information about the Python-list mailing list