OpenMP Thread count question

11,220

Your professor is correct: OpenMP will choose an optimum number of threads by default, which is usually the number of cores.

You don't need to worry about the number of threads being exactly divisible by N: OpenMP will automatically distribute the iterations among the threads, and if they're not evenly divisible, one thread will end up performing a little more or less work.

Share:
11,220
Admin
Author by

Admin

Updated on June 27, 2022

Comments

  • Admin
    Admin almost 2 years

    So Im doing a bit of Parallel Programming of the Trapezoidal Rule for my OS class, this is a homework question but im not looking for source code.

    after a bit of research I decided to use each thread to compute a subinterval. using:

     g = (b-a)/n;
       integral += (func(a) + func(b))/2.0;
    
    #  pragma omp parallel for schedule(static) default(none) \
          shared(a, h, n) private(i, x) \
          reduction(+: integral) num_threads(thread_count)
       for (i = 1; i <= n-1; i++) {
          x = a + i*g;
          integral += func(x);
       }
    

    in my integral function, func(x) is the function that I read in from the file.

    So I email my professor to ask how he wants to go about choosing the number of threads. (since they will need to be evenly divisible by N (for the trapezoidal rule)

    but he is saying I dont need to define them, and it will define them based on the number of cores on my machine........So needless to say Im a bit confused.