after I got such a great response for my first question on this site, I'm very encouraged to asked my second one!
So here it is, very generally: To speed up a "row-wise" (i.e. 1D) operation on a matrix, I tried to use the ParallelTable instead of the Table function. I don't know why, but due to some reason this fails. It seems that the expression inside the ParallelTable gets not evaluated correctly. Maybe somebody knows why?
I start with my functions: The "FftShift1D" is simply to reorder the result of the Fourier function. The "eqn" function is just an arbitrary function to test the parallelization later on.
ClearAll["Global`*"] FftShift1D[x_?VectorQ] := Module[{n = Ceiling[Length[x]/2]}, RotateRight[x, n]] eqn[kx_?MachineNumberQ, y_?MachineNumberQ] := 2/3 Exp[-I kx] (1 + I kx) + Sin[y]/y Now, I create a matrix with the help of the "Table" function. The following definitions are used to change the size of the matrix easily.
kxmin = -100; kxmax = 100; kxdiv = 2000; kxinc = (kxmax - kxmin)/(kxdiv - 1); zmin = -5; zmax = 5; zdiv = 200; zinc = (zmax - zmin)/(zdiv - 1); kspace = Table[ eqn[kx, z], {kx, kxmin, kxmax, kxinc}, {z, zmin, zmax, zinc}]; So I want to apply a FFT only on the "kx" direction, i.e. there are "zdiv" times a 1D FFT. This is how I've done this "serially":
res = Table[ FftShift1D[Fourier[N[ kspace[[;; kxdiv, i]] ]]], {i, 1, zdiv}]; This works properly, and it results in "res" being a matrix (or Table, however you like to call it) with the same size as "kspace". Changing now to
SetSharedVariable[kxmin, kxmax, kxdiv, kxinc, zmin, zmax, zdiv, zinc, kspace, res]; res = ParallelTable[ FftShift1D[Fourier[N[ kspace[[;; kxdiv, i]] ]]], {i, 1, zdiv}]; fails with the following messages:
Fourier::fftl: Argument {eqn[-100.,-5.],eqn[-99.8999,-5.], eqn[-99.7999,-5.],<<6>>,eqn[-99.0995,-5.],<<1990>>} is not a nonempty list or rectangular array of numeric quantities. You see, that although I call "N", the "eqn" gets not evaluated properly... Does someone knows why? Kind regards Clemens
PS: I've found something not completely unlike my problem here, but not as in ParallelTable and Table do not give same result my problem does not change when using Parellelize[Table[...]] instead of ParellelTable[...]
DistributeDefinitionsas used in my answer the code apparently never finishes. Does it work on your machine? $\endgroup$ParallelTable[FftShift1D[Fourier[N[kspace[[;; 10, i]]]]], {i, 1, 2}](ie, decrease the limits) it does work properly (ie gives same asTable). This on 9.0.1. If Clemens still has not worked out what is going on, I'll give it a shot later today (I need to do something first). Would be nice to have a minimal example by the way. $\endgroup$Parallel`package for this sinceFourieris already multithreaded via the MKL. Please see also this question, which perhaps is not the most clearly titled. $\endgroup$