# How to close a specific Kernel after completion of evaluation in ParallelDo

I have a particular code that I have to run over several different parameters. I am using ParallelDo to parallelize the process. Due to the nature of the evaluations some Kernels finish the evaluations much before the others. After that I print the data generated by that Kernel to a file and the Kernel becomes idle. Is there any way to free up the Kernel so that I can use it for a future evaluation?

If you are curious about why some Kernels finish the work before others, it's because I have to solve a differential equation for a fixed number of time periods, say N, but the parameter is the frequency, hence some time periods are much larger than the other and hence take longer to evaluate.

• As a start, you should set Method -> "FinestGrained". This way, you will get a result faster and less time will be spent with few kernels active. Doing what you ask does not seem easy. Perhaps with ParallelSubmit, but I do not have an immediate solution. May 22 '20 at 16:18
• I read up a bit on this, and it seems that this way the distribution is such that Mathematica always uses the maximum number of Kernels possible. This is a possible solution, I will check. Though I was thinking of identifying which Kernel process is completed and closing that Kernel by CloseKernels[n]. Because if I am not mistaken the Kernels have a unique number during the evaluation, but will it make the code unstable? May 23 '20 at 6:16
• You cannot do that from ParallelDo. It might be possible if you micro-manage parallelization with ParallelSubmit. May 23 '20 at 7:52
• I see thanks. Will try this. May 29 '20 at 5:23