1

is there any way to choose the best number of threads from inside the program? for example, if i am running my program on a dual core machine, it will use 2 threads, on a 6 core machine, it will run on 6 threads, etc?

i don't know if there is a pthreads call to see how many of cores the program is being run on, but i was even considering something like the following:

at the beginning of the program, run a for loop (maybe 1000 iterations) and time it. then run it with 2 threads, this should (probably) be somehwere around twice as fast. continue this process until there is no noticeable speedup. this is the optimal number of threads to use.

obviously this is a waste of time (having to loop that many times) and it will not always give you the maximum number of threads to use, but it was just an idea. any other ways?

drjrm3
  • 4,474
  • 10
  • 53
  • 91

0 Answers0