Main Content

tocBytes

Read how many bytes have been transferred since callingticBytes

    Description

    example

    tocBytes(pool)reads how many bytes have been transferred since callingticBytes. The function displays the total number of bytes transferred to and from each of the workers in a parallelpoolafter the most recent execution ofticBytes.

    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

    bytes= tocBytes(pool)returns the number of bytes transferred to and from each of the workers in the parallelpool.

    example

    tocBytes(pool,startState)displays the total number of bytes transferred in the parallelpoolafter theticBytescommand that generatedstartState.

    example

    bytes= tocBytes(pool,startState)returns the number of bytes transferred to and from each of the workers in the parallelpoolafter theticBytescommand that generatedstartState.

    Examples

    collapse all

    UsetocBytes(gcp,startS)to measure the amount of data transferred.

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

    Usebytes = tocBytes(gcp)to measure the amount of data transferred.

    ticBytes(gcp);spmdrand(100);endbytes = tocBytes(gcp)
    bytes = 13448 1208 13448 1208 13448 1208 13448 1208

    Workers transfer the same number of bytes, because each worker carries out the same number 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, pair 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.

    创建一个过程ss pool or cluster pool, useparpool.

    Example:pool = parpool('Processes');

    Starting state returned byticBytes(pool).

    Example:startState = ticBytes(gcp);

    Output Arguments

    collapse all

    Bytes transferred, returned as a matrix of sizenumWorkersx 2. This matrix contains the number of bytes transferred to and from each of the workers in the parallel pool.bytesreturns values in bytes without headings. UsetocBytes(pool)without an output argument to get Sent and Received headings, worker numbers, and values in bytes in the Command Window output.

    Example:bytes = tocBytes(pool);

    版本历史

    Introduced in R2016b

    Baidu
    map