1

Say we have a serial application that stops normally for a while 'till a completely independent function is computed. How can one use OpenMP to spawn that function only to a thread and only printf its result when it ends? [without stopping the main application]

EDIT: Can it be done if the independent function is run inside the main app?

j riv
  • 3,593
  • 6
  • 39
  • 54
  • Does this answer your question? [Execute functions in parallel using openmp](https://stackoverflow.com/questions/25431821/execute-functions-in-parallel-using-openmp) – user202729 Jan 22 '21 at 08:51

1 Answers1

1

You can use parallel sections.

#pragma omp parallel sections
{
   #pragma omp section
   YourMainApp ();

   #pragma omp section
   YourIndepFunction ();
}
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • TY. Can the above be done by having the independent function inside the main app? – j riv Nov 27 '10 at 14:14
  • They both should run in independent threads. But I guess ultimately it's actually up to the OpenMP implementation... – Pablo Santa Cruz Nov 27 '10 at 14:15
  • [I edited the initial comment-question] Can the above be done by having the independent function inside the main app? – j riv Nov 27 '10 at 14:16
  • Nevermind, I opened a new question http://stackoverflow.com/questions/4292191/can-a-function-run-independently-inside-a-main-app-openmp and it answered my confusion. – j riv Nov 28 '10 at 08:15