In general, can Mathematica automatically (i.e. without writing code specifically for this) exploit GPU hardware and/or parallelize built-in operations across multiple cores?
For example, for drawing a single very CPU-intensive plot or solving a very CPU-intensive equation, would upgrading the graphics hardware result in speed-up? Would upgrading to a CPU with more cores speed things up? (I realize that more cores mean I could solve more equations in parallel but I’m curious about the single-equation case)
Just trying to get a handle on how Mathematica exploits hardware.
I wouldn’t say Mathematica does automatically GPU or Paralell-CPU computing, at least in general. Since you need do something with paralell kernels, then you should initialize more kernels and/or upload CUDALink or OpenCLLink and use specific Mathematica functionality to exploit the potential of CPU and/or GPU.
For example, I haven’t got very powerful graphics card (NVIDIA GeForce 9400 GT) but we can test how CUDALink works. First I have to upload
CUDALink:I am going to test multiplication of large matrices. I choose a random matrix
5000 x 5000of real numbers in range(-1,1):M = RandomReal[{-1,1}, {5000, 5000}];Now we can check the computing times without GPU support
and with GPU support
In this case we obtained a performance speed-up roughly of factor 4, by using CUDADot instead of Dot.
Edit
To add an example of parallel CPU acceleration (on a dual-core machine) I choose all prime numbers in range
[2^300, 2^300 +10^6].First without parallelizing :
while using
Parallelize[expr], which evaluates expr using automatic parallelizationAs one could expect we’ve got almost two times faster evaluation.