How to do Matlab calculations in parallel

I have a Matlab.m script that installs and trains a neural network ("nn") using the Matlab Neural toolkit. The script launches some graphical interface that shows training progress, etc. Learning nn usually takes a lot of time.

I am doing these experiments on a computer with 64 processor cores. I want to train several networks at the same time without having multiple Matlab sessions. Therefore I want:

  • Start Neural Network Training
  • Change the script that creates the network to create another
  • Start Modified Network Training
  • Modify the script to create another network ...
  • Repeat steps 1-4 several times

The problem is that when I run the script, it blocks the Matlab terminal, so I can not do anything until the script executes its last command - and this will take a lot of time. How can I run all these calculations in parallel? I have a Matlab parallel toolbar.


EDIT: Matlab Error ??

Update: This problem seems to occur only on R2012a, it looks like it is fixed on R2012b.

When trying to execute the sequence of commands recommended in Edric answer>, there is a very strange error very . Here is my code:

 >> job = batch(c, @nn, 1, {A(:, 1:end -1), A(:, end)});
 >> wait(job);
 >> r = fetchOutputs(job)
 Error using parallel.Job/fetchOutputs (line 677)
 An error occurred during execution of Task with ID 1.

 Caused by:
    Error using nntraintool (line 35)
    Java is not available.

Here are lines 27-37 from nntraintool(part of the Matlab neural network toolkit) where the error occurred:

if ~usejava('swing')
  if (nargin == 1) && strcmp(command,'check')
    result = false;
    result2 = false;
    return
  else

    disp('java used');
    error(message('nnet:Java:NotAvailable'));
  end
end 

, , GUI ( Swing ) , batch. , nn - . train, , nn :

net.trainParam.showWindow = false;
net = train(net, X, y);

, nn (>> nn(A(:, 1:end -1), A(:, end));), if-then nntraintool 27 ( ). , , ~usejava('swing') 0, , 1 batch.

? Matlab Neural networks: (((

+2
1

Parallel Computing Toolbox 12 " " ( , MATLAB Distributed Computing Server). , BATCH . , . - ( R2012a +):

c = parcluster('local'); % get the 'local' cluster object
job = batch(c, 'myNNscript'); % submit script for execution
% now edit 'myNNscript'
job2 = batch(c, 'myNNscript'); % submit script for execution
...
wait(job); load(job) % get the results

, BATCH script , .

+6

Source: https://habr.com/ru/post/1532528/


All Articles