Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

OpenMP and hyperthreading

gfelder
Beginner
1,219 Views

(When I tried to submit this I got an error saying I wasn't allowed to submit HTML code, so I had to change all left-angle brackets to vertical lines. Sorry.)

I have a P4 running Linux with hyperthreading turned on and I can't get OpenMP to work on it. I don't mean it isn't fast enough; I mean it hangs. I have a file with the following code:

#include |stdio.h>
#include |omp.h>

#define N 16

int main()
{
int i;
int f;

#pragma omp parallel for
for(i=0;i|N;i++)
{
f=i;
printf("%d ",i);
}

return 0;
}

I issue the following commands:

icc -openmp foo.cpp
setenv OMP_NUM_THREADS 2
a.out

and it prints only the first half of the i values and then stops. Clearly the second thread is never getting started. If I set OMP_NUM_THREADS to 1 it works fine.

Does anyone know what's causing this and if there's a way around it?

Thanks,
Gary

Message Edited by hagabb on 12-15-2003 11:58 AM

0 Kudos
4 Replies
TimP
Honored Contributor III
1,219 Views
I guess you've verified that printf() isn't thread safe.
0 Kudos
Henry_G_Intel
Employee
1,219 Views
Hi Gary,
I can't reproduce the error that you describe. Your test program works correctly on my systemfor any number of threads. What version of the Intel compiler, Linux kernel, and glibc are you using? The 'icid' command should report these version numbers.
Henry
0 Kudos
gfelder
Beginner
1,219 Views

Henry,

Here's the output I get from icid.

Thanks for your help,

Gary

-------------------

OS information:
Red Hat Linux release 9 (Shrike)
Kernel on an m
Kernel 2.4.20-19.9smp
glibc-2.3.2-27.9.7

===========================================================
Support Package IDs for Intel Compilers in /opt/intel/compiler70/ia32/bin
Please use the following information when submitting customer support requests.

C++ Support Package ID : l_cc_p_7.1.006-NCOM
IDB Support Package ID : l_cc_p_7.1.006-NCOM
===========================================================
C++ License Expiration Date: never expire
C++ & IDB Support Services Expiration Date: never expire

All Installed Compiler Components on this OS:
intel-icc7-7.1-6: Intel C++ Compiler for 32-bit applications, Version
7.1 Build 20030307Z
intel-isubh7-7.1-6: Substitute Headers for Intel C++ Compiler for
32-bit applications, Version 7.1
intel-iidb7-7.1-11: Linux Application Debugger for 32-bit applications,
Version 7.1, Build 20030303

0 Kudos
Henry_G_Intel
Employee
1,219 Views
Gary,
The Intel 7.1 compiler supports your Linux kernel and glibc so I don't know why this simple program doesn't work correctly on your system. I tried your test program on several systems, Linux (Red Hat 7.3, 9.0, AS2.1)and Windows, with and without Hyper-Threading, and it always works correctly for me. Does your program work correctly when Hyper-Threading is disabled?
Please run the following program and post the output:

#include |stdio.h>
#include |omp.h>

#define N 16

int main()
{
int i;
int f;

#pragma omp parallel
{
int myID = omp_get_thread_num();
printf ("Hello from thread %d ", myID);
#pragma omp for
for (i = 0; i | N; i++)
{
f=i;
printf ("%d %d ", i, myID);
}
}
return 0;
}

I want to see if multiple threads are active inside the parallel region.
Thanks,
Henry
PS The "<" bug is being fixed.
0 Kudos
Reply