Memory Allocation issues in FORTRAN 90

In summary, you are having trouble allocating memory for a dynamic two dimensional array in FORTRAN 90. When you do the same thing using three on dimensional arrays instead of an array with the dimensions 3*x, you don't have a problem. It looks like you are trying to allocate memory for the same array -- input1 -- twice, and that is not allowed.
  • #1
ZackVM
3
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
  • #2
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?
 
  • #3
Why does your READ statement refer to two different I/O units?
 
  • #4
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!
 
  • #5


I understand the importance of efficient memory allocation in scientific programming. FORTRAN 90 is a high-level programming language commonly used in scientific computing, and it has specific methods for managing memory allocation.

Based on the provided code, it seems that the issue may be related to the size of the arrays being allocated. The first allocation statement creates an array with dimensions 3*ndat1, while the second one creates an array with dimensions 3*ndat2. If ndat1 and ndat2 have different values, it is possible that the second allocation statement is trying to allocate more memory than is available, resulting in the error message.

Additionally, using three one-dimensional arrays instead of one two-dimensional array may have worked because it requires less memory. It is also possible that the code for allocating the one-dimensional arrays is different and may have handled the memory allocation more efficiently.

To resolve this issue, I would suggest checking the values of ndat1 and ndat2 and making sure they are within the available memory. It may also be helpful to look into the specific methods for allocating memory in FORTRAN 90 and see if there are better ways to handle this type of situation. Additionally, using a debugger or memory profiler tool can help identify any potential memory leaks in the code.

I hope this helps in resolving the memory allocation issues in FORTRAN 90. As a scientist, it is important to carefully manage memory allocation to ensure efficient and accurate results in our scientific computations.
 

1. What is memory allocation in FORTRAN 90?

Memory allocation in FORTRAN 90 refers to the process of reserving and assigning memory space to program variables and data structures. This allows the program to store and manipulate data during runtime.

2. What are common memory allocation issues in FORTRAN 90?

Common memory allocation issues in FORTRAN 90 include memory leaks, where allocated memory is not properly released, and memory fragmentation, where the available memory is divided into small, unusable chunks due to repeated allocations and deallocations.

3. How can memory allocation issues be avoided in FORTRAN 90?

Memory allocation issues can be avoided in FORTRAN 90 by carefully planning and managing memory usage, using appropriate memory allocation functions, and properly deallocating memory when it is no longer needed.

4. What is the maximum amount of memory that can be allocated in FORTRAN 90?

The maximum amount of memory that can be allocated in FORTRAN 90 depends on the system and compiler being used. In general, it is limited by the available physical memory and address space of the system.

5. How can memory allocation issues be debugged in FORTRAN 90?

Memory allocation issues can be debugged in FORTRAN 90 using memory allocation tools and techniques, such as memory profilers, to track memory usage and identify potential problems. Debugging can also involve carefully examining the code for any errors or inconsistencies in memory allocation and deallocation.

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
4
Views
6K
  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Programming and Computer Science
Replies
4
Views
11K
  • Programming and Computer Science
Replies
10
Views
6K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
33
Views
4K
Back
Top