Hi, I am using OpenMP to do multithreading with my nested loops. Since new to this stuff, I am not sure if I am using OpenMP in the correct way so that it can actually do the parallel programming. So I like to know if I can measure the performance of my C++ program that uses OpenMP so I can tell it actually works and I am on the right track? Like how many threads are running in parallel and how long it takes for each of them to finish. Thanks and regards!
+1
A:
You could use windows taskmanager (CTRL-SHIFT-ESC) on windows to monitor CPU usage, or top on *nix boxes.
Just check if many cores are used or not
Eric
2009-08-19 20:15:24
+1
A:
You can use your debugger (Visual Studio if you're on Windows) to:
- see how may threads are running
- see which code each of them is running
- pause some of them while letting others continue
RichieHindle
2009-08-19 20:47:26
Do you know how to do these with gdb / on Linux?
Tim
2009-08-19 20:58:26
This should help: http://www.delorie.com/gnu/docs/gdb/gdb_25.html See also the links at the bottom of that page. (Caveat: I found that with Google; I'm not a GDB user.)
RichieHindle
2009-08-19 21:15:27
On linux you can always use 'top' to see all of your cores, and check what they are doing.
Anna
2009-08-27 10:51:08
+3
A:
#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();
}
...
Obviously you need ot provide the two timer functions, but that's the gist. The OMP functions are pretty self-explanatory. Also make sure that your environment is set up properly and that you're compiling with the proper mechanisms. g++ option is -fopenmp. On Visual Studio go to project settings, C++, Language, and enable "OpenMP Support".
Brandon Pelfrey
2009-08-20 05:24:22