Pipelines: Merging two different buffers

Pipelines: Merging two different buffers

Hi,

I am new to TBB and currently implemented a simpleTBB program using Pipeline. The I/P filter passes an integer array to the Transform filter which then performs an operation on the array and the O/P filter writes it out.

Now, I want to pass two differentarrays into the pipeline and have the transform filter merge the two buffers based on some criteria. The O/P filter then prints out the merged result. I want to know if this is possible using the Pipeline and Filter classes . My question is more on 'how' to pass two different arrays using the I/P filter.

Rgds.

publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

I would be inclined to use a std::pair object that points to the two arrays. Pass the pair objects through the pipeline. The transform stage should take a std::pair as its input and return a pointer to the merged results as its output.

If you want the I/P filter to process the pairs of input arrays in parallel, the simplest way is to write a parallel loop that loops over i=0,1 and does one of the arrays for each index. TBB is good about supporting nested parallelism, so putting the parallel_for inside a pipeline stage shouldn't cause any surprises.

An alternative, if the I/P operation is the same for each array, is to pass arrays into the I/P stage, and then write a serial "pairing" stage that does pairing. The pairing stage would return either the paired arrays (say a std::pair) or a dummy object. Each time the pairing stage is run, it inspects whether it has previously accumulated an array. If so, it pairs it with the new incoming array and returns a std::pair. Otherwise it accumulates the array and returns a dummy object. Later stages of the pipeline would have to know to skip processing of dummy objects.

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya