05-25-2021 05:16 PM
I am writing a program where data is continuously acquired on one thread, and processed on another. From my readings, I understand that producer-consumer architecture can be used to send resources across parallel executing threads using the first-in/first-out queue. On the other hand, I could use Reentrant VIs to also grant access to shared resource from multiple threads. However, because data processing is happening at a slower rate than data acquisition, I only care most about the most recently acquired data.
My question is:
- would using Reentrant VI overwrite the data being written to? such that I find new data each time the data processing thread accesses the shared resource
- if there is no over-writing and I get an accumulation of all acquired data, could I simply index into the position of the most recently acquired data?
- is there a more programming efficient method than indexing?
- since I only want the most recent data acquired at the time that the processing thread accesses the resource, how can I programmatically eliminate the data that I do not care about?
The code isn't written out yet, still trying to solidify my conceptual understanding for how to execute the project. Your inputs are much appreciated.
05-25-2021 06:16 PM
Quick comment: To share data using a subVI, it should be non-reentrant. If it is reentrant, each instance has it's own dataspace.
05-25-2021 07:29 PM
You could consider using a Lossy Stream channel.
If you make the maximum size equal 1, it means that it only would ever take the most recent data chunk from the acquisition to look at, if you bundle all the data together.
It would also mean that if you ever got a "faster" setup where the data analysis can now go faster than the acquisition, you'd never accidentally process the same chunk twice since each chunk exits the stream when is taken to be used by the processing code.
You could also set the max size to a slightly higher number equal to the amount of parallel threads you want to do processing at the same time. So if you have (for instance) a processor that can run 8 threads at once, you could set it to 6, spin up 6 parallel processing VIs to run at once, and then you have one thread left for your acquisition loop and 1 left for either incidentals or for the OS to use.
If you use the parallel method you probably would want to somehow index the data when you send it to be saved or displayed to make sure it doesn't get used out-of-order.
05-25-2021 07:48 PM
@ooyeniyi wrote:
However, because data processing is happening at a slower rate than data acquisition, I only care most about the most recently acquired data.
I would just use a Notifier then.