Re: Parallel example for computing pi efficiently is actually slow
Did you mis-read the top comment of the parallel version? > # Compute PI in an **inefficient** way .
Re: Parallel example for computing pi efficiently is actually slow
Even the first line of the parallel version says "# Compute PI in an inefficient way". It doesn't really make it faster, it just shows how parallel/spawn can be used
Re: Parallel example for computing pi efficiently is actually slow
Argh. Looks like I wanted to read this differently
Re: Parallel example for computing pi efficiently is actually slow
Maybe try **Weave**. [https://github.com/mratsim/weave](https://github.com/mratsim/weave)
Re: Parallel example for computing pi efficiently is actually slow
It uses threads to do very little amount of work: 4 * math.pow(-1, k) / (2*k + 1) ... creating a thread is a very heavy weight operation, while doing little math is really easy. So most of the time is spent doing thread bookkeeping. Your computation needs to justify running it in a thread ... which this does not as its just an example for parallel not an efficient implementation.
Re: Parallel example for computing pi efficiently is actually slow
The example is very bad... If you wanna make manythreaded apps - you should consider following facts: 1. At low level - threads(and processes) are OS objects and they are governed by OS (so called "parallel abilites" of any programmin' language is just a sugar above them) 2. Threads and processes are limited resources and there is overhead as much 1-4 mb per process (and ~100kb per thread) 3. It takes some time to create thread and switch between them .. as ~3 processor tacts for creation a thread, and ~2000-3000 tacts for switchin' between 4. Typecally the number of threads for numerical caculations should not exceed the number of workers (cores) your computional system
Re: Parallel example for computing pi efficiently is actually slow
Yeah I didn't think about this carefully. Thanks for all your replies