0

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?

unclejimbo
  • 91
  • 7
  • Related: https://stackoverflow.com/questions/56672/how-do-you-profile-your-code – UKMonkey May 03 '18 at 14:09
  • Unfortunately, it is difficult to say what is going wrong without any code-snippet or reproducer. However, I would recommend to look at [examples/pipeline/square](https://github.com/01org/tbb/tree/tbb_2018/examples/pipeline/square) and [examples/graph/bzip2](https://github.com/01org/tbb/tree/tbb_2018/examples/graph/fgbzip2). The both examples read and process files. – Alex May 03 '18 at 14:18
  • Thanks folks for your help. Now I've found the problem, it's not related to my code, but to a library that I use. FYI, if you use arch linux and use [dlib](https://aur.archlinux.org/packages/dlib/) from the AUR, it'll prevent you from using multiple cores. After I compile dlib from source and the multi-threading is back to business. – unclejimbo May 04 '18 at 04:35

0 Answers0