I'm processing a bunch of files on the disk. The pattern of my program is like reading a file, processing the data and writing to another file, and over and over again for all the files in the directory.
On average reading a file would take about 80ms, processing the data would take about 700ms, and writing a file would take less than 50ms. So I think if I could continuously read the files and use several threads to process them will save me some time.
Thus I've tried to use the pipeline class in TBB to parallel my code. Basically I've made the read filter and write filter to run in serial and the process filter to run in parallel. However I tried to change the ntoken and number of threads, the program run faster when I use only one thread.
I've inspected the CPU usage and I saw only one core was busy although I used multiple threads. So could anyone tell me what is going wrong?