PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

mcmodel question

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



Joined: 08 Feb 2011
Posts: 12

PostPosted: Wed Feb 09, 2011 2:05 pm    Post subject: mcmodel question Reply with quote

Hi,
When I compile the following f90 test program using optimization I get a segfault:

Code:

program bug_test
  integer, dimension(:,:), allocatable :: pc2n
  integer, dimension(:,:), allocatable :: tc2n

  allocate(pc2n(4,11835488)); pc2n = 0
  allocate(tc2n(4,153861344)); tc2n = 0

  pc2n(1:4,1:11835488) = tc2n(1:4,142025857: 153861344)

  deallocate(pc2n)
  deallocate(tc2n)
end program bug_test


I see the crash only when optimization is turned on(O2 or above or -fast). I know if I add -mcmodel=medium and the code seems to work but I feel that I shouldn't need that flag for the above code. Can anyone shed light on if this is a bug or if the above code should actually require the mcmodel=medium flag? Thanks a lot!
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Feb 09, 2011 3:08 pm    Post subject: Reply with quote

Hi Adam,

I'm assuming you're using PGI release 10.9 or earlier? If so, you need to add the flag "-Mlarge_arrays" to enable 64-bit array addressing since the array tc2n is greater than 2GB. The flag "-mcmodel=medium" enables "-Mlarge_arrays" by default.

Note in the 2011 release, we enabled 64-bit addressing by default so your program will no longer need to add "-Mlarge_arrays". "-Mlarge_arrays" is still needed when using arrays with a single dimension greater than 2GB.

Hope this helps,
Mat
Back to top
View user's profile
AdamSimpson



Joined: 08 Feb 2011
Posts: 12

PostPosted: Wed Feb 09, 2011 3:24 pm    Post subject: Reply with quote

Thanks for the reply, I am indeed using release 10.8. I suppose I am confused as to why it does work without the optimization if it's an addressing problem? I also am confused as I don't believe I have a dimension that is greater than 2 GB. Thanks very much for any help.
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Feb 09, 2011 4:31 pm    Post subject: Reply with quote

Hi Adam,

Quote:
I suppose I am confused as to why it does work without the optimization if it's an addressing problem?

At -O2, the compiler will store the addresses in 32-bit registers as opposed to fetching the base address from the stack and then doing the address calculation each time the elements are accessed.
Quote:

I also am confused as I don't believe I have a dimension that is greater than 2 GB.
While you don't have any single dimension over 2GB, the total size of your array is 2.29GB. Hence it needs 64-bit addressing.

Another way to think of this is that tc2n is really just one big area in memory. It starts at one address and ends at another, and the distance between the two addresses needs to be less than 2GB if using 32-bit addressing. To calculate the total size of your array, take the size of the first dimension (4) times the size of the second dimension (153861344), times the size of the data type (4). This comes to 2461781504 Bytes, or 2.29GB.

To clarify about "-Mlarge_arrays". In 10.9 and earlier, the flag enabled both 64-bit addressing and 64-bit indexing (i.e. the number of elements in a dimension can be greater than 2GB). In 11.0 and later, 64-bit addressing is enabled by default, while "-Mlarge_arrays" is still needed for 64-bit indexing.

I should also note that the above only applies to dynamically allocated arrays. For static arrays, the medium memory model (-mcmodel=medium) is still needed for both 64-bit addressing and indexing.

Hope this helps,
Mat
Back to top
View user's profile
AdamSimpson



Joined: 08 Feb 2011
Posts: 12

PostPosted: Wed Feb 09, 2011 5:59 pm    Post subject: Reply with quote

Perfect, Thanks for explaining everything.
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