ticBytes - Start counting bytes transferred within parallel pool - MATLAB (original) (raw)

Main Content

Start counting bytes transferred within parallel pool

Syntax

Description

ticBytes([pool](#bvdz60l-1-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) andtocBytes (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 asparfor, spmd, orparfeval. Use ticBytes andtocBytes to pass around less data and optimize your code.

example

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

example

Examples

collapse all

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

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.

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');

Output Arguments

collapse all

startState — Starting state

TicBytesResult

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

Example: startState = ticBytes(gcp);

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