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

Error severe (41) with function that returns deferred length characters

Samuel_D_
Beginner
1,130 Views
Hello all, I get a "severe (41): insufficient virtual memory" error when running the following code that use deferred-length character component, automatic allocation on assignment and a few other rather new Fortran features. The faulty code line(162) is : res = name // ' value is ' // str(foo) I believe that the length of the deferred-length character is 'lost in translation' hence the insufficient virtual memory error. Or maybe I'm doing something illegal but not reported by the compiler... The test case is quite complicated (could probably be simplified) : [fortran] module vstr_m type :: vstr_t character(len=:), allocatable :: str end type vstr_t interface assignment(=) module procedure op_assign_ch_vs module procedure op_assign_vs_ch end interface !assignment(=) interface operator(//) module procedure op_concat_vs_vs module procedure op_concat_ch_vs module procedure op_concat_vs_ch end interface !operator(//) interface len module procedure len_ end interface len contains elemental subroutine op_assign_ch_vs(var, exp) character(len=*), intent(out) :: var type(vstr_t), intent(in) :: exp var = exp%str end subroutine op_assign_ch_vs elemental subroutine op_assign_vs_ch(var, exp) type(vstr_t), intent(out) :: var character(len=*), intent(in) :: exp var%str = exp end subroutine op_assign_vs_ch elemental function op_concat_ch_vs (string_a, string_b) result (res) character(len=*), intent(in) :: string_a type(vstr_t), intent(in) :: string_b type(vstr_t) :: res res = op_concat_vs_vs(var_str(string_a), string_b) end function op_concat_ch_vs elemental function op_concat_vs_ch (string_a, string_b) result (res) type(vstr_t), intent(in) :: string_a character(len=*), intent(in) :: string_b type(vstr_t) :: res res = op_concat_vs_vs(string_a, var_str(string_b)) end function op_concat_vs_ch elemental function op_concat_vs_vs (string_a, string_b) result (res) type(vstr_t), intent(in) :: string_a type(vstr_t), intent(in) :: string_b type(vstr_t) :: res integer :: len_string_a, len_string_b len_string_a = len(string_a) len_string_b = len(string_b) !allocate(character(len=len_string_a+len_string_b) :: res%str) if (len_string_a > 0) then res%str = string_a%str // string_b%str else res%str = string_b%str end if end function op_concat_vs_vs elemental function var_str(char) result (res) character(len=*), intent(in) :: char type(vstr_t) :: res res%str = char end function var_str elemental function len_(string) result (res) class(vstr_t), intent(in) :: string integer :: res ! Get the length of a varying string if (allocated(string%str)) then res = len(string%str) else res = 0 endif end function len_ end module vstr_m module cast_m private integer, parameter :: MAX_BUFFER_SIZE=32 interface str module procedure :: int_to_string end interface str public :: str contains function int_to_string(i, fmt) result(res) implicit none integer, intent(in) :: i character(len=*), intent(in), optional :: fmt character(len=MAX_BUFFER_SIZE) :: buffer character(len=:), allocatable :: res !integer :: n if (present(fmt)) then write (buffer, fmt), i else write (buffer, '(I8)'), i endif !n = len_trim(adjustl(buffer)) !allocate(character(len=n) :: res) res = trim(adjustl(buffer)) end function int_to_string end module cast_m program test use :: vstr_m use :: cast_m implicit none integer :: foo type(vstr_t) :: name type(vstr_t) :: res foo = 123 name = 'Foo' res = name // ' value is ' // str(foo) print '(A)', res%str end program test [/fortran]
0 Kudos
9 Replies
pbkenned1
Employee
1,130 Views

Hello Samuel,

I believe this is a known issue.  Let me investigate a little, and I'll get back to you.

Patrick

0 Kudos
pbkenned1
Employee
1,130 Views

I can't reproduce your complaint with ifort-14.0.2.176 and default compilation switches, ie, 'ifort foo.f90'.

What compiler options are you using?

Patrick

0 Kudos
Samuel_D_
Beginner
1,130 Views
It's a default visual studio project build with the Debug/Win32 configuration that gives : ifort /nologo /debug:full /Od /warn:interfaces /module:"Debug\\" /object:"Debug\\" /Fd"Debug\vc110.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c Meanwhile I have just tested the same configuration as yours but with a different result : [plain] >ifort test.f90 Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.176 Build 20140130 Copyright (C) 1985-2014 Intel Corporation. All rights reserved. Microsoft (R) Incremental Linker Version 11.00.61030.0 Copyright (C) Microsoft Corporation. All rights reserved. -out:test.exe -subsystem:console test.obj >test.exe forrtl: severe (41): insufficient virtual memory Image PC Routine Line Source test.exe 000000013F0B13DC Unknown Unknown Unknown test.exe 000000013F10A8F6 Unknown Unknown Unknown test.exe 000000013F0F4008 Unknown Unknown Unknown kernel32.dll 00000000777E652D Unknown Unknown Unknown ntdll.dll 000000007791C541 Unknown Unknown Unknown [/plain]
0 Kudos
pbkenned1
Employee
1,130 Views

Meanwhile, I tested with your 32-bit debug options and still can't reproduce this.  Looks like we are both using Visual Studio 2012, but I doubt this has anything to do with VS2012.  The other issue I had with "insufficient virtual memory" could be reproduced from the command line.  But, I will check if that issue has a workaround.

C:\ISN_Forums\U507637>ifort /debug:full /Od /warn:interfaces /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs test.f90
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 14.0.2.176 Build 20140130
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:test.exe
-debug
-pdb:test.pdb
-subsystem:console
-incremental:no
test.obj

C:\ISN_Forums\U507637>test.exe


C:\ISN_Forums\U507637>

0 Kudos
Bernard
Valued Contributor I
1,130 Views

>>>I get a "severe (41): insufficient virtual memory" error when running the following code that use deferred-length character component, automatic allocation on assignment and a few other rather new Fortran features.

The faulty code line(162) is :

res = name // ' value is ' // str(foo)>>>

 

 

 

Could this message mean that some compiler allocated buffer is insufficient to hold the  string.

0 Kudos
pbkenned1
Employee
1,130 Views

OK, I can reproduce this in VS2012 using a 32-bit Debug build (and with 64-bit Debug build as well).  That's unusual -- it's rare to see an issue that can't be reproduced from a command prompt using the same compiler options VS defaults to for Debug builds.

I'll report this to the developers.

@iliyapolak -- presumably, but I don't know.

Patrick

 

0 Kudos
pbkenned1
Employee
1,130 Views

Tracking defect #DPD200254632.  I'll keep this thread updated with the progress to repair.

Patrick

0 Kudos
Samuel_D_
Beginner
1,130 Views
Thank you Patrick, The weird thing is that I could reproduce the pb from the command line as well using "ifort test.f90" as shown above. Seems that our command line prompts are not configured the same way since we are using the same compilers. My promt is the default one (the shortcut from Intel Fortran Installer). Iliyapolak, the strings are less than 10 characters in total. For me that's the compiler that lose the track of the length of the string and then, when doing the final assignment, try to allocate a random (large) deferred-length string... Hoping that makes sense !
0 Kudos
Bernard
Valued Contributor I
1,130 Views

@Samuel

Completely agree with your explanation.It definitely makes sense.

0 Kudos
Reply