can I accelerate parfor loop running external code?

3 views (last 30 days)
Here is my question:
if I run following code, the toc time is 0.296749.
tic
lambda=1;
for k=1:lambda
filename_nam=sprintf('mf2005 test_%03d.nam',k);
[~,~]=system(filename_nam);
.
.
.
end
toc
Otherwise, if I run following code, the toc time is 12.920165. This result is reasonable because 0.296749 * 43 is approximately 12.9.
tic
lambda=43;
for k=1:lambda
filename_nam=sprintf('mf2005 test_%03d.nam',k);
[~,~]=system(filename_nam);
.
.
.
end
toc
Lastly, if I run following code, the toc time is 3.902111. This is obviously improvement by using parfor but I wonder if there is further way of improving the efficiency. In my parallel pool, I have 36 worker (36 core CPU) and the required memory for the exe code is very small compared to my 64Gb memory. The operating system is Windows 10. What is the limiting condition? code? a specific hardware? or any other?
tic
lambda=43;
parfor k=1:lambda
filename_nam=sprintf('mf2005 test_%03d.nam',k);
[~,~]=system(filename_nam);
.
.
.
end
toc
  3 Comments
Eungyu Park
Eungyu Park on 2 Apr 2020
The part inside the parfor loop consists of an execution subpart and a subpart that reads the execution result. It looks like the code using .NET framework is trying to read the results before execution ends. This causes an error. If I just run the code without the reading subpart, the computation rate seems to be very fast. However, the problem is that the toc time is much earlier than termination of all executions (The toc time is already displayed in the command window even though it is still being calculated). Also, the shell window popup consumes computer resources and slows down computation. Are there any solutions?
Walter Roberson
Walter Roberson on 2 Apr 2020
You can test if a process started with .NET is still going, or you can wait for it (with an optional timeout)
Anyhow, typically the answer to the question of the limiting condition is either communications overhead or use of a limited resource (for example disk I/O bandwidth.)

Sign in to comment.

Answers (1)

Eungyu Park
Eungyu Park on 3 Apr 2020
Thank you Mohammad and Walter for your help! It seems that 'system' and 'System.Diagnostics.Process()' take about same time for my parfor loop execution of external code.
  1 Comment
Walter Roberson
Walter Roberson on 4 Apr 2020
Sometimes when multiple processes use a shared resource but do not each need 100% of the resource, then it can be beneficial to start a limited number of the processes and wait for one to finish before starting the next, so that there might be a small number of processes accessing the resource but not too many. This can reduce contention for the resource. This can be especially important for disc access.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!