Community
cancel
Showing results for 
Search instead for 
Did you mean: 
lokida
Beginner
61 Views

Kernel Resource Leak with intel Fortran

Hi,

I have a simple program in Fortran thaht I have copy from a tutorial web site. I use intel Fortran 11.1 on windows XP 32 bits. I have tested Intel Inspector XE 2011 Update 5 on this program and I have Kernel Resource Leaks on print, open and read.

I use this example because on my own program I have the same Kernel Resource Leaks on open and close function. So this program is just to test intel inspector.
Source: http://www.math.hawaii.edu/~hile/fortran/fort7.htm#open


[fortran]	program divisors
! 	This program finds the divisors of an integer input by the user.
! 	The divisors are printed to a file.
	integer n, k, d(10)
	open (unit = 1, file = "divisors")
	print *, "Enter a positive integer :"
	read *, n
	write (1,*) "Here are the divisors of ", n, " :"
	k = 0
	do i = 1, n
		if (mod(n,i) .eq. 0) then
			k = k + 1
			d(k) = i
		end if
		if (k .eq. 10) then
			write (1,5) (d(j), j = 1, 10)
			k = 0
		end if
	end do
	write (1,5) (d(j), j = 1, k)
  5 	format (10i7)
	close (1)
	print *, "The divisors are listed in the file 'divisors'. Bye."
	end[/fortran]



Does Someone can tell me if it 's normal or not to have these Kernel Resources Leaks ?
Thank you.
0 Kudos
9 Replies
Peter_W_Intel
Employee
61 Views

Thanks for your test program.
I'm using Inspector XE 2011 Update 5, build 180252
I'm using Intel Visual Fortran Composer XE 2011, Update 4.
I used "mi1", "mi2", "mi3" to get different results.

"mi3" - it reported, kernel resource leak at malloc.c; it located at getenv.c:83 when doing _heap_alloc_base. Such kind of issues can be ignored in my view

"mi2" - no probelm was reported.

"mi1" - it reported 3 memory leaks, which were called by mainCRTStartup, initializing stage. They could be are Inspector XE's bugs or can be ignored
It also reported 5 kernel resource leak; onewas heapinit related, onewas ioinit related, other 3 kernel resource leaks locates at divisor.f90 source - which locates at linescontaining "open", "printf", "read" statements.

I will talk with developer about these, and get back as soon as I can.

Thanks, Peter

======================================================

C:\zwang\temp\divisors\Debug>inspxe-cl -collect mi3 -- divisors.exe
Used suppression file(s): []
Enter a positive integer :
128
The divisors are listed in the file 'divisors'. Bye.

1 new problem(s) found
1 Kernel resource leak problem(s) detected

C:\zwang\temp\divisors\Debug>inspxe-cl -collect mi2 -- divisors.exe
Used suppression file(s): []
Enter a positive integer :
128
The divisors are listed in the file 'divisors'. Bye.

0 new problem(s) found

C:\zwang\temp\divisors\Debug>inspxe-cl -collect mi1 -- divisors.exe
Used suppression file(s): []
Enter a positive integer :
128
The divisors are listed in the file 'divisors'. Bye.

8 new problem(s) found
5 Kernel resource leak problem(s) detected
3 Memory leak problem(s) detected

Peter_W_Intel
Employee
61 Views

The workaround is to do:

Add divisors.exe into "Include only the following module(s)" in tab "Target" of Project Properties"

Thus, all memory/resource leaks (at process startup)will not be reported.

Regards, Peter

=========== For command line ========================

C:\zwang\temp\divisors\Debug>inspxe-cl -collect mi1 -module-filter-mode=include
-module-filter=.\divisors.exe -- divisors.exe
Used suppression file(s): []
Enter a positive integer :
128
The divisors are listed in the file 'divisors'. Bye.

0 new problem(s) found

lokida
Beginner
61 Views


Thank you for the help.

So, I have set real(8),allocatable :: x(:) and allocate (x(2048)) (Ihaven't set deallocate (x) because I want to see if the memory leak will be detected) in the code.

Without the use of the modification, ("Add divisors.exe into "Include only the following module(s)" in tab "Target" of Project Properties") Inspector detects the memory leak.

When using the modification Inspector detects nothing !

May be I am doing something wrong ?


Peter_W_Intel
Employee
61 Views

Quoting lokida

Thank you for the help.

So, I have set real(8),allocatable :: x(:) and allocate (x(2048)) (Ihaven't set deallocate (x) because I want to see if the memory leak will be detected) in the code.

Without the use of the modification, ("Add divisors.exe into "Include only the following module(s)" in tab "Target" of Project Properties") Inspector detects the memory leak.

When using the modification Inspector detects nothing !

May be I am doing something wrong ?


Please attach modified code - I will investigate why Inspector XE can't detect memory leak(s) when using Add divisors.exe into "Include only the following module(s)".

Thanks, Peter

lokida
Beginner
61 Views

Hi, Here's the code. It is the same as above but I have declared an array x and use deallocate (I have commented deallocate to be sure to detect the memory Leak.

[bash]	program divisors
! 	This program finds the divisors of an integer input by the user.
! 	The divisors are printed to a file.

    real(8),allocatable :: x(:)
    
	integer n, k, d(10)
	open (unit = 1, file = "divisors")
	print *, "Enter a positive integer :"
	read *, n
	write (1,*) "Here are the divisors of ", n, " :"
	k = 0
	do i = 1, n
		if (mod(n,i) .eq. 0) then
			k = k + 1
			d(k) = i
		end if
		if (k .eq. 10) then
			write (1,5) (d(j), j = 1, 10)
			k = 0
		end if
	end do
	write (1,5) (d(j), j = 1, k)
  5 	format (10i7)
	close (1)
	print *, "The divisors are listed in the file 'divisors'. Bye."
	

    allocate (x(2048))
 !   deallocate (x)
    
	end[/bash]
Peter_W_Intel
Employee
61 Views

Yes. This is an additional concern.

I will get back to you if we found a solution.

Thanks, Peter

lokida
Beginner
61 Views

Hi,

I use a free 30 days trial. I wanted to test the solution. So, I am not sure that when the "problem" will be fixed, I could use Inspector.
Peter_W_Intel
Employee
61 Views

The results after investigatin are:

"The missing leak problem, dynamically allocated arrays (allocatable) never leaks in Fortran 95 or later since the compiler will put the garbage collect code automatically. Memory Checkeractually see those deallocations even it's not explicitly called."

It could be accepted that report has no memory leak item, I checked the doc -
When the execution of a procedure is terminated by execution of a RETURN or END statement, an allocatable variable that is a named local variable of the procedure retains its allocation and definition
status if it has the SAVE attribute or is a function result variable or a subobject thereof; otherwise, it is deallocated.

Pleaseuse latest Update 7 - which has other problems fixed. Thank you.

Not applicable
61 Views