# Function or script which maxes out the CPUs?

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.

-
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

An example comes from the documentation:

With[{L=4,dz=0.25},
sols=ParallelTable[
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}}
,Axes->None,PlotLabel->{a,b}]
, {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.

-
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