3 ms·
At the section "What about per-thread count arrays?" he uses the omp_get_num_threads() to allocate "per thread" array, but as far as I see he's still not in the
by acqq 15y ago
At the section "What about per-thread count arrays?" he uses the omp_get_num_threads() to allocate "per thread" array, but as far as I see he's still not in the parallel region, the num threads can as well be 1 there.
Author also writes: "This is likely the cost of starting N=110885 different worker threads in Python." As far as I understand, he has only 4 hard coded threads (that they are they hard coded doesn't have sense too).
Finally I don't see why he should get only speedup of two with four cores, he certainly doesn't explain it. EDIT 1: I believe commenter onemoreact found the reason: the compiler probably assumes that all loop passes take around the same time, but the author managed to make longest loop last N times longer than the shortest.
- dalke 15y agoGood catch acqq! I wrote the code for that essay first, copied it in my working algorithm (which is a bit more complicated than what wrote here), and after a few segfaults and other problems, got it working there by just using the max thread count. However, that fix didn't make it back to the essay. I've updated the essay code, with commentary about the problem. Thank you for pointing it out. I've updated the test so it says "starting N=110885 different jobs for the worker threads". Also, I never reported the speedup of one core vs. four cores. What I reported was the speedup from computing across the NxN matrix vs. using symmetry and only computing the N*(N-1)/2 similarities. That's the factor of two time. Raw data computed yesterday, for a threshold of 0.80 (and a slightly different problem), on an 8 core machine, using from 1 to 8 cores, is: OpenMP pthreads cores time scaleup time scaleup 1 0:02:00 1.0 0:02:01 0.99 2 0:01:06 1.8 0:01:06 1.8 3 0:00:44 2.7 0:00:44 2.7 4 0:00:32 3.75 0:00:33 3.6 5 0:00:27 4.4 0:00:28 4.3 6 0:00:23 5.2 0:00:23 5.2 7 0:00:20 6.0 0:00:20 6.0 8 0:00:26 4.6 0:00:19 6.3 This is a rented Amazon node, and I consistently found that 8 nodes using OpenMP gave poor results, so I suspect I didn't have access to 8 cores. This benchmark also doesn't have the randomization which confused my previous benchmark run, so you can see that the two threading systems gave essentially identical timings. Looks like I'll need to update a previous essay.