I have the following code:

 If[IntegerQ@Sqrt[80892036 + 17994 x (1 + x) (-5995 + 5998 x)], x, 
  Nothing], {x, 6694300, 31072325}]

It uses 6 kernels to compute the result. Is it possible to speed it further up, by for example using more kernels?

  • $\begingroup$ Yes. But that depends (i) on your hardware and (ii) on your Mathematica license. Notice that Mathematica does not use nor count virtual cores, only physical ones. (Hyperthreading is usually pointless for well-written numerical code.) $\endgroup$ – Henrik Schumacher Jan 10 '20 at 10:51
  • $\begingroup$ @HenrikSchumacher what does it depend on for the hardware, I've an intel core i7 8gen and 32 gb of ddr4 ram. And I've the Professional version of Mathematica $\endgroup$ – Jan Jan 10 '20 at 10:57
  • $\begingroup$ So how many cores does the processor have? Maybe 6? $\endgroup$ – Henrik Schumacher Jan 10 '20 at 10:59
  • $\begingroup$ @HenrikSchumacher yes 6 cores and 12 threads $\endgroup$ – Jan Jan 10 '20 at 11:03
  • 1
    $\begingroup$ Please, if you use a brute force search to find solutions, use the fast square root options in this question. For example, results are returned 25 times faster by using sQ from @MichaelE2. $\endgroup$ – KennyColnago Jan 10 '20 at 20:05

You can launch as many subkernels as you want (and as your license allows) using LaunchKernels. Mathematica launches as many as the number of CPU cores by default, but you can specify the exact number you want, and you can launch more.

Using more subkernels than the number of CPU cores you have will typically lead to no performance improvement at all. Sometimes it leads to worse performance. In rare cases, it may be worth doing with a hyperthreading CPU. I strongly recommend you do some benchmarks to verify that you do actually gain performance before launching more subkernels than the number of CPU cores.


Not the answer you're looking for? Browse other questions tagged or ask your own question.