PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

malloc on Opteron?

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
abowden



Joined: 26 Oct 2004
Posts: 2

PostPosted: Tue Dec 14, 2004 3:22 pm    Post subject: malloc on Opteron? Reply with quote

I'm running into trouble with malloc on the Opteron. I understand size limitations, but this seems a little ridiculous - I've been unable to malloc an array larger than 10,000 words? Any ideas on what I'm missing? I'm using the default compilation flags (i.e., none). I'm running on a dual Opteron 250 box w/ 4 GB of RAM (linux kernel 2.4.21-15)

Thanks

For example the code snippet below works fine with iasize= 10000, seg faults with iasize=100000

program mymall

pointer (iaa,b(:))

iasize = 100000
iaa = malloc(4*iasize)

do 10 i=1,iasize
b(i)=0.0
10 continue

write(*,*)'success'
stop
end
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 5815
Location: The Portland Group Inc.

PostPosted: Wed Dec 15, 2004 1:31 pm    Post subject: Reply with quote

Hello,

This is a known problem but unfortunately there isn't a good solution.

The problem stems from the fact that the Fortran malloc function is not an intrinsic function and thus is implicity defined to be "INTEGER*4 malloc". Therefore, you must remember to explicitly declare "INTEGER*8 malloc" or compile with "-i8" to be consistant with the size of the returned 64-bit pointer.

The second and more difficult problem is that the argument for malloc is INTEGER*4 and is inconsistent with C's 64-bit malloc. Ideally, we could simply port the Fortran malloc to 64-bits by changing the argument data type to INTEGER*8. However, since integers are still implicity declared as INTEGER*4, doing so would require all users to make sure the actual argument's data type is INTEGER*8. Since most users would probablly be unaware of this change, doing so would end up breaking a lot of code.

A second possible solution is create the INTEGER*8 version of malloc and call it different name. Of course, the user would still need to explictiy declare it and make sure only INTEGER*8 arguments are used, but we could then presume that the user understood these requirements.

While we don't like to dictate how users code, the true solution to this problem is to not use malloc. Rather you should consider using Fortran 90's allocatable arrays. Below, I've modified your code to use an allocatable array.
Code:

  program mymall

!   pointer (iaa,b(:))
   pointer :: b(:)
   integer*8 iasize

   iasize = 1000000

!   iaa = malloc(4*iasize)
   allocate(b(4*iasize))

  do i=1,iasize
     b(i)=0.0
  end do
  write(*,*)'success'
  stop
  end


Thanks,
Mat
Back to top
View user's profile
abowden



Joined: 26 Oct 2004
Posts: 2

PostPosted: Sat Dec 18, 2004 3:18 pm    Post subject: Thanks Reply with quote

Hi Mat,
Thanks for the tip - it works on my code snippet, now I just have to apply to change to 250,000 lines of legacy Fortran code. Your help was very much appreciated.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group