Hi,
Is there a known issue about pthreads and openMP not being compatible??
I saw someone raise the exact same issue on the OpenMP forum but he was
sent back to the gcc forum.
I have an FC6 machine running with:
gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)
I have a simple program spawning 2 threads, each of which executes a
simple loop using openMP.
This program is very unstable, sometimes it works, sometimes it just
enters a deadlock.
Without the openMP pragmas it works just fine.
I can also make it stable by doing :
omp_set_num_threads(1);
instead of:
omp_set_num_threads(2);
but that kind of defeats the purpose :-)
I've built a more recent gcc, no luck:
gcc version 4.3.1 (GCC)
Machine used has 2 CPUs:
====================
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 6
model name : Intel(R) Pentium(R) D CPU 3.20GHz
stepping : 2
cpu MHz : 3192.348
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 6
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca
cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm
constant_tsc pni monitor ds_cpl vmx cid cx16 xtpr lahf_lm
bogomips : 6387.66
clflush size : 64
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 6
model name : Intel(R) Pentium(R) D CPU 3.20GHz
stepping : 2
cpu MHz : 3192.348
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 6
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca
cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm
constant_tsc pni monitor ds_cpl vmx cid cx16 xtpr lahf_lm
bogomips : 6383.19
clflush size : 64
==================== omp_set_num_threads(1);
Here's the very simple program I use:
====================
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <pthread.h>
#define MAX_CNT 1000000
//
***************************************************************************
//
***************************************************************************
//
// Thread A
void *_threadA(void* arg)
{
int i;
int x = 0;
#pragma omp parallel for
for ( i = 0; i < MAX_CNT; i++ ) {
x += i;
}
printf("%s: %u\n", __FUNCTION__, x);
return NULL;
}
//
***************************************************************************
//
***************************************************************************
//
// Thread B
//
void *_threadB(void* arg)
{
int i;
int x = 0;
#pragma omp parallel for
for ( i = 0; i < MAX_CNT; i++ ) {
x += i;
}
printf("%s: %u\n", __FUNCTION__, x);
return NULL;
}
//
***************************************************************************
// ***************************** MAIN
****************************************
//
***************************************************************************
//
//
//
int main(int argc, char *argv[])
{
pthread_t a_thr;
pthread_t b_thr;
int status;
omp_set_num_threads(2);
//
------------------------------------------------------------------------
status = pthread_create(&a_thr,
NULL,
_threadA,
(void*) NULL );
if ( status != 0 ) {
printf("Failed to create thread A\n");
return (-1);
}
//
------------------------------------------------------------------------
status = pthread_create(&b_thr,
NULL,
_threadB,
(void*) NULL );
if ( status != 0 ) {
printf("Failed to create thread B\n");
return (-1);
}
//
------------------------------------------------------------------------
status = pthread_join(a_thr, NULL);
if ( status != 0 ) {
printf("Failed to join thread A\n");
return (-1);
}
status = pthread_join(b_thr, NULL);
if ( status != 0 ) {
printf("Failed to join thread B\n");
return (-1);
}
return 0;
}
====================
Compiled as follows:
g++ -pthread -fopenmp omp_test.c -o omp_test
Am I missing something obvious??
Thanks,
Emmanuel.