Start counting bytes transferred within parallel pool
startState = ticBytes(pool)
counting the number of bytes transferred to each worker in the
so that later
measure the amount of data transferred to each worker between the
together to measure how much data is transferred to and from the workers
in a parallel pool. You can use
executing parallel language constructs and functions, such as
pass around less data and optimize your code.
a = 0; b = rand(100); ticBytes(gcp); parfor i = 1:100 a = a + sum(b(:, i)); end tocBytes(gcp)
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers. BytesSentToWorkers BytesReceivedFromWorkers __________________ ________________________ 1 42948 7156 2 36548 7156 3 27500 4500 4 27500 4500 Total 1.345e+05 23312
Workers might transfer different numbers of bytes, because each worker might carry out different numbers of loop iterations.
Measure the minimum and average number of bytes transferred
while running a
parfor loop nested in a
REPS = 10; minBytes = Inf; ticBytes(gcp); % ticBytes, pair 1 for ii=1:REPS a = 0; b = rand(100); startS = ticBytes(gcp) % ticBytes, pair 2 parfor i = 1:100 a = a + sum(b(:, i)); end bytes = tocBytes(gcp, startS) % tocBytes, pair 2 minBytes = min(bytes, minBytes) end averageBytes = tocBytes(gcp)/REPS % tocBytes, pair 1
Note that nesting a
parfor-loop in a
can be slow due to overhead, see Convert Nested for-Loops to parfor.
startState— Starting state
Starting state returned as an input argument for a subsequent
startState = ticBytes(gcp);