2

I want to measure performance of parallel program implemented using C++(openMP)

Recommended way to measure time using this technology is

double start = omp_get_wtime();

// some code here

double end = omp_get_wtime();
printf_s("Time = %.16g", end - start);

But i get time near 0, despite i wait for program about 8 seconds. All other methods to get execution time return 0.0 Also tried use these code examples

DWORD st = GetTickCount();
time_t time_start = time(NULL);
clock_t start = clock();
auto t1 = Clock::now();     

time_t time_finish = time(NULL);
DWORD fn = GetTickCount();
clock_t finish = clock();
auto t2 = Clock::now();

All without success. Program spend running a lot of time. But results always zero. (In debug and release mode) If i debug step-by-step results differs from zero.

Here is my parallel #pragma directive

#pragma omp parallel default(none) private(i) shared(nSum, nTheads, nMaxThreads, nStart, nEnd, data, modulo) {
    #pragma omp master
    nTheads = omp_get_num_threads();
    nMaxThreads = omp_get_max_threads();

    #pragma omp for
    for (int i = nStart; i < nEnd; ++i)
    {           
        #pragma omp atomic
        nSum += (power(data[i], i) * i) % modulo;
    }
}

Where is my error? Please help me. I spend a lot of time with this problem.

Mark Lavrynenko
  • 628
  • 9
  • 18
  • This posts doesn't help me http://stackoverflow.com/questions/10874214/measure-execution-time-in-c-openmp-code?rq=1 because i am using Windows. – Mark Lavrynenko Jun 04 '14 at 16:29
  • Did you include ? If not, maybe omp_get_wtime() is being treated as returning an int, which would be sub-optimal. – Jim Cownie Jun 05 '14 at 16:02
  • 2
    @JimCownie omp.h was included. I solve my problem by moving double start = omp_get_wtime() to the very beginning of the program and double end = omp_get_wtime() to the very end. And it worked. But i can't understand how this helped! All time consuming code was wrapped in previous example too. – Mark Lavrynenko Jun 06 '14 at 16:54

0 Answers0