Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29341 Discussions

Namelist read corrupts dynamically allocated arrays?

longden_loo
Beginner
845 Views
Are there any known issues with Namelist reads affecting arrays initialized using the ALLOCATE command (IVF 11.1.038)?

When I converted a segment of code that previously used a hard-coded dimensioned array, to one created via ALLOCATE, the Namelist read to load values completes, but attempting to display the first element (via a PRINT) gets a complaint about the subscript "value 1 which is less than the lower bound of 2036491375".

Before the Namelist read, I added some test lines to manually assign values to the first element of the dynamically allocated array, and successfully PRINTed it. Then the code does the Namelist read and the PRINT that follows gets an error.

I can post code and data samples, but I thought to ask first to conserve bandwidth in case this is something well-known.

Thx, Longden
0 Kudos
4 Replies
Steven_L_Intel1
Employee
845 Views
I know of some issues with allocatable arrays in NAMELIST. One is an inappropriate error given in the declaration, which is not your issue. The other was reported as a segfault/access violation on a READ, which is more likely to be your issue. This latter issue is not yet fixed. Please do supply a test case so that we can be sure to get yours taken care of.
0 Kudos
longden_loo
Beginner
845 Views
I know of some issues with allocatable arrays in NAMELIST. One is an inappropriate error given in the declaration, which is not your issue. The other was reported as a segfault/access violation on a READ, which is more likely to be your issue. This latter issue is not yet fixed. Please do supply a test case so that we can be sure to get yours taken care of.

Test case (code, namelist input, console output) follows. I added an iostat to the namelist read but it didn't reveal any errors. The main driver simply calls nameListRead_static followed by nameListRead_dynalloc. Both subroutines read the same namelist file, but the first one has no problems while the 2nd one crashes. The 2nd one also includes a manual assigment of values to the dynamically allocated array and successfully PRINTs the result, followed by the namelist read where the subsequent PRINT crashes.

[plain]==> test case. Main driver simply calls nameListRead_static, followed by nameListRead_dynalloc. The first subroutine uses a hard coded dimension and the 2nd one dynamically allocates. Both use the same namelist file (below). The dynamic allocation version also does a test by manually assigning values to the array and displaying them before doing the namelist read.

      SUBROUTINE nameListRead_static
      INTEGER :: lin=5
      CHARACTER(30) :: listNames(2)

      NAMELIST / stuff  / listNames
      OPEN (LIN, FILE="listNames.dat", STATUS = 'OLD')
      READ(lin,stuff)
      close (lin)
      print *, "->", listNames(1), "<>", listNames(2)
      return
      end
      
      SUBROUTINE nameListRead_dynalloc
      INTEGER :: lin=5, ierr1=0, ierr2=0, ierr3=0
      CHARACTER(30), ALLOCATABLE :: listNames(:)
      IF( ALLOCATED( listNames ) ) then
         DEALLOCATE ( listNames, STAT = ierr1 ) 
 	  else
 	     ALLOCATE ( listNames(2), STAT= ierr2 )
	  ENDIF
	  print *, "allocation error codes->", ierr1, ierr2

      listNames(1) = "alpha"
      listNames(2) = "beta"
      print *, "->", listNames(1), "<>", listNames(2)
      
      NAMELIST / stuff  / listNames
      OPEN (LIN, FILE="listNames.dat", STATUS = 'OLD')
      READ(lin,stuff,iostat=ierr3)
      close (lin)
      print *, "read err code=",ierr3
      print *, "->", listNames(1), "<>", listNames(2)
      return
      end
      
===> namelist file (listNames.dat)
&stuff
listNames(1) = "hello                         "
listNames(2) = "goodbye                       "
/

===> console output
 ->hello                         <>goodbye
 allocation error codes->           0           0
 ->alpha                         <>beta
 read err code=           0
forrtl: severe (408): fort: (3): Subscript #1 of the array LISTNAMES has value 1
 which is less than the lower bound of 2036491375

Image              PC        Routine            Line        Source
libifcoremdd.dll   0447191A  Unknown               Unknown  Unknown
libifcoremdd.dll   0446B678  Unknown               Unknown  Unknown
libifcoremdd.dll   043EC150  Unknown               Unknown  Unknown
libifcoremdd.dll   043EC771  Unknown               Unknown  Unknown
DynamicSectors.ex  0040F8AB  Unknown               Unknown  Unknown
DynamicSectors.ex  0041DFBD  Unknown               Unknown  Unknown
DynamicSectors.ex  004F49C3  Unknown               Unknown  Unknown
DynamicSectors.ex  004F3668  Unknown               Unknown  Unknown
DynamicSectors.ex  004F34AF  Unknown               Unknown  Unknown
kernel32.dll       7C817077  Unknown               Unknown  Unknown[/plain]

0 Kudos
abhimodak
New Contributor I
845 Views
Hi

Most likely, I have missed an update to this thread and/or compiler documentation.

Just an FYI: The code-snippet below does the following:-

Compiler version 11.1.038

(1) With 11.1.038 allocatable array becomes undefined when explored in the debug mode; however the write statement writes the values correctly.
(2) If I use the release configuration, the write statement prints correct values.


The problem in (1) goes away in 11.1.046.

Sincerely
Abhi

--

Program Test_NameList

Implicit None

Integer, Parameter :: myFP = kind(1.0d0)

Integer, Parameter :: InputUnit = 21
Integer, Parameter :: N = 3

Real(myFP) :: A(N)

Real(myFP), Allocatable :: B(:)

NameList / Test/ A, B

Allocate(B(N))

Open(InputUnit, File='Test.inp', Form='Formatted', Status='Unknown')
Rewind(InputUnit)
Read(InputUnit, NML=Test)
Close(InputUnit)

Write(*,NML=Test)

End program Test_NameList


The contents of the input file "Test.inp" are:

&Test

A = 1.0d0, 2.0d0, 3.0d0

B = 4.0d0, 5.0d0, 6.0d0

/


0 Kudos
Steven_L_Intel1
Employee
845 Views
Seems to work in 11.1.046.
0 Kudos
Reply