Fortran - compilator dependent, intrinsic array manipulation, memory problem

In summary, the conversation discusses a code that applies cyclic rotation to a dynamically created array. However, when used for large values of n, a segmentation fault occurs. It is suggested that the issue may be related to the use of cshift and the creation of temporary arrays. Possible solutions include controlling the location of temporary arrays or increasing the stack memory limit. The behavior may differ depending on the compiler used.
  • #1
lacek
2
0
Welcome all,

I have a following code:

Code:
program aaaa
implicit none 

double precision, dimension(:), allocatable :: inp,outp
integer ::n,i

read(*,*) n

allocate(inp(n),outp(n))

write(*,*) allocated(inp), allocated(outp)

write(*,*) inp(1)
inp=cshift(outp,-size(outp)/2)
write(*,*) inp(1)

end program aaaa

It really does nothing - it just applies cyclic rotation of dynamically created array.
But when I use is for large n (in my case - over 10^6) then Segmentation fault occurs. More precisely this is the output:

Code:
T T
  0.000000000000000E+000
Segmentation fault

I also discovered that by increasing the limit for stack memory the segmentation fault can be avoided. Clearly I am using cshift not appropriately.

Additionally the code perform does not exists when the compilation is done with gfortran, but it exists with ifort v12.0.0.

What is going on? I tried to compile with -check all, but it provides no info.
 
Technology news on Phys.org
  • #2
I guess cshift() is creating a temporary array somewhere. That seems a reasonable thing for it to do, since it function doesn't "know" you are just assigning its output to another variable. For example your code might say something like
Code:
inp=(cshift(outp,1) + cshift(outp,2))/2

I think you need to find out if you can control where temporaries are created (on the stack or the heap) and/or how to make the stack big enough. Those things are compiler-dependent, which is why the defaults "work" for one compiler but not for the other.
 

Related to Fortran - compilator dependent, intrinsic array manipulation, memory problem

1. What is Fortran and how is it used in scientific computing?

Fortran is a high-level programming language commonly used in scientific and numerical computing. It was created in the 1950s and has evolved over the years to become one of the most widely used languages in the scientific community. Fortran is particularly useful for its efficient handling of complex mathematical computations and its ability to work with large datasets.

2. What does it mean for Fortran to be "compilator dependent"?

Fortran is a compiled language, meaning that it needs to be translated into machine code before it can be executed. However, different compilers may have different ways of optimizing and translating the code, which can result in slightly different outputs. This is known as "compilator dependency" and can be a source of errors or inconsistencies when working with Fortran code.

3. How does Fortran handle intrinsic array manipulation?

Intrinsic array manipulation in Fortran refers to the built-in functions and operations that are specifically designed to work with arrays (multi-dimensional data structures). These include operations such as array slicing, reshaping, and transposing, as well as mathematical functions like dot products and matrix multiplication. Fortran's efficient handling of arrays makes it a popular choice for scientific computing tasks that involve large datasets.

4. What are common memory problems encountered when using Fortran?

One common memory problem in Fortran is the issue of dynamic memory allocation, where the program must allocate and deallocate memory during runtime. This can be tricky to manage and can lead to memory leaks or other errors if not done correctly. Another issue is the use of pointers, which can cause problems if not properly initialized or if the memory they point to is not properly managed.

5. Are there any alternatives to using Fortran for scientific computing?

Yes, there are several alternatives to Fortran for scientific computing, including languages like C, C++, and Python. Each of these languages has its own strengths and weaknesses, and the choice often depends on the specific needs and preferences of the user. Some scientists also prefer to use a combination of languages, depending on the task at hand.

Similar threads

  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
692
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
5
Views
7K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
5
Views
12K
Back
Top