# ParallelTable should distribute dedicated evaluation range to different kernels

I have 4 kernels and would like that in ParallelTable:

kernel 1 takes i from   1 to  250
kernel 2 takes i from 251 to  500
kernel 3 takes i from 501 to  755
kernel 4 takes i from 756 to 1000


How can I do that as example for the lower code?

ParallelTable[

x = i^2;
Print[x],

{i, 1, 1000}

]

• ParallelTable doesn't seem to have that, maybe something like ParallelEvaluate[ Table[{$KernelID, n}, {n, ($KernelID - 1) 250 + 1, $KernelID 250}]]~Flatten~1 – Jason B. Feb 5 '16 at 14:23 • How would the code look like when I want to read images from a List imageNamesList e.g. ParallelTable[ Import[ imageNamesList[[i]] ], {i, 1, 1000} ] – mrz Feb 5 '16 at 15:11 • Like this, right? ParallelEvaluate[ Table[Import[ imageList[[n]]], {n, ($KernelID - 1) 250 + 1, $KernelID 250}]]~Flatten~1 – Jason B. Feb 5 '16 at 15:15 • I get the following errors: (kernel 1) Part::partd: Part specification imageNamesList[[1]] is longer than depth of object. (kernel 2) Part::partd: Part specification imageNamesList[[251]] is longer than depth of object. and so on ? – mrz Feb 5 '16 at 15:24 • Then you have to set imageNamesList as a shared variable, right? SetSharedVariable[imageNamesList] – Jason B. Feb 5 '16 at 15:26 ## 1 Answer Here is the solution of Jason B. ParallelEvaluate[ Table[ {$KernelID, i};
x = i^2;
Print["$KernelID = ",$KernelID, ", i = ",
i ", x = \!$$\*SuperscriptBox[\(i$$, $$2$$]\) = ", x],
{i, ($KernelID - 1) 250 + 1,$KernelID 250}
];
];


Output is correct: (I only do not understand why for i=1 no output is shown?)

...

• "I only do not understand why for i=1 no output is shown" - when you are building statements like this to print, combining strings and numbers, the best way to do it is by converting everything to a string and using StringJoin to combine them. Print["$KernelID = " <> IntegerString[$KernelID] <> ", i = " <> IntegerString[i] <> ", x = \!$$\*SuperscriptBox[\(i$$, $$2$$]\) = " <> IntegerString[x]] – Jason B. Feb 8 '16 at 8:14
• @Jason B: can you overtake my written solution (which is yours), so I can accept it as solved? – mrz Feb 11 '16 at 12:16
• no worries, you should accept this as is :-) – Jason B. Feb 11 '16 at 12:33
• It is not possible to vote for my own answer ... – mrz Feb 21 '16 at 13:37
• I just meant that you should accept it, with the green check mark, since it is the solution to the problem. There isn't a way to transfer the ownership of a post, and it really is not a big deal for the attribution. You could make the answer a community wiki I think, but I'm not familiar with how to do that. Cheers – Jason B. Feb 21 '16 at 13:41