Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
n = 100; While[True, MatrixPower[RandomReal[1, {#, #}], #] &[++n]] maxes my CPU out pretty quickly. – Corey Kelly Jun 26 '13 at 18:25
n = 10000; A = RandomReal[1, {n, n}]; While[True, A.A]; – Eric Brown Jun 26 '13 at 19:10
…but something tells me you are looking for saturation with a function that is called via the "Parallel" statement. – Eric Brown Jun 26 '13 at 19:11
@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. – Oleksandr R. Jun 26 '13 at 19:22
@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?) – Eric Brown Jun 26 '13 at 19:25
up vote 3 down vote accepted

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.

share|improve this answer
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. – lynvie Jun 26 '13 at 20:06
@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. – Eric Brown Jun 26 '13 at 20:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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