tocBytes - Read how many bytes have been transferred since calling

            ticBytes - MATLAB ([original](http://www.mathworks.com/access/helpdesk/help/parallel-computing/parallel.pool.tocbytes.html)) ([raw](?raw))

Read how many bytes have been transferred since callingticBytes

Syntax

Description

tocBytes([pool](#bvd794d-pool)) reads how many bytes have been transferred since calling ticBytes. The function displays the total number of bytes transferred to and from each of the workers in a parallelpool after the most recent execution of ticBytes.

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

example

[bytes ](#bvd794d-bytes)= tocBytes([pool](#bvd794d-pool)) returns the number of bytes transferred to and from each of the workers in the parallel pool.

example

tocBytes([pool](#bvd794d-pool),[startState](#bvd794d-startState)) displays the total number of bytes transferred in the parallelpool after the ticBytes command that generated startState.

example

[bytes ](#bvd794d-bytes) = tocBytes([pool](#bvd794d-pool),[startState](#bvd794d-startState)) returns the number of bytes transferred to and from each of the workers in the parallel pool after the ticBytes command that generated startState.

example

Examples

collapse all

Measure Amount of Data Transferred While Running a Simple parfor-loop

Use tocBytes(gcp,startS) to measure the amount of data (and associated metadata) transferred.

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

Measure Amount of Data Transferred While Running a Simple spmd Block

Use bytes = tocBytes(gcp) to measure the amount of data (and associated metadata) transferred.

ticBytes(gcp); spmd rand(100); end bytes = 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.

Simultaneously Measure Multiple Amounts of Data Transferred, Using Two Pairs of ticBytes and tocBytes Calls

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

Input Arguments

collapse all

pool — Parallel pool

parallel.ProcessPool object | parallel.ClusterPool object

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

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

Example: pool = parpool('Processes');

startState — Starting state

TicBytesResult

Starting state returned by ticBytes(pool).

Example: startState = ticBytes(gcp);

Output Arguments

collapse all

bytes — Bytes transferred

tocBytes(pool)

Bytes transferred, returned as a matrix of sizenumWorkers x 2. This matrix contains the number of bytes transferred to and from each of the workers in the parallel pool.bytes returns 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);

Extended Capabilities

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced in R2016b