0

I want to create an array of 10^9 kind 8 integers in gfortran (Fortran f90 or f95).

I tried declaring it as follows

integer(kind=8) :: x(1000000000)

I expected it to compile but it doesn't. If instead of 1000000000 I use 100000000 it compiles without a problem. My machine has 64G RAM. What can I do?

EGME
  • 103
  • 3
  • 1
    Be aware that `kind=8` is not portable, see https://stackoverflow.com/questions/3170239/fortran-integer4-vs-integer4-vs-integerkind-4 Did the compiler show you any error message. If yes, you should definitely show it. – Vladimir F Героям слава Mar 31 '22 at 18:33
  • I cannot reproduce your problem. My gfortran compiles your arrays declaration just fine. Please show the complete code that shows the problem. See [mcve] and [ask]. Where you should get an error, is trying `(10000000000)` as that is a number too big for a 32-bit integer. But `(1000000000)` should be fine. We really need the error message and the code. – Vladimir F Героям слава Mar 31 '22 at 18:36

1 Answers1

1

Without seeing your code, I suspect you'll be happier as will your OS if you use the heap.

integer, parameter :: nx = 1000000000
integer(8), allocatable :: x(:)      ! Yes, I know 8 is not portable.
allocate(x(nx))
steve
  • 657
  • 1
  • 4
  • 7
  • Thank you. This worked very well. I did not post the code because I wasn't sure you could do that, I am new to this site. I am also "newish" to Fortran. I will soon post another question, hope you see it. – EGME Apr 01 '22 at 10:04
  • You're welcome. In general, we (those answering questions) want to see a minimum example code of what you're trying to do. In this case, advice was easy as you never want to declare a very large array as you were trying to do. – steve Apr 01 '22 at 14:04