Message Boards Message Boards

0
|
1370 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

ParallelEvualate using very little CPU time.

Posted 11 months ago

I want to test if for any prime n > 3, that (n+1)(n-1) is not divisible by 24. I want it to execute it on all cores. I have this code, which is virtually the same as one of the examples in the documentation,

https://reference.wolfram.com/language/ref/ParallelEvaluate.html

under "Neat Examples" which checks if n! + 1 is prime.

Whilst Mathematics is launching multiple kernels, the "top" command on linux shows one of them is using about 75% of the CPU time, and the others about 1%. All kernels except one run for 8 to 10 seconds. The top command on this machine is configured such that percentages are based on the individual cores, not the sum of all cores, so the sum of the CPU times should far exceed 100%.

ParallelEvaluate[$RecursionLimit = 500]

n = 1; primes = {}; SetSharedVariable[n, primes];
PrintTemporary[Dynamic[{n, primes}]];
CheckAbort[
 ParallelEvaluate[While[True,
   With[{n = n++},   
    If[Mod[(Prime[n] + 1) (Prime[n] - 1), 24] != 0        , 
     AppendTo[primes, n]]]]],
 {n, primes}]

Here's the output from top. The load average of the computer is 1.55, which is pretty low. A serial version of the code would run faster. Can anyone suggest a better way to do this, which will make more use of multiple cores?

top - 00:02:11 up  9:49,  1 user,  load average: 1.55, 1.48, 1.78
Tasks: 717 total,   4 running, 713 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.7 us,  0.5 sy,  0.0 ni, 96.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem : 385596.8 total, 372310.2 free,   8849.1 used,   4437.5 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used. 374307.1 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                             
  40619 drkirkby  20   0 5541304 172432  72212 R  66.3   0.0   3:28.18 WolframKernel                                                       
  15761 drkirkby  20   0 4811860 904880 225976 S  17.9   0.2  21:24.35 firefox                                                             
  31080 drkirkby  20   0 3942452 261308 132848 S  15.2   0.1   3:16.16 Mathematica                                                         
  38667 drkirkby  20   0 2552824 228688 107152 S  12.1   0.1   0:51.26 Isolated Web Co                                                     
   2481 drkirkby  20   0 4573500 450416 127528 S   7.2   0.1   8:38.70 gnome-shell                                                         
   2129 root      20   0   24.2g 118088  70232 R   3.7   0.0   5:45.92 Xorg                                                                
   2171 root     -51   0       0      0      0 S   2.6   0.0   2:15.89 irq/165-nvidia                                                      
   2113 drkirkby   9 -11 2908504  20416  15792 S   1.4   0.0   8:05.07 pulseaudio                                                          
  41350 drkirkby  20   0 1082404 136948  58796 S   1.0   0.0   0:04.14 WolframKernel                                                       
  40686 drkirkby  20   0 1082404 136548  58396 S   0.9   0.0   0:04.38 WolframKernel                                                       
  40687 drkirkby  20   0 1307832 159464  65268 S   0.9   0.0   0:06.14 WolframKernel                                                       
  40709 drkirkby  20   0 1082400 136612  58460 S   0.9   0.0   0:04.24 WolframKernel
POSTED BY: David Kirkby
Posted 10 months ago

Has nobody got any thoughts on this?

POSTED BY: David Kirkby
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract