Background Data Generation
This example shows how to generate simulation input data in the background while running your simulation loop on parameterized conditions. This workflow eliminates the need to generate data in advance and recall it from storage during run time.
Workflow Overview
Running simulations without interruption requires a supply of input data. For example, you might want to:
Generate a bit error rate (BER) curve over a range of values.
Evaluate the maximum reception rate for a software defined radio (SDR).
Generate channel estimate data at a rate that minimizes computational delays in a deep learning training loop that performs training or validation.
In this example, you compare the run times for producing input data and processing data frames in a conventional simulation for-loop versus a background runner simulation for-loop. The helperBackgroundRunner supporting file implements an object that enables you to generate simulation input data in the background while your simulation loop runs on parameterized conditions.
The helperBackgroundRunner object runs your data‐generation function on a pool of background workers by using the backgroundPool and parfeval function and buffers the results in a FIFO queue. You specify the generator function and the desired number of outputs as input arguments to the helperBackgroundRunner object. The object creates the pool, schedules futures, and returns the generated data. For more details on the underlying parallel mechanisms, see the parfeval function and Background Workers.
This examples uses a simple workflow to demonstrate how the helperBackgroundRunner object can provide real-time access to simulation input data. It uses:
A 16-QAM waveform generation function,
wwg_qam, adapted from a script exported from the Wireless Waveform Generator appA MIMO channel generation function,
wcd_mimo, adapted from a script exported from the Wireless Channel Designer appA local function,
genChanout, to run thewwg_qamandwcd_mimofunctions, and return the received signal and path gains as the generated dataThe
helperBackgroundRunnerto launch thegenChanoutdata‐generation function
Create Generator Object
Define a generator that produces one frame of channel estimates and a background runner object.
genFcn = @() genChanout(); br = helperBackgroundRunner( ... GeneratorFunction=genFcn, ... NumOutputs=2);
When you create a background runner object to generate data:
If you do not have a license for Parallel Computing Toolbox™, the number of workers in the background pool is 1.
If you have a license for Parallel Computing Toolbox™, the number of workers is equal to the number of physical cores you have.
A background runner creates one
Futureper worker (+1) to keep the pipeline full.
Process Frames in Conventional Loop
Simulate frame processing in a conventional for-loop, and then display the total run time.
numIterations = 1000; tic for k = 1:numIterations [rxSignalFM, pathGainsFM] = genChanout(); % Next, a practical simulation would recover the received % waveform and compare to the transmitted waveform to % compute a BER. end frameModeTime = seconds(toc)
frameModeTime = duration
38.015 sec
Process Frames in Background Loop
Replace direct calls to your batch generator with a single call to the helperBackgroundRunner object, br. Each call fetches the next ready batch. The helperBackgroundRunner automatically schedules a new future to regenerate that slot in the background. Check the number of workers on your system by assigning the variable pool.
pool = backgroundPool
pool =
BackgroundPool with properties:
NumWorkers: 6
Busy: false
tic for ii = 1:numIterations % Pull the next ready batch, blocking only if the queue is empty [rxSignal, pathGains] = br(); % Next, a practical simulation would recover the received % waveform and compare to the transmitted waveform to % compute a BER. end brTime = seconds(toc)
brTime = duration
14.327 sec
Startup time for the parallel pool will result in increased time for first simulation. Subsequent runs after the parallel pool is initialized will show true benefit of running with background pool. Your training loop never stalls waiting for data because the helperBackgroundRunner object maintains its own queue and spawns futures on each fetch.
Inspect Results
When the simulation ends, display the number of workers and futures that the br object used.
s = info(br); % Display worker and futures status fprintf("helperBackgroundRunner using %d workers, %d futures.\n", ... s.NumWorkers,s.NumFutures);
helperBackgroundRunner using 6 workers, 7 futures.
Release Background Jobs
Next, terminate all background jobs by releasing the br object.
release(br); % Terminate all background jobsLocal Function
function [rxSignal, pathGains] = genChanout() waveform = wwg_qam(); [rxSignal, pathGains] = wcd_mimo(waveform); end
See Also
Apps
Topics
- AI-Based CSI Feedback (5G Toolbox)
- Train PyTorch Channel Prediction Models with Online Training (5G Toolbox)