0

I have these 2 functions that are used to measure the performance for a single threaded function.

#include <Windows.h>
#include <intrin.h>
typedef unsigned __int64 prof_time_t;

void inline start_measure(prof_time_t & cycle_read)
{
    SetProcessAffinityMask(GetCurrentProcess(), 1);
    SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
    int a[4], b = 1;
    __cpuid(a, b);
    cycle_read = __rdtsc();
}

void inline end_measure(prof_time_t & cycle_read)
{
    unsigned int c;
    cycle_read = __rdtscp(&c);
    int a[4], b = 1;
    __cpuid(a, b);

}

But now that I am doing a multithreaded function, I realise that I'm not sure how to convert this function to account for the various threads. I am using open mp for the multithreading.

I looked for a solution but still not very sure how I should go about with editing my function to account for openmp threads.

Measuring time in a multithreaded C++ application

I'm not very strong with multi-threading, so I'm a little lost with this, please help :(

All help is appreciated, thank you!!

DavidW
  • 29,336
  • 6
  • 55
  • 86
Megan Darcy
  • 530
  • 5
  • 15
  • Maybe better to just use some benchmark library, like https://github.com/google/benchmark – pptaszni Nov 25 '21 at 14:18
  • 2
    RDTSC/RDTSCP is not portable (only on x86) and timings cannot be compared between threads due to frequency scaling (eg. turbo-boost on Intel processors). OpenMP has its own portable function to measure the *wall-clock time*. See [Measure execution time in C++ OpenMP code](https://stackoverflow.com/questions/10874214/measure-execution-time-in-c-openmp-code). – Jérôme Richard Nov 25 '21 at 14:39
  • @JérômeRichard thank you! this was the best solution from that post :) https://stackoverflow.com/a/63621357/15233108 – Megan Darcy Nov 26 '21 at 11:34

0 Answers0