Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

the_statistics.record to gather statistics

prasun_gera
Beginner
320 Views
I was trying to gather statistics by defining the macro STATISTICS as 1. From what I understand, each thread updates its own set of values such as steal_count mail_received etc., and in the end, all of them are updated to statistics.txt. I ran some of the examples from the directory with varying number of threads passed to task_scheduler_init, and I saw that the number of lines in the statistics file weren't consistent with the number of threads. The records are updated by the_statistics.record which is called in GenericScheduler::free_scheduler. free_scheduler in turn is called by GenericScheduler::cleanup_worker and GenericScheduler::cleanup_master. After adding prints, I found out that only cleanup_master is called at times and cleanup_worker isn't called which would indicate that only the master is writing to the file. Is this the expected behaviour?
0 Kudos
3 Replies
Alexey-Kukanov
Employee
320 Views

try explicit library initialization with a task_scheduler_init object, and after it is destroyed or its terminate() method is called, make the program sleep a little before exiting. This may help.

The explanation is that TBB worker threads are detached, i.e. the library signals them to shut down but does not wait for their completion. If the process exits right after TBB is deinitialized, worker threads could just get killed; no guarantee that they complete shutdown code. By adding some wait before process exit you give the threads some time to complete.

0 Kudos
prasun_gera
Beginner
320 Views

Thanks Alexy. Sleep seems to work, but as you said, only in cases of explicit initialization and termination of the library. I was wondering if I could resolve this issue at the library level by moving the writes to the file to a location prior to the signalling of the shutdown. Any hints regarding that? Another option that comes to my mind is using a shared data structure, so that the master can extract all the information from it, and only the master writes to the file.

PS: on_scheduler_exit faces the same limitation right?

0 Kudos
Alexey-Kukanov
Employee
320 Views

Yes on_scheduler_exit can be missed due to the same reason.

As for hints... In TBB 2.2, look for terminate_workers, and go both up and down the call stack to find a suitable place for statistics dump.

0 Kudos
Reply