How to find out if OpenMP works in my C ++ program

I use OpenMP for multithreading with my nested loops. Since I'm new to this, I'm not sure if I'm using OpenMP correctly so that it can actually do concurrent programming. So I like to know if I can measure the performance of my C ++ program that uses OpenMP, so I can say that it works, and am I on the right track? Like how many threads work in parallel and how much time is required to complete each of them. Thank you and welcome!

+5
source share
3 answers
#include <omp.h>

...
int target_thread_num = 4;
omp_set_num_threads(target_thread_num);
unsigned long times[target_thread_num];

// Initialize all the times
#pragma omp parallel
{
   int thread_id = omp_get_thread_num();
   times[thread_id] = start_time();

   std::cout << "Thread number: " << omp_get_thread_num() << endl;

   times[thread_id] = end_time();
}
...

, , . OMP . , . g++ - -fopenmp. Visual Studio , ++, Language OpenMP.

+9

Windows taskmanager (CTRL-SHIFT-ESC) * nix-.

,

+1

(Visual Studio, Windows), :

  • , .
  • ., .
  • ,
+1
source

All Articles