I am trying to use OpenMP for threading as it is cross platform. However I can’t work out how to make the code after the parallel continue while the loop is running? It basically just executes the first loop in parallel but never gets to the second non parallel loop?
int main() {
#pragma omp parallel
while(1) {
Sleep(4000);
printf("doing work in thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
while (1) {
Sleep(4000);
printf("Hello from main %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
}
I think you could just make one of the threads your special thread within your omp parallel block
Weather this makes sense in your case is hard to judge without more details.
You could also use
sections. Example from here: http://bisqwit.iki.fi/story/howto/openmp/#Sections :You can do nested renationalisation: OpenMP: What is the benefit of nesting parallelizations?