Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am running the code below, and it works perfectly. I have some function in Fourier space, and I take the numerical InverseFourierTransform. However, I will have to repeat this calculation often, and therefore I want to use ParallelTable. I've tried this, by replacing Table in the code below by ParallelTable. I am running the code on a computer with 8 kernels. Surprisingly, using ParallelTable doesn't speed up the calculation. I simply find almost the same computation time (not roughly a factor 8 difference)!

Can anybody explain to me what the reason for this is? I've tested the ParallelTable with commands like

  ParallelTable[Pause[1]; f[i], {i, 4}] // AbsoluteTiming

and for this case it works fine, but not for the NInverseFourierTransform.

ClearAll["Global`*"];
f[q_] := Sqrt[2/Pi]*(-Sinc[q] + Cos[q]);
k[q_] := Sqrt[Pi/2]/Abs[q];
a = 10^-2;
b = 10^-2;
Needs["FourierSeries`"]
hfourierdomain[ω_] = a*f[ω]*k[ω]/(1 + b*ω^2*k[ω]);
displ = Table[{j, NInverseFourierTransform[hfourierdomain[ω], ω, j]}, {j, -5, 5, 1/60}];
share|improve this question
    
If you have a recent NVidia Graphics Card, you may use CUDAFourier which is much faster and easy to install/use. (May be there's nothing to install, I can't remember) –  andre Jan 28 '13 at 20:47
    
@andre I think NInverseFourierTransform relies on NIntegrate internally, not on Fourier. It works on a numerical black-box function, not on a list of numbers. So CUDAFourier might not be useful here (it is of course a good replacement for Fourier) –  Szabolcs Jan 28 '13 at 20:51
    
@Szabolcs Agree. I have Fourier[] and FourierTransform[] mixed up. –  andre Jan 28 '13 at 21:05
1  
Use ParallelNeeds[] for this. –  Daniel Lichtblau Jan 28 '13 at 22:10
add comment

1 Answer 1

up vote 2 down vote accepted

When I run your code on my machine with Table (not ParallelTable), I see that all the cores of the CPU are used by a single MathKernel process. This means that internally NInverseFourierTransform uses an operation that is already parallelized. Certain operations, such as LinearSolve, will be able to use all cores of your CPU even when run on a single kernel.

Because of this the Table version is likely already as efficient as it can be, and splitting the task into several parts and distributing it among kernels (which will individually all want to use all your CPU cores) is likely to just reduce performance.

P.S. If your CPU has 4 cores and supports hyperthreading (e.g. many i7 processors), your OS will show 8 cores in total out of which 4 are working.

share|improve this answer
    
Ok, thanks a lot for this helpful information! This also explains to me why parallelization for some expressions does speed up the calculations, and why it never wanted to work for NInverseFourierTransform. I am running the code on some cluster that has (I am not sure) 4 CPU's. –  user5613 Jan 28 '13 at 20:59
    
@user5613 If you are running the code on a cluster and you are able to launch Mathematica kernels on more than one machine, then ParallelTable should be useful. Just make sure you launch a single subkernel per machine. How to do this well on various types of clusters is a good question on its own ... –  Szabolcs Jan 28 '13 at 21:03
    
@user5613 Also, sometimes parallelization doesn't speed up much computations because the problem is not broken into appropriately sized chunks. In this case manually tuning the Method option of Parallelize may help (but this doesn't apply to your particular problem). I couldn't get Outer to speed up the other day ... (with Parallelize --- there's no ParallelOuter, but Parallelize does work with Outer) –  Szabolcs Jan 28 '13 at 21:06
    
Hi Szabolcs, I will check tomorrow if I can maybe run Mathematica on more than one machine.. Either case, initially I thought this problem would be ideally to parallize as you don't need any information from 'previous calculations' in this loop. Thanks a lot! –  user5613 Jan 28 '13 at 21:13
add comment

Your Answer

 
discard

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.