Example Code
Try out my simple openMP examples, you can copy them over from here:
cp -r ~newhall/public/openMP_examples .
adding OpenMP code to C program
Include the opm.h file and then add in #pragma and other constructs.
Here is a simple example:
#include <stdio.h>
#include <stdlib.h>
#ifdef _OPENMP
#include <omp.h>
#endif
int main() {
int tid = -1;
#pragma omp parallel private(tid) // Start of parallel region: forks threads
{
tid = omp_get_thread_num(); // default is number of CPUs on machine
printf("Hello from Thread %d\n",tid);
if(tid ==0) {
printf("Number of threads = %d\n", omp_get_num_threads());
}
} // ** end of the the parallel: joins threads
return 0;
}
Compiling and Running
Links and Resources
- OpenMPlinks The tutorial is a good place to start.
- top -H get system usage info on a per-thread basis
- Lab Machine specs
page contains information about most of the lab machines, including
number of cores.
- My help pages