Undefined reference to `omp_get_wtime_' error

Hi Fortran experts here,

I am following source code from <>.
it has one module called toolbox with hundreds of subroutines.

I am using a cygwin system to run this code.

I am trying to run a program called prog02_02.f90
A: it uses toolbox.f90 module
B: I run gfortran -c toolbox.f90 prog02_02.f90
C: it generates: toolbox.mod, toolbox.o, prog02_02.o
D: I run: gfortran toolbox.o prog02_02.o
it give error message: undefined reference to `omp_get_wtime_’ error
see the screenshot attached.
if this error is something very common, I will appreciate if any expert can simply point out some solution to solve it.
I appreciate your time and help.

Martin

You have to link your program against OpenMP, using the -fopenmp flag for GNU Fortran.

1 Like

Hi Interkosmos,

It works. much appreciate your help.

The prog02_02.f90 is as below: I do not notice any mention of openMP, sorry for my basic question, I literally know nothing about parallel computing.

program lineqsys

use toolbox

implicit none

integer :: i, j

real*8 :: A(3, 3), b(3)

real*8 :: L(3, 3), U(3, 3)

! set up matrix and vector

A(1, :) = (/ 2d0,  0d0,  1d0/)

A(2, :) = (/ 0d0,  4d0,  1d0/)

A(3, :) = (/ 1d0,  1d0,  2d0/)

b       = (/30d0, 40d0, 30d0/)

! solve the system

call lu_solve(A, b)

! decompose matrix

call lu_dec(A, L, U)

! output

write(*,'(a,3f7.2/)')'    x = ', (b(j),j=1,3)

write(*,'(a,3f7.2/,2(5x,3f7.2/))') &

    ' L = ',((L(i,j),j=1,3),i=1,3)

write(*,'(a,3f7.2/,2(5x,3f7.2/))') &

    ' U = ',((U(i,j),j=1,3),i=1,3)

end program

Regards

Martin

The main program may not contain any OpenMP calls or directives, but one or more routines in the “toolbox” may. Look for an invocation of omp_get_wtime() in those routines, and verify that such an invocation is within !$omp directives and that the toolbox gets compiled with -fopenmp.

Hi Mecej4,

No mention of !$omp in the two subroutines called in the prog02_02. but I find
omp is mentioned in one toc subroutine with the line: time = omp_get_wtime()
which is exactly what the error message is about. but since it is not called by prog02_02, it is strange that it triggered the error message.

anyway, really appreciate your time and help

Martin

subroutine toc(file)

    use omp_lib  
        

    ! optional file identifier

    integer, intent(in), optional :: file        

    real*8 :: time

    integer :: outfile

    real*8 :: times(4)
   

    ! get cpu time

    time = omp_get_wtime()
  

    ! calculate time difference

    time = time - starttime_cpu
   
    ! get number of days

    times(1) = floor(time/(24d0*60d0*60d0))

    time = time - times(1)*24d0*60d0*60d0
 

    ! get number of hours

    times(2) = floor(time/(60d0*60d0))

    time = time - times(2)*60d0*60d0
  

    ! get number of minutes

    times(3) = floor(time/60d0)

    time = time - times(3)*60d0

    ! get number of seconds

    times(4) = time

    call outTime(times, outfile)

end subroutine toc

That statement is based on a misconception. Your program may itself contain no calls to the missing routine, and during a run the statement in the “toolbox” routine that contains the call to omp_get_wtime() may never be executed, but a linker may not care about that. Some linkers may work a bit harder to find out which listed external references are not needed, and avoid linking in those external references, and may do so only if requested with an appropriate flag.

you are right. since I am process the whole of toolbox module, not just the two subroutines.

thanks

Martin