Computers are getting faster, that's for sure. However, they are also getting more cores: new laptops thesedays are dual-core and servers are four-or-more-core. Cores are a fancy word for something a bit like another processor. I happen to have lots of things I want to process independently, but if I only use a single process I'll only use one core, a quarter of those available on my server. That's wasting CPU power. The solution is to do more than one thing at a time and common solutions for this are threading and forking. I've found a particularly neat solution which is a very nice idiom too: parallel foreach with Proc::ParallelLoop Something along the lines of the following, which will parallelise the loop by forking 4 workers at a time:
pareach \@todo, \&generate, { Max_Workers => 4 };
The nice thing is that Linux balances each long-lived process on a core, and suddenly my program runs about four time faster! (Okay, so cores aren't complete CPUs - they tend to have dismal floating point performance - but all I am doing are integer calculations so it is mostly the same in my case).
There are many modules on the CPAN which do something similar, but I particularly like the fact that this is a cute idiom: exactly like a foreach, but slightly parallelised. Neat!
See you at the London.pm social meeting tonight!
Multiple Cores and Floating Point Parallel-Each (Score:1)
That may depend upon brand and architecture. But really, Parallel-Each dispatch of floating point operations would be the wrong way, multi-core or single-core SMP.
* [sun.com], ** [theregister.co.uk].
Prior USiii dual-core models had 1 FPU per Core, but it wasn't safe to max them. *** [sun.com].
2xFPU/core = 8 FPUs in the 2 socket, 4 core G5 * [apple.com], ** [ibm.com]
Bill
# I had a sig when sigs were cool
use Sig;
Do Perl 6 Junctions do this anyway? (Score:1)
Bill
# I had a sig when sigs were cool
use Sig;