Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2158 Discussions

compilation problem with ifort in openmp

anupam_mu
Beginner
1,342 Views
hi everybody,
i am learning openmp programming now. my problem is with compilation the code.i use noncomercial version of ifort and icc

if i use ifort to compile the code i get a error message.

compile command:ifort -openmp -openmp_reprot2 -o file file.f90

*********************************************************************
this is the error message that i get:

fortcom: Severe: /tmp/ifort3FPGKi.f90, line 1: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error.
# 2 "2.f90"
^
compilation aborted for 1.f90 (code 3)
*********************************************************************
but with icc everything works

i am attaching the f90 program herewith:

PROGRAM HELLO
INTEGER:: NTHREADS, TID, OMP_GET_NUM_THREADS,&
& OMP_GET_THREAD_NUM

! Fork a team of threads giving them their own copies of variables
!$OMP PARALLEL PRIVATE(NTHREADS, TID) num_threads(np1)
! Obtain and print thread id
TID = OMP_GET_THREAD_NUM()
PRINT *, 'Hello World from thread = ', TID
! Only master thread does this
IF (TID .EQ. 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
N=OMP_GET_NUM_PROCS()
PRINT *, 'Number of threads = ', NTHREADS
PRINT *, 'N of Procs:',N
END IF
! All threads join master thread and disband
!$OMP END PARALLEL
END

if i dont use the -openmp_report2 in time of compilation the program get compiled.
but the print result for the OMP_GET_NUM_PROCS() is not right.

here is the output without -openmp_report2:

Hello World from thread = 0
Number of threads = 2
N of Procs: -2147483648
Hello World from thread = 1

i dont understand the print result of N.


but there is no problem with icc compiler.
0 Kudos
8 Replies
TimP
Honored Contributor III
1,342 Views
There have been bugs in the past, in -openmp_report2. Please make sure you are running a current version of the compiler. Your evaluation license should allow you to open am account on premier.intel.com and get updates for 30 days.
0 Kudos
Matt_Walsh
Beginner
1,342 Views

Here's an even simpler program to repro the problem...on my Linux machine with Ifort 8.0.039 I get the same '-2147483648' error.


PROGRAM omp_test
N = omp_get_num_procs()
WRITE (*,*) "omp_get_num_procfs = ", N
END

Note, this 'C' program works fine...

#include
#include
int main(void) {
int num_procs;
num_procs = omp_get_num_procs();
printf("num procs = %d ", num_procs);
return 0;
}

0 Kudos
anupam_mu
Beginner
1,342 Views
hi tim18,
thanks for your comments.
i am using ifort version 8.0, which is available free for noncommercial purpose. do you mean that this openmp problem is due to any bug in it.
other versions are not available free.
is there anyway out.
thanks
0 Kudos
Henry_G_Intel
Employee
1,342 Views
Hi,
Since OMP_GET_NUM_PROCS isn't declared, it's treated as a real function in your program even though the function returns an integer. Declare the OMP_GET_NUM_PROCS function to be integer and the problem goes away.
Best regards,
Henry
0 Kudos
TimP
Honored Contributor III
1,342 Views
Ideally, there should be a USE file including necessary OpenMP declarations.
0 Kudos
jose
Beginner
1,342 Views
I have te same compiler error, but I've declared the variables, or so I guess. I am compiling fortran applications with Ifort 8.0 and openmp in the hope to obtain executables that runs independent threads in every one of my two cpu's. I'm using intel fortran 8.0 for IA32 on a redhat 9.0 smp kernel. I have no problems compiling MPI codes that run on the two cpu's, but when using openmp, I can force the program to create any number of threads with the OMP_NUM_THREADS environment variable, but all the thread created go and run in the cpu 0. ssh I'm using ifort 8.0, kernel 2.40.20-8smp and the code is as:
C FILE: omp_hello.f
C DESCRIPTION:
C In this simple example, the master thread forks a parallel region.
C All threads in the team obtain their unique thread number and print it.
C The master thread only prints the total number of threads. Two OpenMP
C library routines are used to obtain the number of threads and each
C thread's number.
C SOURCE: Blaise Barney 5/99
C LAST REVISED:
C******************************************************************************
PROGRAM HELLO
real a(100000)
INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS,
+ OMP_GET_THREAD_NUM
isum=0
C Fork a team of threads giving them their own copies of variables
!$OMP PARALLEL PRIVATE(NTHREADS, TID)

C Obtain thread number
TID = OMP_GET_THREAD_NUM()
do 100 j=1,1000
do 100 i=1,100000
a(i)=sin(i*1.)
isum=isum+1
100 continue
PRINT *, 'Hello World from thread = ', TID
C Only master thread does this
IF (TID .EQ. 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
PRINT *, 'Number of threads = ', NTHREADS,isum
END IF
C All threads join master thread and disband
!$OMP END PARALLEL
END
It reports the right number of threads, but they run all in one cpu.
Also, option -openmp_report 2 gives an internalcompiler error.
Thanks for the help
Jose
0 Kudos
ClayB
New Contributor I
1,342 Views
Besides being declared correctly, in order to get correct results from most OpenMP API functions, they must be called from within a parallel region. The code that Jose has included does this and he gets correct results. An earlier poster had an example without any parallel region, but calls to OMP_GET_THREAD_NUM(). There are no OpenMP thread numbers unless the execution is within a parallel region. The same is true of finding the number of threads executing.
For Fortran 90, there is an OpenMP module that can be loaded through "USE omp_lib" or one can use the preprocessor #include "omp_lib.h".
--clay
0 Kudos
ClayB
New Contributor I
1,342 Views


jose@nuc2.fis.ucm.es wrote:
IF (TID .EQ. 0) THEN
NTHREADS = OMP_GET_NUM_THREADS()
PRINT *, 'Number of threads = ', NTHREADS,isum
END IF

Jose -

I'm surprised that Blaise Barney would write code this way. However, since this was written back in 1999, it is more understandable. Of course, a better way to write the above portion of the code would be

Code:
!$omp master
  NTHREADS = OMP_GET_NUM_THREADS()
  PRINT *, 'Number of threads =', NTHREADS, isum
!$omp end master

The assignment of threads to which processors on your system is something that the operating system is responsible for. I'm surprised that such a recent version of Red Hat Linux would be giving you such bad distribution.

The problem with using the -openmp_report 2 flag is something that is wrong with the compiler. This should be reported to Intel Premier Support (http://premier.intel.com).

--clay

0 Kudos
Reply