-2

i've been trying to learn how to use OpenMP for c++ and i'm having a huge headache trying to apply it to a code that uses the Riemann Zeta function, i only found it this way(in the code), but if you run it you will see that the serial process is way faster. Can anyone help me to find why the serial is faster than the parallel?

    double rzfParallel(int n, long inf)
    {
        double sum = 0.0;
        #pragma omp parallel for reduction(+:sum) num_threads(8)
            for(int k = 1; k <= inf; k++)
                sum += 1.0/pow(k, (double)n);

        return sum;
    }


   The method to chath time:
   startTime = clock();
   funcResult = rzfParallel(n, inf);
   endTime = clock();
   timeResult = (endTime/CLOCKS_PER_SEC) -(startTime/CLOCKS_PER_SEC);
Alexandre Pedrecal
  • 117
  • 1
  • 2
  • 10
  • 1
    Please don't post a link to offsite code. It makes this question useless for the future. Faced with that we mods are compelled to close and delete. – David Heffernan Jan 26 '16 at 22:41
  • Ok, how can I put my code in a better way to complete my question? – Alexandre Pedrecal Jan 26 '16 at 23:28
  • Copy+paste a minimal working portion of your code into the question itself, indenting with 4 spaces so that this site sees it as code and not as text. – NoseKnowsAll Jan 26 '16 at 23:30
  • Also, technically your `#pragma` statement is correct. However, as @MSalters has noted, each thread is doing very little work, so you are unlikely to see much speedup overall. Furthermore, you are using `clock()` to measure your code's time-to-completion when you should be using `omp_get_wtime()`. One measures CPU time (not what you care about), while the other measure actual wall time (what you are looking for) of your program. – NoseKnowsAll Jan 26 '16 at 23:32

2 Answers2

1

The usual : Too much time staring parallel thread, too little work per thread.

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

I solved this with the flag -mavx in the Intel compiler. I'm trying to understand the problem, not sure yet. Something that my processor wasn't vectorizing. Still cant get a -vec-report. If anyone know how to do it, please tell me. Special thanks to NoseKnowsAll

Alexandre Pedrecal
  • 117
  • 1
  • 2
  • 10