How does gcc determine the best number of threads if one sets omp_set_dynamic(1)? OpenMP leaves it implementation defined, but I would love to know how gcc implements it.
Thanks!
GCC implements OpenMP using the libgomp runtime library. It's part of the compiler and its source code is freely available under the same GPL license as used by GCC. You can either download some point release of GCC and examine the libgomp folder or you can browse the source code online. This links is for the latest stable version of GCC 4.8.3. Starting with GCC 4.9, libgomp implements OpenMP 4.0 features and that makes the source code harder to understand.
The logic for implementing dynamic number of threads is to be found in gomp_resolve_num_threads() in parallel.c. Basically it only supports dynamically setting the number of threads for the parallel sections combined construct and tries to set the number of threads in the team equal to the number of distinct sections inside the construct.