Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29298 Discussions

ifort+openmp evaluates ASSOCIATED on empty pointer to TRUE

wimr
Beginner
526 Views
Hi,
I am experiencing some problems when compiling my code with the -openmp flag, even in parts where there is no OpenMP presents. To illustrate one problem, I wrote the small code below. I'm on Mac OS X 10.6.6 and the problem occurs for me with ifort11.1.067 and also with 12.0.0.085
When I compile in debug mode, using ifort -g -FR test.f90, the program performs as expected: the ASSOCIATED(adata) inside the subroutine alloc returns false and so the array is being allocated, and the subroutine returns. When I add the openmp flag (even though there is no openmp code here) to the compilation options, I get the following output:
inside alloc, testing associated
Adata associated
Size: 1606416640 0
Deallocation with status 173
Allocation with status 0
End program
For some reason, the ASSOCIATED returned a TRUE, and the code continues with deallocating the pointer from which it returns an error code.
Is there something wrong with the code I wrote in terms of Fortran rules, that only shows up when I compile with -openmp? Or is this a compiler bug? By the way, the problem disappears without the -g flag.
Thanks!
[fortran]PROGRAM test

IMPLICIT NONE

INTERFACE alloc
   SUBROUTINE alloc(adata,info)
     IMPLICIT NONE
     INTEGER, DIMENSION(:,:), POINTER :: adata
     INTEGER, INTENT(INOUT)  :: info
   END SUBROUTINE alloc
END INTERFACE alloc

INTEGER, DIMENSION(:,:), POINTER :: Npx
INTEGER  :: info

   CALL alloc(Npx,info)

   DEALLOCATE(Npx)
   WRITE(*,*) 'End program'
END PROGRAM


SUBROUTINE alloc(adata,info)

IMPLICIT NONE

INTEGER, DIMENSION(:,:), POINTER :: adata
INTEGER, INTENT(INOUT)  :: info

   WRITE(*,*) 'inside alloc, testing associated'
   IF(ASSOCIATED(adata)) THEN
      WRITE(*,*) 'Adata associated'
      WRITE(*,*) 'Size: ',Size(adata,1),Size(adata,2)
      DEALLOCATE(adata,STAT=info)
      WRITE(*,*) 'Deallocation with status ',info
      NULLIFY(adata)
   END IF

   ALLOCATE(adata(10,10),STAT=info)
   WRITE(*,*) 'Allocation with status ',info

END SUBROUTINE alloc[/fortran]
0 Kudos
4 Replies
Steven_L_Intel1
Employee
526 Views
The association status of your pointer is "undefined", therefore the result of calling ASSOCIATED is also undefined. If you want Npx to start out as unassociated, add => NULL() to its declaration.
0 Kudos
wimr
Beginner
526 Views
Dear Steve,
That's it. Calling ASSOCIATED on undefined pointers has not affected my code until now, so I had a hard time finding out that this was what made my code fail with OpenMP. Sinceit's a bad thing to have in my code anyway, I will fix it now. Thanks a lot for your quick answer.
0 Kudos
Steven_L_Intel1
Employee
526 Views
Glad to hear it. By the way, I tried using the compiler's Static Security Analysis feature, used in conjunction with Intel Inspector XE, and it identified the uninitialized variable.
0 Kudos
mriedman
Novice
526 Views
If you need thread safe code then youmust notnullify in the declaration because that makes the pointer implicitly persistent und thus thread unsafe(like SAVE).

It's inconvenient butthenullify must be done seperately.
0 Kudos
Reply