Re: std.parallelism curious results

2014-10-05 Thread flamencofantasy via Digitalmars-d-learn
Thanks everyone for the replies. I wasn't sure how std.parallel operated but I thought it would launch at most a number of threads equal to the number of cores on the machine, just as Ali confirmed and similar to what Windows' thread pool does.

Re: std.parallelism curious results

2014-10-05 Thread Sativa via Digitalmars-d-learn
On Sunday, 5 October 2014 at 21:53:23 UTC, Ali Çehreli wrote: On 10/05/2014 02:40 PM, Sativa wrote: > foreach(i; thds) { ulong s = 0; for(ulong k = 0; k < > iter/numThreads; k++) The for loop condition is executed at every iteration and division is an expensive operation. Apparently, the

Re: std.parallelism curious results

2014-10-05 Thread Ali Çehreli via Digitalmars-d-learn
On 10/05/2014 02:40 PM, Sativa wrote: > foreach(i; thds) { ulong s = 0; for(ulong k = 0; k < > iter/numThreads; k++) The for loop condition is executed at every iteration and division is an expensive operation. Apparently, the compiled does some optimization when the divisor is known at c

Re: std.parallelism curious results

2014-10-05 Thread Sativa via Digitalmars-d-learn
On Sunday, 5 October 2014 at 21:25:39 UTC, Ali Çehreli wrote: import std.stdio, std.cstream, std.parallelism, std.datetime, std.range, core.atomic; void main() { StopWatch sw; shared ulong sum1 = 0; ulong sum2 = 0, sum3 = 0, time1, time2, time3; enum numThreads = 4; // If nu

Re: std.parallelism curious results

2014-10-05 Thread Ali Çehreli via Digitalmars-d-learn
On 10/05/2014 07:27 AM, flamencofantasy wrote: > I am summing up the first 1 billion integers in parallel and in a single > thread and I'm observing some curious results; > > parallel sum : 45, elapsed 102833 ms > single thread sum : 45, elapsed 1667 ms > > The par

Re: std.parallelism curious results

2014-10-05 Thread Sativa via Digitalmars-d-learn
Two problems, one, you should create your threads outside the stop watch, it is not generally a fair comparison in the real world. It throws of the results for short tasks. Second, you are creating one thread per integer, this is bad. Do you really want to create 1B threads when you only have

Re: std.parallelism curious results

2014-10-05 Thread Artem Tarasov via Digitalmars-d-learn
Welcome to the world of multithreading. You have just discovered that atomic operations are performance killers, congratulations on this.

Re: std.parallelism curious results

2014-10-05 Thread Russel Winder via Digitalmars-d-learn
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/10/14 15:27, flamencofantasy via Digitalmars-d-learn wrote: > Hello, > > I am summing up the first 1 billion integers in parallel and in a > single thread and I'm observing some curious results; I am fairly certain that your use of "parallel fo

std.parallelism curious results

2014-10-05 Thread flamencofantasy via Digitalmars-d-learn
Hello, I am summing up the first 1 billion integers in parallel and in a single thread and I'm observing some curious results; parallel sum : 45, elapsed 102833 ms single thread sum : 45, elapsed 1667 ms The parallel version is 60+ times slower on my i7-3770K C