0
$\begingroup$

I want to close the kernels which have completed their jobs in parallel computation. I have a test code as following:

LaunchKernels[5]

func[i_] := (
  Print["func:", i];
  Pause[2 i];
  Print[$KernelID, " Complete"];
  )
ParallelDo[func[i]; CloseKernels[$KernelID], {i, 1, 5}]

The output I get is this:

(kernel 12) func:1

(kernel 11) func:2

(kernel 10) func:3

(kernel 9) func:4

(kernel 8) func:5

(kernel 12) 12 Complete

(kernel 12) CloseKernels::subnopar :  Parallel programming is not available in subkernels of another parallel computation.

(kernel 11) 11 Complete

(kernel 11) CloseKernels::subnopar :  Parallel programming is not available in subkernels of another parallel computation.

(kernel 10) 10 Complete

(kernel 10) CloseKernels::subnopar :  Parallel programming is not available in subkernels of another parallel computation.

(kernel 9) 9 Complete

(kernel 9) CloseKernels::subnopar :  Parallel programming is not available in subkernels of another parallel computation.

(kernel 8) 8 Complete

(kernel 8) CloseKernels::subnopar :  Parallel programming is not available in subkernels of another parallel computation.

How to resolve these errors?

Note: I need to do parallel computation and close the kernels which have completed their jobs so that I can assign them more jobs. I don't want to close them all simultaneously because some of them complete their jobs before others(like in the example with Pause function), the computation is of that nature. I'm doing very heavy computation and can't do it sequentially.

$\endgroup$
  • 3
    $\begingroup$ You did not address the comments under your previous question: mathematica.stackexchange.com/q/219903/12 It still sounds like you simply should not be doing this. Did you set the parallel functions to use the finest granularity? $\endgroup$ – Szabolcs Apr 20 at 16:00
  • $\begingroup$ Finest grained will not work because I don't need to fine grain parallelization. I need to distribute 100 samples of population data analysis over 100 kernels (the maximum capacity of my workstation). 1 sample takes anywhere from 2 to 24 hours depending on some random parameters. The kernels which take more time is not because of problem with parallelization, it's because of NIntegrate. I just want to utilize the kernels which keep sleeping after finishing their jobs, while those which take more time can continue to complete their previous job. $\endgroup$ – Divyajyoti Apr 20 at 17:29
  • $\begingroup$ I am not going to argue with you, but you might want to read up on what Method -> "FinestGrained" actually does. It will save you some trouble. $\endgroup$ – Szabolcs Apr 20 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.