I have found the same question
Avoid copying memory for each subkernel
However, there was no proper answer. This question was posted in 2015. Now it has been 6 years. So, I wish to find the solution to this problem in Mathematica.
Now I am performing calculations using the command ParallelTable. Sort of the code is as follows.
<<Analytic_H.txt;
B1 = 210;
Do[Ham[p2, p1] = Ham[p1, p2], {p1, 1, B1}, {p2, p1, B1}];
T = Table[Ham[p1, p2], {p1, 1, B1}, {p2, 1, B1}];
AA = T;
HH = ParallelTable[AA; {Min[Eigenvalues[SetPrecision[AA, 15]]], a1, a2, a3}, {a1, 2.6, 3.1, 0.1}, {a2, 4.8, 5.8, 0.2}, {a3, 4.0, 4.4, 0.1}];
As can be seen in the above code, data file "Analytic_H.txt" is loaded first. At this stage, the memory use is about 20 GB. The problem arises when performing ParallelTable part.
Performing ParallelTable, the subkernels are automatically opened and duplicating the data begins in each subkernel. So, if there are 5 subkernels open, then the total memory usage becomes 5 times the memory used in the master kernel (i.e., 5*20 GB = 100 GB).
I wish to avoid this duplication of the memory. Is there any way to share the data in the master kernel without duplicating the data into each subkernel?
Thank You
SetSharedVariable[data]
causesdata
to be always evaluated on the main kernel.data
will still be copied over to subkernels, but not just once, but every single time it is accessed. Never useSetSharedVariable
unless you fully understand the consequences. Probably a quarter of parlallelization questions here stem from a misuse ofSetSharedVariable
/Function
. $\endgroup$