How do I run two scripts in parallel ?

I have a for loop that runs through a very large number of iterations. In every iteration I have two blocks 'S1' and 'S2' of codes which are themselves composed by for loops. The scripts 'S1' and 'S2' do not depend of each other.
Serial config:
for i=1:50000
run(S1);
run(S2);
end
I tried using batch but it slowed my program VERY much. Parallel config:
for i=1:50000
batch(S1);
batch(S2);
wait(S1);
wait(S2);
load(S1);
load(S2);
end
What is the best way to make my code run in parallel ?

1 comentario

Walter Roberson
Walter Roberson el 3 de Feb. de 2016
Are they scripts or are they functions? Scripts are harder to deal with.

Iniciar sesión para comentar.

Respuestas (1)

Sean de Wolski
Sean de Wolski el 3 de Feb. de 2016

0 votos

Try parfeval, which uses an already open pool rather than opening a new one like batch and turn your scripts into functions so you're not saving/fetching unnecessary variables.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 3 de Feb. de 2016

Respondida:

el 3 de Feb. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by