Why doesn't ParallelTable work while Table does in Mathematica 11?

I have written a heavy program that my computer is unable to process. Therefore, I decided to use both processor cores for data processing. My code is as follows: (Note that to test the program, set the value of p to a smaller number, such as 5.)

I used the function LaunchKernels[]; to activate both processor cores, and instead of the Table function, I used the ParallelTable function. However, the program does not produce any output. If I use the Table function, the program works correctly.

Can anyone explain why the program does not work with ParallelTable?

I am using version 11.

I mean you don’t store the results I think… normally you have:

 output = (Parallel)Table[…]

You want to do this:

data = ParallelTable[previous code followed by ;
   (Subscript[fdiag, r] - Re[Subscript[fSp, r]])/4
   ,
   {r, 0.01, 3.5, 0.01}
   ];

Here the last statement inside the Table comments is ‘collected’ and store in the data variable…

And then use:

ListLinePlot[data, …]

Btw, using subscripts is bound to fail at some point. You should use that as a typographic construct only.

And in the code you can remove all the subscripts and it will work…

Also the use of For loop is very awkward and can be much simplified for readability:

data = ParallelTable[
   pf = \[Rho][r];
   pf /= Tr[pf];
   ef = Chop[Eigenvalues[pf]];
   fdiag = 0;
   fSp = 0;
   Do[
    If[Chop[pf[[i, i]]] =!= 0,
     fdiag -= pf[[i, i]] Log2[pf[[i, i]]]
     ];
    If[ef[[i]] =!= 0,
     fSp -= ef[[i]] Log2[ef[[i]]]
     ];
    ,
    {i, 1, Length[\[Rho][r]]}
    ];
   (fdiag - Re[fSp])/4
   ,
   {r, 0.01, 3.5, 0.01}
   ];

But even these loops are not really needed as the entire thing can be handled in a vector manner:

ClearAll[NewLog2]
SetAttributes[NewLog2, Listable];
NewLog2[val_] := If[Chop[val] == 0, 0, Log2[val]]
data = ParallelTable[
   pf = \[Rho][r];
   pf /= Tr[pf];
   ef = Chop[Eigenvalues[pf]];
   fdiag = -Total[Diagonal[pf] NewLog2[Diagonal[pf]]];
   fSp = -Total[ef NewLog2[ef]];
   (fdiag - Re[fSp])/4
   ,
   {r, 0.01, 3.5, 0.01}
   ];