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.
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,