Dear Community, I have a very simple question relating to ParallelTable[] function. The following code works as it must.
In[1]:= ParallelTable[k, {k, 10}]
Out[1]= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
But, if I use Print[], it works as it follows:
In[2]:= ParallelTable[Print[k], {k, 10}];
(kernel 2) 1
(kernel 1) 4
(kernel 2) 2
(kernel 1) 5
(kernel 2) 3
(kernel 1) 6
(kernel 2) 7
(kernel 1) 9
(kernel 2) 8
(kernel 1) 10
Can someone explain how it works?
One additional code, the result of which looks very strange:
In[3]:= i = 0; ParallelTable[Print["k = ", k, " \[Rule] i = ", ++i], {k, 10}];
(kernel 2) k = 1 -> i = 26
(kernel 1) k = 4 -> i = 26
(kernel 2) k = 2 -> i = 27
(kernel 1) k = 5 -> i = 27
(kernel 2) k = 3 -> i = 28
(kernel 1) k = 6 -> i = 28
(kernel 2) k = 7 -> i = 29
(kernel 1) k = 9 -> i = 29
(kernel 2) k = 8 -> i = 30
(kernel 1) k = 10 -> i = 30
Why the values of variable i are so strange?