views:

40

answers:

2

I have a functioning implementation of a MPI routine, which works fine. In the process of making this a hybrid between MPI and shared memory, I am using pthreads. This in turn proofed the need of pthread_barriers.

But when I try to compile my code with the mpicc compiler, it complains over pthread_barrier_t and other barrier commands. If I remove these, and keep other threading parts it compiles just fine.

This is the line of code I insert to break the compilation:

pthread_barrier_t* barrier;

And for compilation I use:

mpicc -lm myprogram.c -o myprogram

The error returned from the compiler is:

myprogram.c:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Where line 34 corresponds to what I wrote above.

[Edit] I am runnings this on Ubuntu 9.10, with the following gcc/mpicc compiler: gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1. [/Edit]

Does anyone know what could be wrong and how I can make it compile?

Cheers!

+1  A: 

Hello, pthread_barrier_t is part of the ADVANCED REALTIME THREAD option, so it might not be available on your system. BTW, if you pose such a specific question you should always mention OS, version number and things like that.

Jens Gustedt
Ok. How do I find out, wheter this is a part of my system or not - and if not, how do I get support for it, and can I?I have added os and compiler version to my questing. Thanks!
R Hoof
yes on ubuntu it should be in. do `man pthread_barrier_wait` to know the includes you need to specify etc
Jens Gustedt
Ah, also you should give the error that gcc gives you. I vaguely remember that in some version you could not call a variable `barrier` because they had defined a macro by that name in some system includes. Perhaps rename it to something else just to see.
Jens Gustedt
Tried with another barrier name :) --Ill look more into the man page...
R Hoof
+1  A: 

This means that pthread_barrier_t type is not in scope. Have you #include'd pthread.h?

Roman Cheplyaka
Yes, or else I would not be able to compile all the other thread stuff...
R Hoof
Can you provide some minimal example of the code which doesn't compile?Cause this one compiles perfectly:#include <pthread.h>int main () { pthread_barrier_t* barrier; return 0;}
Roman Cheplyaka
Which compiler? and on what system? That wouldn't compile on my system using mpicc..
R Hoof
Wow. Does it produce the same error message? Does it compile using pure gcc, not mpicc?Mine is Debian Squeeze, gcc 4.4.4, and MPICH2 1.2.1.1. I also tried it on an Ubuntu 9.04 box, gcc 4.3.3 (but without mpicc), also ok.
Roman Cheplyaka
Sorry Roman, I was a bit quick there. It does indeed compile - just missed the stdlib :)I will try to make a larger small scale example of my code, to see when it breaks...
R Hoof
I reduced it, and found out it is actually the "std=c99" option that makes it fail... The above mentioned:#include <pthread.h> int main () { pthread_barrier_t* barrier; return 0; }Cannot compile with c99 - any idea why?
R Hoof
Use `gcc -std=c99 -D_XOPEN_SOURCE=600` to compile your source.
Roman Cheplyaka