Parallel job bring me same random numbers

13 ビュー (過去 30 日間)
Dario Toledo
Dario Toledo 2017 年 11 月 20 日
編集済み: Dario Toledo 2017 年 11 月 21 日
The outputof my jobs depend of random numbers, I have the following script and i need to compare the result but i can't because they return the same.
Here is my code:
clear all;
clc;
thread1= batch('DiferentialEvo');
thread2= batch('DiferentialEvo')
wait(thread1);
wait(thread2)
load(thread1);
thread1Pg=Pg_best;
thread1pf=Pgf_best;
delete(thread1);
load(thread2);
thread2Pg=Pg_best;
thread2pf=Pgf_best;
delete(thread2);

採用された回答

Edric Ellis
Edric Ellis 2017 年 11 月 20 日
編集済み: Edric Ellis 2017 年 11 月 20 日
Parallel Computing Toolbox deliberately sets the random number state of workers such that the each task of a job starts from a known state - i.e. Task 1 of every job starts from a particular state, and Task 2 of every job starts from another particular state etc. See this doc page for more.
So, in conclusion, the simplest approach is simply to place
rng('shuffle')
inside your script - but be warned that this approach is fragile (as mentioned in the doc page referenced above) because it is based on the time at which the code executes.
For a more robust approach, you need to pass in the random seed to your task, and set up the random state from that.
  1 件のコメント
Dario Toledo
Dario Toledo 2017 年 11 月 20 日
編集済み: Dario Toledo 2017 年 11 月 21 日
Thank you, this actually works for me because of the nature of my script.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMulticore Processor Targets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by