Example code... web resources, tutorials?
I've just started learning parallel processing and IMHO, there just isn't too much useful info on the net concerning parallel processing in general and OpenMP in particular. I did find one useful example as follows:
Code:
// openmp.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <time.h>
#include <float.h>
#include <math.h>
#include <windows.h>
#ifdef _OPENMP
#include <omp.h>
#endif
#define BOOL _Bool
#define true 1
#define false 0
// Matrix size constants
// Be careful to set your shell's stacksize limit to a high value if you
// wish to increase the SIZE.
#define SIZE 160 // Must be a multiple of 8.
#define M SIZE/8
#define N SIZE/4
#define P SIZE/2
#define NTIMES 5 // product matrix calculations
int main(void)
{
double a[M][N], b[N][P], c[M][P], walltime;
printf("here\n");
bool nthr_checked=FALSE;
time_t start;
int i, j, k, l, i1, i2, i3, k1, k2, k3, nthr=1;
printf("Using time() for wall clock time\n");
printf("Problem size: c(%d,%d) = a(%d,%d) * b(%d,%d)\n",
M, P, M, N, N, P);
printf("Calculating product %d time(s)\n", NTIMES);
// a is identity matrix
for (i=0; i<M; i++)
for (j=0; j<N; j++)
a[i][j] = 1.0;
// each column of b is the sequence 1,2,...,N
for (i=0; i<N; i++)
for (j=0; j<P; j++)
b[i][j] = i+1.;
start = time(NULL);
#ifdef _OPENMP
#pragma omp parallel private(i,j,k)
#endif
{
for (l=0; l<NTIMES; l++) {
#ifdef _OPENMP
#pragma omp single nowait
#endif
if (!nthr_checked) {
#ifdef _OPENMP
nthr = omp_get_num_threads();
#endif
printf( "\nWe are using %d thread(s)\n", nthr);
nthr_checked = true;
}
// Initialize product matrix
#ifdef _OPENMP
#pragma omp for nowait
#endif
for (i=0; i<M; i++)
for (j=0; j<P; j++)
c[i][j] = 0.0;
// Parallelize by row. The threads don't need to synchronize at
// loop end, so "nowait" can be used.
#ifdef _OPENMP
#pragma omp for nowait
#endif
for (i=0; i<M; i++) {
for (k=0; k<N; k++) {
// Each element of the product is just the sum 1+2+...+n
for (j=0; j<P; j++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
} // #pragma omp parallel private(i,j,k)
} // l=0,...NTIMES-1
walltime = time(NULL) - start;
printf("\nFinished calculations.\n");
printf("Matmul kernel wall clock time = %.2f sec\n", walltime);
printf("Wall clock time/thread = %.2f sec\n", walltime/nthr);
printf("MFlops = %f\n",
(double)(NTIMES)*(double)(N*M*2)*(double)(P)/walltime/1.0e6);
return 0;
}
I'm not sure where I found the above example. But IMHO, it's a good starting point to learn OpenMP.
Also, the best tutorials I have found so far are located at high performance computing link. I use the training material provided for the introduction to parallel processing and OpenMP. I'll be using this resource until I find something better.
Finally, the last time I checked, the MS Express edition compiler doesn't support parallel processing. You'll need the Professional edition or higher.