Hello, I've been learning OpenMP by reading Using OpenMP: Portable Shared Memory Parallel Programming by Chapman et. al.
I've been trying to get the following example in the book to work, using the atomic construct. Here is an example from page 92 of said book.
I fixed a mistake in the text. They give
if I try compiling it with gcc -fopenmp file.c, I get the following error:
file.c:16: error: invalid operator for '#pragma omp atomic' before '=' token
However if I change
to
it compiles and runs just fine. I've tried this with gcc-mp-4.4 and gcc-mp-4.5 (which are versions 4.4.6 and 4.5.3 respectively) and I get the same problems. These compilers were downloaded from macports. Am I missing something or is the text I'm using incorrect in its usage of the atomic construct. Perhaps the compilers I'm using do not meet the OpenMP standard. Any insight would be appreciated.
I've been trying to get the following example in the book to work, using the atomic construct. Here is an example from page 92 of said book.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main(){
int ic, i, n;
ic = 0;
n = 10;
#pragma omp parallel shared(n, ic) private(i)
for(i=0; i<n; i++)
{
#pragma omp atomic
ic = ic +1;
}
printf("Counter = %d\n",ic);
return 0;
}
I fixed a mistake in the text. They give
Code:
for(i=0; i++, i<n)
if I try compiling it with gcc -fopenmp file.c, I get the following error:
file.c:16: error: invalid operator for '#pragma omp atomic' before '=' token
However if I change
Code:
ic=ic+1;
Code:
ic++;