# Invoking functions in other kernels

Suppose one wants to parallelize as much as possible N tasks, each task produces a graphics via ParametricPlot or something like that. If the system is allowed to run 4 parallel kernels, how do I assign the tasks to all the available kernels?

So far what I've been doing is opening multiple notebooks, each running on a separate kernel, and running on different batches of input data.

Is there a better approach for this? Is possible to spawn a clone of the current kernel, or possibly just invoke code to execute in other kernels, so that the master program runs inside a single notebook, but schedules commands to other kernels?

You can use ParallelDo and ParallelTable to parallelize automatically.

ParallelTable[
ParametricPlot[p, ...],
{p, {thingsToPlot}}
]


Depending on your case, you could use Export inside of ParallelDo to save the files as you go. Otherwise the results will be returned to the master kernel if you use ParallelTable.

• ParallelDo sounds exactly what I need. Thanks Jan 1 '16 at 2:40
• You should be aware of some problems that may occure when using ParallelDo when writing to shared variable. ParallelTable handles this without additional programming effort, so you get back a "clean" list with all the elements in the right order. ParallelDo may have issue when trying to write an entry to a list while a second kernel is also doing so (see CriticalSection). In addition you may get a messed up order with ParallelDo depending on wich kernel finishes first. So there is no relation of list order and index order unless you store the index with the result. Jan 1 '16 at 21:23