So I have a Launcher.m script which executes a function.m using parfor. The function.m also has its own parfor. Will this work?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Feb. 2023
Bearbeitet: Walter Roberson am 2 Feb. 2023

1 Stimme

it will be accepted but will execute the second one in serial order

4 Kommentare

Rishi Balasubramanian
Rishi Balasubramanian am 1 Feb. 2023
That was quick, thank you.
Rishi Balasubramanian
Rishi Balasubramanian am 2 Feb. 2023
Is there a way to run both the parfors. The function.m uses parfor within. That must be driven for values [1, 2, 3, 4, 4.2, 4.4, 4.6, 4.8] for which I use parfor?
Walter Roberson
Walter Roberson am 2 Feb. 2023
The nested parfor will be executed in serial, in reverse order. It is not possible to initiate parallel constructs within parallel constructs and have the nested ones operate in parallel.
(Though I am not certain what would happen if you were to parfeval() or batch() within a parallel construct.)
Looks like parfeval() and parfor() cannot initiate parfeval() ...
p = parpool();
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 2).
outer_results = parfevalOnAll(p, @test_outer, 0, p)
outer_results =
FevalOnAllFuture with properties: ID: 5 Function: @test_outer CreateDateTime: 02-Feb-2023 02:33:51 StartDateTime: 02-Feb-2023 02:33:51 RunningDuration: 0 days 0h 0m 0s State: running Error: [1x2 cell]
celldisp(outer_results.Error)
ans{1} = ParallelException with properties: identifier: 'MATLAB:parallel:future:NoFevalOnWorkers' message: 'Workers cannot execute parfeval or parfevalOnAll.' cause: {} remotecause: {[1×1 MException]} stack: [2×1 struct] Correction: [] ans{2} = ParallelException with properties: identifier: 'MATLAB:parallel:future:NoFevalOnWorkers' message: 'Workers cannot execute parfeval or parfevalOnAll.' cause: {} remotecause: {[1×1 MException]} stack: [2×1 struct] Correction: []
parfor K = 1 : p.NumWorkers
test_outer(p);
end
Analyzing and transferring files to the workers ...done. outer about to start inner, ID = 67
Error using parallel.ProcessPool/parfevalOnAll
Workers cannot execute parfeval or parfevalOnAll.

Error in solution>test_outer (line 13)
inner_results = parfevalOnAll(p, @test_inner, 0, ID)
function test_outer(p)
ID = randi(99);
fprintf('outer about to start inner, ID = %d\n', ID);
inner_results = parfevalOnAll(p, @test_inner, 0, ID)
celldisp(inner_results.Error)
fprintf('outer fininished inners, ID = %d\n', ID);
end
function test_inner(ID)
subID = randi(99);
fprintf('inner ID %d subid %d reporting!\n', ID, subID);
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by