Here is a simplified example illustrating my issue;
G = GaussianMatrix[{1000, 1000}];
f[] := (
n = RandomInteger[];
n + Total[G, 2]
)
ParallelTable[f[], {2}] (* two kernels *)
During the evaluation one needs two times the memory which is used for Table. The variable G is duplicated for each subkernel although G remains unchanged.
How to avoid that?
Totalcould be computed on the main kernel only once and only the result needs to be transferred. I'm sure that your real problem is not that simple, but can you explain in more detail what sort of computation you are doing and precisely what data it needs? – Szabolcs Feb 12 '15 at 19:18@character, as I'm doing here. Otherwise they don't get notified about the response and may never return to check. – Szabolcs Feb 12 '15 at 19:58SetSharedFunctionon it. This function will always be evaluated on the main kernel. Calling it will be slow. However, you will avoid data duplication. If your algorithm is such that it doesn't spend most of its time in this function, this approach might work without a slowdown that is too significant. ... – Szabolcs Feb 12 '15 at 20:02Compiled functions. It's much more limited but it also has much less overhead. It might be used to parallelize some simple basic steps of the algorithm. – Szabolcs Feb 12 '15 at 20:12