Start counting bytes transferred within parallel pool


startState = ticBytes(pool)



ticBytes(pool) starts counting the number of bytes transferred to each worker in the pool, so that later tocBytes(pool) can measure the amount of data transferred to each worker between the two calls.

Use the ticBytes (pool) and tocBytes (pool) functions together to measure how much data is transferred to and from the workers in a parallel pool. You can use ticBytes and tocBytes while executing parallel language constructs and functions, such as parfor, spmd, or parfeval. Use ticBytes and tocBytes to pass around less data and optimize your code.


startState = ticBytes(pool) saves the state to an output argument, startState, so that you can simultaneously record the number of bytes transferred for multiple pairs of ticBytes and tocBytes calls. Use the value of startState as an input argument for a subsequent call to tocBytes.


collapse all

a = 0;
b = rand(100);
parfor i = 1:100
    a = a + sum(b(:, i));
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 for loop.

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));
   bytes = tocBytes(gcp, startS)  % tocBytes, pair 2  
   minBytes = min(bytes, minBytes)

averageBytes = tocBytes(gcp)/REPS  % tocBytes, pair 1 

Note that nesting a parfor-loop in a for-loop can be slow due to overhead, see Convert Nested for-Loops to parfor-Loops.

Input Arguments

collapse all

Parallel pool, typically specified by gcp, if you want the current parallel pool. Otherwise, use parpool to create a new pool.

Example: ticBytes(gcp);

Output Arguments

collapse all

Starting state returned as an input argument for a subsequent call to tocBytes.

Example: startState = ticBytes(gcp);

Introduced in R2016b