- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using ifort to compile my Fortran source codes. There is a problem when running the one of the functions to allocate memories. The function 'rmalloc' returns an negative value, which is not correct, once the 'size' parameters is larger than 70000. There is no such error when the 'size' parameter less than 2260. Any suggestion is appreciated.
function rmalloc (size,at,total)
integer size,amount,idx,rmalloc,total
integer(C_INTPTR_T) ptr, block
dimension at(*)
pointer (ptr,a(1)),(block,b(1))
ptr = %loc(at)
amount = 4*size + 8
block = malloc(amount)
do i=1,size+1
b(i) = 0
enddo
rmalloc = (block - ptr)/4 + 1
total = total + amount/4
return
end
function rmalloc (size,at,total)
integer size,amount,idx,rmalloc,total
integer(C_INTPTR_T) ptr, block
dimension at(*)
pointer (ptr,a(1)),(block,b(1))
ptr = %loc(at)
amount = 4*size + 8
block = malloc(amount)
do i=1,size+1
b(i) = 0
enddo
rmalloc = (block - ptr)/4 + 1
total = total + amount/4
return
end
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using a 64-bit compiler? If so, your use of "integer" for block, etc. is wrong. I suggest declaring address-sized integers as:
integer(C_INTPTR_T)
where C_INTPTR_T is defined in intrinsic module ISO_C_BINDING.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. I am compiling the codes on the 64-bit system.The segment error happens when the 'size' parameter equals 70000, there is no such error when the 'size' parameter less than 2260.When I modify the 'ptr' and 'block' to use 'integer(C_INTPTR_T) ptr, block'. There is a compiling error like 'error #6683: A kind type parameter must be a compile-time constant. [C_INTPTR_T]'. I simplified the function like below.
function rmalloc (size,at,total)
integer size,amount,idx,rmalloc,total
integer(C_INTPTR_T) ptr, block
dimension at(*)
pointer (ptr,a(1)),(block,b(1))
ptr = %loc(at)
amount = 4*size + 8
block = malloc(amount)
do i=1,size+1
b(i) = 0
enddo
rmalloc = (block - ptr)/4 + 1
total = total + amount/4
return
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add:
use, intrinsic :: iso_c_binding
just after the "function" statement.
Did you edit the code in your initial post?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Steve. Yes, I simplified the intial post for easier to view. I tried adding intrinsic :: iso_c_binding rightbehind the 'function rmalloc (size,at,total)'. There is a compiling error says 'error #6407 This symbolic name is not an intrinsic function name or an intrinsic subroutine name [ISO_C_BINDING]'
Add:
use, intrinsic :: iso_c_binding
just after the "function" statement.
Did you edit the code in your initial post?
Quoting - Steve Lionel (Intel)
Add:
use, intrinsic :: iso_c_binding
just after the "function" statement.
Did you edit the code in your initial post?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You forgot the keyword "use".
use, intrinsic :: iso_c_binding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. You are right. I forgot the 'use'. Since this function is used by other main programs. Should I also define integer(C_INTPTR_T) for the variables which uses this function? Is this (C_INTPTR_T) same as I define integer *8 ptr, block for the 64-bit system? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should use this to declare any address-sized integer variables. It will select the proper size for 32-bit or 64-bit compilations.
However, if you name the variable as the pointer in an "integer POINTER" statement, as is shown currently in your source, you can skip declaring it entirely and the compiler will declare it to the correct size.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve. I tried this method. There are too many variables in the source codes. The major problem is that the source code is written in 32-bit, while our computing system is 64-bit now. Is there any method could run 32-bit code on 64-bit system without changing the source code.
You should use this to declare any address-sized integer variables. It will select the proper size for 32-bit or 64-bit compilations.
However, if you name the variable as the pointer in an "integer POINTER" statement, as is shown currently in your source, you can skip declaring it entirely and the compiler will declare it to the correct size.
Quoting - Steve Lionel (Intel)
You should use this to declare any address-sized integer variables. It will select the proper size for 32-bit or 64-bit compilations.
However, if you name the variable as the pointer in an "integer POINTER" statement, as is shown currently in your source, you can skip declaring it entirely and the compiler will declare it to the correct size.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would have to build with the 32-bit compiler, which is likely to require that you install additional 32-bit development components as specified in the Intel Fortran release notes.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page