Error running FORTRAN code

Thread Tools Search this Thread
Top Forums Programming Error running FORTRAN code
# 8  
Old 07-05-2011
This doesn't seem to be too bad, but I think the app should be in c++, or an interpreter language, and not Fortran. Unfortunately I am getting ready for a conference and a grant meeting, so I may not be able to work much on this until later in the month.

Please let me know if you need it right away and I will see what I can do.

# 9  
Old 07-06-2011
Please take your owm time.
# 10  
Old 07-07-2011

I looked over the code that you posted. It contains ALLOCATE statements, so I think you can ignore LMHmedchem comments about array declarations, because that is the Fortran-77 way of doing things. Fortran-90 and later use modern techniques for dynamic storage.

My take is different from LMHmedchem's in that I think a bird in the hand is worth two in the bush -- so you have a Fortran code, you might as well use it, as opposed to writing something new in a different language.

I considered the possible problems from too many files being open, so I wrote two test codes. The first simply opens files associating with "unit=1", but never explicitly closing them. The second opens files concurrently, associating with unit=n, where n varies. Both read a value from the file and the second goes back to read the first data file to make sure that the first file is still open and accessible.

I tried these codes with 2000 data files. "data0011 - data2010". The data files have a unique integer number in them (basically the sequence), and then the negative of that (number+1). Both test programs worked as I expected, without error.

I do agree with LMHmedchem that "Most likely, you are exceeding the capacity of some data structure that stores the contents of the files ...".

I will demonstrate a technique for identifying such errors in a subsequent post ... cheers, drl

---------- Post updated at 11:09 ---------- Previous update was at 10:57 ----------


I wrote the following code to demonstrate how ALLOCATE can obtain storage dynamically, but the array is still subject to being over-run:
     program f1

! @(#) f1	Demonstrate Fortran-95.

       real, allocatable :: x(:)

       write (*,*) " Hello, world from Fortran-95."
       allocate (x(1))

       x(1) = 1.0
       write(*,*) " x(1) is ",x(1)

! For the loop below:
! 1)
! both gfortran, g95 -- beyond 6 one gets:
! glibc detected *** ./a.out: free(): invalid next size (fast)
! ifort (compiling name.90 -- beyond 7 yields:
! glibc detected *** ./a.out: double free or corruption

! 2)
! gfortran -fbounds-check:
! At line 19 of file one.f95
! Fortran runtime error: Array reference out of bounds for array
! 'x', upper bound of dimension 1 exceeded (2 > 1)
! g95 -fbounds-check:
! At line 25 of file one.f95
! Traceback: not available, compile with -ftrace=frame or -ftrace=full
! Fortran runtime error: Array element out of bounds: 2 in (1:1), dim=1
! ifort -check bounds two.f90
! forrtl: severe (408): fort: (2): Subscript #1 of the array X
! has value 2 which is greater than the upper bound of 1

       do i = 2, 6
         x(i) = float(i)
       end do


This was run in the following context:
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
GNU bash 3.2.39
gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
G95 (GCC 4.0.3 (g95 0.92!) Jun 24 2009)
ifort (IFORT) 11.1 20090827

The results are part of the comments above. The first section shows that errors occur when the array is over-run sufficiently. However, if one enables bounds-checking, the error is caught immediately.

Regrettably, the AIX box to which I have access does not have a Fortran compiler that I could find. However, I think IBM almost certainly will have provided a means to check for such errors, so you'll need to do a bit of reading for that.

Adding the bounds check may degrade performance, but it's such a easy change to make to see if that is the error, that your time will be well-spent.

Best wishes, and keep us updated ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Error in my FORTRAN program

I have a Fortran program and I am writing out to logical unit 7. The program is reading from a text file and writing to the new file formatted. It gets through the read and writes some to the file but then stops with the following error: 1525-013 The sequential WRITE statement cannot be... (5 Replies)
Discussion started by: KathyB148
5 Replies

2. Homework & Coursework Questions

FORTRAN error *** glibc detected ***

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I'm doing aproximation of derivative called five-point stencil. For every value of x, in interval , in step... (0 Replies)
Discussion started by: antonija
0 Replies

3. Programming

Strange characters in FORTRAN code output

Hi guys, After compiling a .f90 code and executing it, i get strange characters in the output file like : ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ Are these windows characters? how can i get rid of this? Much appreciated. Paul (1 Reply)
Discussion started by: Paul Moghadam
1 Replies

4. Programming

Removing goto statements in FORTRAN code

I have the code below and I want to remove the "go to" statements. Any idea how I can do it? if (iorder == 0) then tmincurrent = 1.0e11 if(ireverse == 0 .or. istop /= 1) then do i = 1, 6 if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then ... (1 Reply)
Discussion started by: kristinu
1 Replies

5. Programming

Using Doxygen on Fortran code

I am using doxygen for documenting my fortran code. I want to write some notes after the header in different parts of the subroutine. Any idea what the tags should be as anything I write after the header is not displayed ... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Programming

Help with make this Fortran code more efficient (in HPC manner)

Hi there, I had run into some fortran code to modify. Obviously, it was written without thinking of high performance computing and not parallelized... Now I would like to make the code "on track" and parallel. After a whole afternoon thinking, I still cannot find where to start. Can any one... (3 Replies)
Discussion started by: P_E_M_Lee
3 Replies

7. UNIX and Linux Applications

Getting error code when running the script 2 (RC)2

hi All, we have a script to remove the files from particular path,when we tryingto run manually the script went to success and removed the files but the same script which is running by other team it got failed and giving the error "2 (RC)2 "..what is the cause of the failure..and we passing the... (2 Replies)
Discussion started by: nagavenkatesh
2 Replies

8. Programming

Making FORTRAN code more efficient

Hi, I have a very large, very old FORTRAN code that I work with. The code is quite messy and I was wondering if I can speed up execution time by finding subroutines that code execution spends the most time in. Is there any kind of software I can use to see where the code spends most of the... (1 Reply)
Discussion started by: rks171
1 Replies

9. Programming

Error while running the C code

Hi Sir, I am running C program which include directfb.h header files. root@lxdevenv:~/Desktop# vi n.c root@lxdevenv:~/Desktop# gcc n.c -o n -I/usr/local/include/directfb -L/usr/local/lib -ldirectfb -lfusion -ldirect -lpthread -lm n.c: In function ‘main':... (2 Replies)
Discussion started by: Ravikishore
2 Replies
Login or Register to Ask a Question