Stop a worker and continue the Parallel pool in Matlab

Asked

Viewed 39 times

0

I have a code with a parfor simple in Matlab that calls the Workers.

parfor valor= 1:fim

        [output, out] = Computacao(dado1, dado2, int32(valor));
end

within the function that is called have an if for a condition in which if found an error it should stop, but wanted only one worker to stop for the value = 3 for example, and all others would be computed normally.

I tried it this way:

if or(((aaa+4/3*sss)./ddd) < 0, mu < 0)

    problemaaa = 1;
    fprintf('PROBLEM FOUND');
    error('deuruim');

end

But when it finds the error it does not just for the calculation of the index with error, for all computations in progress. There is a way for me to kill only the worker of that index who found the error and continue normally?

1 answer

0

It’s not very clear to me, but I think you just want to skip to the next iteration if something specific happens, so you can use the continue, he will continue trying the next conditions, a basic example would be this:

for n = 1:50
    if mod(n,7)
        continue
    end
    disp(['Divisible by 7: ' num2str(n)])
end

Upshot:

Divisible by 7: 7
Divisible by 7: 14
Divisible by 7: 21
Divisible by 7: 28
Divisible by 7: 35
Divisible by 7: 42
Divisible by 7: 49

In the example the algorithm jumps to the next iteration if the number is not divisible by 7, you can do the same when your worker has value = 3 instead of error put a continue

if or(((aaa+4/3*sss)./ddd) < 0, mu < 0)

    problemaaa = 1;
    fprintf('PROBLEM FOUND');
    continue

end

I hope I understand your problem ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.