Memory Allocation issues in FORTRAN 90

Click For Summary

Discussion Overview

The discussion revolves around issues related to memory allocation for dynamic two-dimensional arrays in FORTRAN 90. Participants explore the differences in behavior when using two-dimensional arrays versus multiple one-dimensional arrays, and address specific coding practices related to memory management and input/output operations.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant reports an error when attempting to allocate memory for a two-dimensional array, specifically noting that the second allocation fails with an error code of 5014.
  • Another participant questions the logic of allocating memory for the same array twice, suggesting that a different array should be used for the second allocation.
  • A later reply acknowledges a typo in the original code, clarifying that the participant was indeed trying to allocate memory for two different arrays, which resolved the issue.
  • Participants discuss the use of different I/O units for reading data from separate files, which is relevant to the context of the memory allocation issue.

Areas of Agreement / Disagreement

The discussion includes a mix of confusion and clarification, with initial disagreement about the allocation logic, but later consensus on the resolution of the issue through correction of a typo.

Contextual Notes

Limitations include the initial misunderstanding of the allocation process and the specific error codes, which may depend on the environment or compiler settings used for FORTRAN 90.

Who May Find This Useful

Readers interested in FORTRAN programming, particularly those dealing with dynamic memory allocation and file I/O operations in scientific computing contexts.

ZackVM
Messages
2
Reaction score
0
I'm having trouble allocating memory for a dynamic two dimensional array in FORTRAN 90; the odd thing is that when I did the same thing using three on dimensional arrays instead of an array with the dimensions 3*x, I didn't have a problem.

read (1,*) ndat1 !The first line of every file is the number of
read (2,*) ndat2 !rows of data.

allocate (input1(3,ndat1), STAT=AllocateStatus) !Allocating memory for input arrays.
if (AllocateStatus /= 0) STOP "first ***Not enough memory"
allocate (input1(3,ndat2), STAT=AllocateStatus)
if (AllocateStatus /= 0) STOP "***second Not enough memory"

When I run it, I get to 'second Non enough memory', and when I print out an error statement, I get 5014. Does anyone know what is going on? Thanks.
 
Technology news on Phys.org
ZackVM said:
I'm having trouble allocating memory for a dynamic two dimensional array in FORTRAN 90; the odd thing is that when I did the same thing using three on dimensional arrays instead of an array with the dimensions 3*x, I didn't have a problem.

read (1,*) ndat1 !The first line of every file is the number of
read (2,*) ndat2 !rows of data.

allocate (input1(3,ndat1), STAT=AllocateStatus) !Allocating memory for input arrays.
if (AllocateStatus /= 0) STOP "first ***Not enough memory"
allocate (input1(3,ndat2), STAT=AllocateStatus)
if (AllocateStatus /= 0) STOP "***second Not enough memory"

When I run it, I get to 'second Non enough memory', and when I print out an error statement, I get 5014. Does anyone know what is going on? Thanks.

It looks to me like you are trying to allocate memory for the same array -- input1 -- twice. Why aren't you using a different array for the 2nd call to allocate?
 
Why does your READ statement refer to two different I/O units?
 
Sorry, I was being dumb; I just didn't catch that typo. Thanks very much; it works now. I changed input1 to input2. I am reading from two separate files, and then building an array for each file, which is why I needed to I/O units. Thanks again!
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
12K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 20 ·
Replies
20
Views
6K
  • · Replies 8 ·
Replies
8
Views
4K