Main Content

ticBytes

Start counting bytes transferred within parallel pool

    Description

    example

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

    Use theticBytes(pool) andtocBytes(pool) functions together to measure how much data is transferred to and from the workers in a parallel pool. You can useticBytesandtocByteswhile executing parallel language constructs and functions, such asparfor,spmd, orparfeval. UseticBytesandtocBytesto 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 ofticBytesandtocBytescalls. Use the value ofstartStateas an input argument for a subsequent call totocBytes.

    Examples

    collapse all

    a = 0; b = rand(100); ticBytes(gcp);parfori = 1:100 a = a + sum(b(:, i));endtocBytes(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 aparforloop nested in aforloop.

    REPS = 10; minBytes = Inf; ticBytes(gcp);% ticBytes, pair 1forii=1:REPS a = 0; b = rand(100); startS = ticBytes(gcp)% ticBytes, pair 2parfori = 1:100 a = a + sum(b(:, i));endbytes = tocBytes(gcp, startS)% tocBytes, pair 2minBytes = min(bytes, minBytes)endaverageBytes = tocBytes(gcp)/REPS% tocBytes,对1

    Note that nesting aparfor-loop in afor-loop can be slow due to overhead, seeConvert Nested for-Loops to parfor-Loops.

    Input Arguments

    collapse all

    Parallel pool, specified as aparallel.ProcessPoolorparallel.ClusterPoolobject.

    To create a process pool or cluster pool, useparpool.

    Example:pool = parpool('Processes');

    Output Arguments

    collapse all

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

    Example:startState = ticBytes(gcp);

    Version History

    Introduced in R2016b