Functions working with parfor but not parfeval
1 view (last 30 days)
Show older comments
Hello,
I am currently working on a code where I want to accelerate a bit the process with some parallel computing.
I have 2 independant functions which give me outputs in two different folder. They run by writing :
parfor i = 1:2
if i == 1
glacier_point_output(temp_folder,formatOut,result_path, run_number, forcing_divided_path_glacier, parameters_file_glacier, constants_file_glacier, date, main_folder,yr,mm,dd);
else
land_point_output(temp_folder,formatOut,result_path, run_number, forcing_divided_path_land, parameters_file_land, constants_file_land, date, main_folder, yr,mm,dd);
end
end
I have those two lists generated in the functions that I save in a temporary folder, load later in the script and display them.
Now, a Staff member from Mathworks told me I could use parfeval since the two functions are totally independant, and that it would be more resilient if I want to get the two generated lists as an output. I write the following lines:
% Invoke both function evaluations in parallel.
fut_land = parfeval(@land_point_output, 1, temp_folder,formatOut,result_path, run_number, forcing_divided_path_land, parameters_file_land, constants_file_land, date, main_folder, yr,mm,dd);
fut_glacier = parfeval(@glacier_point_output, 1, temp_folder,formatOut,result_path, run_number, forcing_divided_path_glacier, parameters_file_glacier, constants_file_glacier, date, main_folder, yr,mm,dd);
% Collect results - this blocks until the evaluation is complete.
[buggy_points_land] = fetchOutputs(fut_land);
[buggy_points_glacier] = fetchOutputs(fut_glacier);
The issue is that these lines above don't work. The functions are exactly the same in the two cases, but I get an error message saying the functions were not able to write the files into the folder.
Is this code just not adapted ? Because the functions in both cases are exactly the same, and the parfor loop works really well.
Thank you !
2 Comments
Edric Ellis
on 4 May 2020
Those two pieces of code ought to be doing the same thing. Although perhaps if temp_folder is a function rather than a variable, that would make a difference (in the parfor case, it would be evaluated on the worker; in the parfeval case, it would be evaluated on the client at the point you execute the parfeval call).
Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!