简体   繁体   中英

OpenMP Thread count question

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM