Here is some simple code:
Quit[]
B[d_] := Sum[Sqrt[1 + k^2] // N[#, d] &, {k, 0, 2 d}]
LaunchKernels[];
k = $KernelCount
outputting 6 for k. Next, I have
ClearSystemCache[];
d = 10^4;
mem1 = MemoryInUse[];
B[ d];
mem2 = MemoryInUse[];
(mem2 - mem1)/d // N
outputing
3903.61
Replacing ClearSystemCache[; in the last 6 lines of code by ClearSystemCache[] // ParallelEvaluate; gives a much smaller number, 29.0552, instead of 3903.61. This is completely unexpected to me. Doesn't ClearSystemCache[] // ParallelEvaluate; clear the memory more thoroughly than ClearSystemCache[]; ?
Repeating again with ClearSystemCache[] // ParallelEvaluate; gives a yet smaller number, 11.8872, in place of 29.0552.
Now I try to measure memory use per kernel:
ClearSystemCache[] // ParallelEvaluate;
d = 10^4;
mem1 = MemoryInUse[] // ParallelEvaluate;
B[d];
mem2 = MemoryInUse[] // ParallelEvaluate;
(mem2 - mem1)/(k d) // N // Total
and get 0 (!!).
Next, I replace Sum[] in the definition of B[] by ParallelSum[]:
Quit[]
BPar[d_] := ParallelSum[Sqrt[1 + j^2] // N[#, d] &, {j, 0, 2 d}]
Using BPar[] in place of B[] yields 8.0696 and 1.2688 in place of the mentioned numbers 3903.61 and 29.0552, respectively.
If, in addition, I also replace the two instances of MemoryInUse[] by MemoryInUse[] // ParallelEvaluate, to measure memory use per kernel:
ClearSystemCache[] // ParallelEvaluate;
d = 10^4;
mem1 = MemoryInUse[] // ParallelEvaluate;
BPar[d];
mem2 = MemoryInUse[] // ParallelEvaluate;
(mem2 - mem1)/(k d) // N // Total
then I get 1.21805; this does not seem to decrease with repetitions.
When BPar[d_] is replaced by
BParCoarse[d_] :=
ParallelSum[Sqrt[1 + j^2] // N[#, d] &, {j, 0, 2 d},
Method -> "CoarsestGrained"]
then I get 1.2952 and 2022.59 in place of the mentioned numbers 8.0696 and 1.21805.
So, there seems to be no agreement whatsoever between any of the output numbers, which vary very widely. Nothing of this makes any sense to me. I would very much appreciate your help.