OpenMP batch processing for independent streams¶
Tutorial goal
Run many independent signals through the C++ backend and compare batch behavior.
Note
New to the terminology? See the lattice DSP concept map and the causality/data-use guide for how online, offline, block, and MIMO examples should be read.
Context¶
The C++ extension is most useful when the same lattice operation is applied to many independent channels, trials, or parameter settings. This example demonstrates the batch interface used by the benchmarks.
Key idea and equations¶
If C independent channels each contain N samples, the batch path parallelizes over
independent jobs while preserving each stream’s state recursion.
How to read the result¶
Check whether OpenMP is reported as available and compare the batch output against the scalar reference path.
Run command¶
python examples/openmp_batch_processing.py
Run status¶
Return code: 0
Captured stdout¶
OpenMP enabled: True
input shape: (64, 50000)
output shape: (64, 50000)
output RMS: 0.9071251047245191
Source code¶
1"""Multi-channel batch processing demo.
2
3Rows are independent channels and can be parallelized by OpenMP in the C++ core.
4"""
5
6import numpy as np
7
8from lattice_dsp import HAS_OPENMP, process_batch
9
10rng = np.random.default_rng(7)
11channels = 64
12samples = 50_000
13x = rng.normal(size=(channels, samples))
14
15reflection = [0.3, -0.2, 0.1]
16taps = [0.1, -0.05, 0.2, 0.9]
17y = process_batch(reflection, taps, x, n_threads=0)
18
19print("OpenMP enabled:", HAS_OPENMP)
20print("input shape: ", x.shape)
21print("output shape: ", y.shape)
22print("output RMS: ", float(np.sqrt(np.mean(y * y))))