How to compile OMP program in C-Linux

Hi,
I have written the following omp program in C language. I am getting some errors on compilation which I can't understand. Somebody please guide me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <omp.h>
void main(){
//Write  a multithreaded program that prints "hello World"
#pragma omp parallel
{

int ID = 0;
printf("hello(%d) ", ID);

printf("World(%d)\n",ID);
}
}




When I am compiling the code , I am getting following error messages:


$ gcc prg1.c -fopenmp
prg1.c: In function ‘main’:
prg1.c:5:21: error: expected ‘#pragma omp’ clause before ‘{’ token
#pragma omp parallel{
^
prg1.c:7:1: error: expected expression before ‘int’
int ID = 0;
^~~
prg1.c:8:22: error: ‘ID’ undeclared (first use in this function)
printf("hello(%d) ", ID);
^~
prg1.c:8:22: note: each undeclared identifier is reported only once for each function it appears in
prg1.c: At top level:
prg1.c:12:1: error: expected identifier or ‘(’ before ‘}’ token
}


Some body please guide me.

Zulfi.
Last edited on
Is this yet another avenue to solve your concurrency issues?
http://www.cplusplus.com/forum/unices/251211/
Hi,

Yes you are right.

I am studying a parallel programming course.

Some body please provide me the solution.

Zulfi.

Hi,
I solved this problem:

gcc -fopenmp prg1.c


Zulfi.
Topic archived. No new replies allowed.