PDA

View Full Version : Fortran 95 - Segmentation Fault




huskrfreak88
Oct 17, 2008, 12:12 AM
I am going CRAZY for a solution to this problem! Hopefully these outputs are of some help to you, however if not, please specify what more you would like and I can attempt to do it!

To further elaborate on the problem described above. The Segmentation Error occurs when j =9,10,11 but ONLY after the sub-routine is called. There is some kind of error going back to the main program when j = 9, 10, or 11. If the subroutine is NOT called while j=9,10,11 the program will finish, however if the subroutine is called while j is any of those values, I get a segmentation fault. Hopefully this can point out the problem?

CODE: www.derekjohansen.com/code/bloodtest_WRITES.f95
SUCCESS RUN: www.derekjohansen.com/code/successful_run.txt



lee1210
Oct 18, 2008, 03:36 PM
This is the line with the problem:

array(x) = sum(temp_array)


You surely mean:

array(k) = sum(temp_array)


You write far enough past the end of array, eventually, that you crush the stack (that's what it looked like to me, at least). When that happens, the address of some local variables now point to 0xfffffffa and things, and when a read is attempted from this address... crash.

Also, why not make group_two an internal subroutine? It will save you room on the stack, as you are essentially just using the same variables? Since it's all by reference, it's not that much space, but it still seems clearer. You also pass infected, with a dimension of 10000, to infected_array with dimension of 100. Did you mean to pass an array slice of infected to group_two?

-Lee