This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with procedure pointers passed as arguments


Hi Andrew,

> OK - I've succeeded in making a test case which demonstrates the problem.

thanks. I can now reproduce the bahavior you're seeing with gfortran 4.4.


> It seems that I get a null pointer back in some cases even when it should be
> associated. Actually, it seems that in this test case I get the same crash
> even when running without OpenMP (in the original code, this problem seems to
> arise only when I compile for OpenMP).

Confirmed. However, with the code you sent, the problem is only seen
on machines with more than four cores due to "if (omp_get_thread_num()
> 3)". So I modified it a bit for testing [these days not everyone has
a hexacore machine in their living room yet, I guess]. This version
here fails with any number of cores and in fact also when compiled
without -fopenmp:

program test
  use OMP_Lib
  implicit none

  !$omp parallel
  do while (.true.)
     call Do_Inter_Go
  end do
  !$omp end parallel

contains

  subroutine Do_Inter_Go
    procedure(), pointer :: assignedProc
    assignedProc => null()
    call Get_Proc(assignedProc)
    !$ print *,omp_get_thread_num(),loc(assignedProc)
    call assignedProc()
  end subroutine Do_Inter_Go

  subroutine Get_Proc(assignedProc)
    procedure(), pointer, intent(out) :: assignedProc
    call Give_Me_A_Proc(assignedProc)
  end subroutine Get_Proc

  subroutine Give_Me_A_Proc(assignedProc)
    procedure(), pointer, intent(out) :: assignedProc
    assignedProc => Proc_To_Call
  end subroutine Give_Me_A_Proc

  subroutine Proc_To_Call
    print *,'do task'
  end subroutine Proc_To_Call

end program test


While failing with gfortran 4.4, it actually works with the current
trunk (soon to be gfortran 4.5). As documented on
http://gcc.gnu.org/wiki/ProcedurePointers, a couple of procedure
pointer bugs have been fixed only after the release of gfortran 4.4.
I'm guessing the failure we're seeing here is due to
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40450.

So, you're advised to try a recent build of gfortran 4.5 trunk. We're
close to the 4.5 release already, so the trunk should be in a rather
stable and usable state. Various binaries are available at
http://gcc.gnu.org/wiki/GFortranBinaries. Alternatively, you might
wanna build gfortran yourself (from source).

Cheers,
Janus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]