Can Cilk++ be as parallel as a TBB pipeline?

Can Cilk++ be as parallel as a TBB pipeline?

My typical application reads an input file line by line, performs a time-consuming process on each line, and then writes an output file line by line. I've successfully used TBB, with a pipeline and a concurrent line queue on the input, to achieve a major parallel processing speedup. I'd like to try the next such similar application using Cilk.

A TBB pipeline with three filters, serial input, parallel transform, and a serial output filter has parallelism not only by having multiple middle filters running at once, but also by having in the pipeline at the same time one or more input and output filters.

Can this even be done with Cilk? I may have a cilk_for operating on multiple lines at once, but the reading of the input file and writing of the output file appear to have to be done serially, and not at the same time as the parallel processing.

Is a TBB pipeline inherently more parallel than Cilk?

Worst case might be a TBB pipeline with 8 serial filters in sequence. TBB would overlap all the processing using 8 processors, but could Cilk? Theoretically dataflow architecture is extremely powerful

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

I don't believe that Cilk has anything like the TBB pipeline concept. The closest you can come is Cilk's reducers. With a properly written reducer, a parallel, multi-core run will produce the same result as a serial, single-core run. I suggest that you look at the ostream reducer which is shipped with the Cilk kit. It will buffer any intermediate results until they are reduced into the "leftmost" instance, when they'll be written to the file.

Another example to look at is the bzip2 example written by John Carr, which is available at .

- Barry

Barry is right.

However, the compiler ships with an ostream reducer that would facilitate your output. The ostream reducer wraps an ostream and ensures output occurs in the serial order.

Leave a Comment

Please sign in to add a comment. Not a member? Join today