I've been using Mathematica for awhile now and have never come even close to maxing out my CPU cycles. Are there any functions which consume lots of CPU cycles? Right now I am running a script which uses Parallelize and is consuming about 15%.

Also, a related question -- is there any way to get Mathematica to use more CPUs? It'd be nice to get to my answers faster.

  • 1
    $\begingroup$ n = 100; While[True, MatrixPower[RandomReal[1, {#, #}], #] &[++n]] maxes my CPU out pretty quickly. $\endgroup$ – Corey Kelly Jun 26 '13 at 18:25
  • 1
    $\begingroup$ n = 10000; A = RandomReal[1, {n, n}]; While[True, A.A]; $\endgroup$ – Eric Brown Jun 26 '13 at 19:10
  • 1
    $\begingroup$ …but something tells me you are looking for saturation with a function that is called via the "Parallel" statement. $\endgroup$ – Eric Brown Jun 26 '13 at 19:11
  • $\begingroup$ @EricBrown the highest load will almost certainly come from your suggestion of repeated multiplication of large matrices. Depending on how well the matrix-matrix multiply is optimized, the matrix size may need to be adjusted to fit into cache for optimum results. $\endgroup$ – Oleksandr R. Jun 26 '13 at 19:22
  • $\begingroup$ @OleksandrR. Interesting you say that: on my Macbook Air (i7) the matrix multiply only uses two cores ("processors") whereas the Parallel operations, shown in my answer, get four (hyper threading?) $\endgroup$ – Eric Brown Jun 26 '13 at 19:25

An example comes from the documentation:

localsol=Quiet@NDSolve[{D[u[t,x,y], t, t] == D[u[t,x,y], x,x] + D[u[t, x, y], y, y] + 
Sin[u[t,x,y]], u[t,-L, y] == u[t, L, y], u[t, x, -L] == u[t, x, L], 
u[0,x, y] == a Exp[-(b x^2 + y^2)], Derivative[1,0,0][u][0,x,y] == 0}, 
u, {t,0,L/2}, {x,-L,L},{y,-L,L}]; 

Plot3D[Evaluate[u[L/2, x, y] /. First[localsol]]
, {x,-L,L},{y,-L,L}
, PlotRange-> {{-L,L},{-L,L}, {-dz, dz}}
, {a, -0.5, 0.5, 0.2},{b,0.8,1.2,.1},Method->"FinestGrained"]

You can play with values of the step sizes of a and b, until you can fry an egg on your computer.

  • $\begingroup$ Thanks for the script! This used ~50% of my 4 cores. I suppose that's because they are multi-threaded cores so I can have 8 threads going and Mathematica is using only 4 of them. $\endgroup$ – lynvie Jun 26 '13 at 20:06
  • 1
    $\begingroup$ @lynvie my pleasure. Sounds reasonable, it's possible that it is cores instead of hyperthreading, but it is also possible that a) your license restricts you to 4 cores and/or b) you have the number of cores manually hard-wired in your Parallel Preferences. $\endgroup$ – Eric Brown Jun 26 '13 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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