PCM usage in multi-threaded application #212
-
Hi all, I hope this is the right place to ask my question. I would like to profile some sections of a multithreaded application. Each code section is executed within one thread on a partition of the input. What i want to do is to profile each code section that runs on a specific core. I am a bit confused regarding the multi-threaded model of PCM. Can one PCM instance be shared across threads? Would that be expensive, e.g., is there a lock?Is this an intended way of using PCM or should one use it in a dedicated thread that samples stats every N milliseconds (e.g., like in the provided examples).
I am aware that this could also be done via Vtune but I would be interested in using pcm only. EDIT: is |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
what you should do is the following:
getCoreCounterState has only per-core/thread locks inside, so it should not matter for you |
Beta Was this translation helpful? Give feedback.
-
hi @opcm thank you very much for your help. Much appreciated. It works! Please, feel free to close the issue or let me know if i can help making this snippet available for future use. |
Beta Was this translation helpful? Give feedback.
-
@opcm a followup question, if i may. Would it be possible to configure a different set of custom counters on each core? If that is not possible, would you recommend reprogramming the PCM instance with different counters every N units of time or should the PCM instance be untouched after |
Beta Was this translation helpful? Give feedback.
-
you can change the set of monitored events for all cores altogether: https://github.com/opcm/pcm/blob/4f326d4b45b29fe996e9a6b60034eeee28a6e8f6/pcm-core.cpp#L89 I expect reprogramming should work. |
Beta Was this translation helpful? Give feedback.
-
@opcm thank you! i confirm that reprogramming on-the-fly the PCM instance works. |
Beta Was this translation helpful? Give feedback.
@opcm thank you! i confirm that reprogramming on-the-fly the PCM instance works.