![]() |
reactor-c 1.0
C Runtime for Lingua Franca
|
Support for optimizing sparse input through multiports. More...
Go to the source code of this file.
Data Structures | |
| struct | lf_multiport_iterator_t |
| An iterator over a record of the subset of channels of a multiport that have present inputs. More... | |
Macros | |
| #define | lf_multiport_iterator(in) |
| Macro for creating an iterator over an input multiport. | |
| #define | LF_SPARSE_CAPACITY_DIVIDER 10 |
| Divide LF_SPARSE_WIDTH_THRESHOLD by this number to get the capacity of a sparse input record for a multiport. | |
| #define | LF_SPARSE_WIDTH_THRESHOLD 10 |
| Threshold for width of multiport s.t. | |
Typedefs | |
| typedef struct lf_multiport_iterator_t | lf_multiport_iterator_t |
| An iterator over a record of the subset of channels of a multiport that have present inputs. | |
Functions | |
| lf_multiport_iterator_t | _lf_multiport_iterator_impl (lf_port_base_t **port, int width) |
| Given an array of pointers to port structs, return an iterator that can be used to iterate over the present channels. | |
| int | lf_multiport_next (lf_multiport_iterator_t *iterator) |
| Return the channel number of the next present input on the multiport or -1 if there are no more present channels. | |
Support for optimizing sparse input through multiports.
This header file is for macros, functions, and structs for optimized sparse input through multiports. When reading from a wide input multiport, before this optimization, it was necessary for a reactor to test each channel for presence each time a reaction was triggered by the multiport. If few of the input channels are present, this can be very inefficient. To more efficiently handle this situation, reactor authors should annotate the input port with the "@sparse" annotation and use lf_multiport_iterator() to read from an input multiport. For example:
The lf_multiport_iterator() function constructs an iterator (which is a struct) that can be passed to the lf_multiport_next() function to obtain the first channel number with a present input. Subsequent calls to lf_multiport_next() return the next channel index that is present until there are no more, at which point they return -1.
The way this works is that for each input multiport p1 that is marked @sparse, a struct s of type lf_sparse_io_record_t will be dynamically allocated and a pointer to this struct will be put on the self struct in a field named "portname__sparse". Each port channel struct within the multiport will be given a pointer to s.