Main Content

ticBytes

Start counting bytes transferred within parallel pool

    Description

    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 (and associated metadata) 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.

    example

    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.

    example

    Examples

    collapse all

    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 'Processes' 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));
       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 for-loop can be slow due to overhead, see Convert Nested for-Loops to parfor-Loops.

    Input Arguments

    collapse all

    Parallel pool, specified as a parallel.ProcessPool or parallel.ClusterPool object.

    To create a process pool or cluster pool, use parpool.

    Example: pool = parpool('Processes');

    Output Arguments

    collapse all

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

    Example: startState = ticBytes(gcp);

    Extended Capabilities

    Version History

    Introduced in R2016b

    Go to top of page