I have built this with MinGW gfortran on Win32, but it crashes, no matter what input I use (mine or yours)

I introduced some write statements to trace its progress, and the fault appears to occur in routine BINDING_SQUARES

It looks like a problem with array indexing - someone is stepping on local memory!

BINDING_SQUARES has a rather ugly main loop (DO kcell = 1, bind_squares). The first few calls to this routine are well-behaved but then somewhere in that maze of "sudoku logic" code, the loop control variable kcell suddenly changes and so the loop control fails, and all hell breaks loose.

It either goes into an infinite loop, or crashes, which seems to indicate serious memory destruction (Code? Data?) is taking place.

I ran it with compiler option to check array bounds and hey presto, your SUM_ARRAY which has dimension 20, is quickly overflowing (as this log indicates):

Update pass = 0 , solved cells = 0

stage 1 solved_cells_final = 2

stage 2 solved_cells_final = 2

stage 3 solved_cells = 2

stage 4 solved_cells_Final = 2

-> Binding_squares

-> Binding_squares cage # 1

-> bind_squares = 2

sum_array( 1 ) = 7

sum_array( 2 ) = 8

sum_array( 3 ) = 9

sum_array( 1 ) = 2

sum_array( 2 ) = 3

sum_array( 3 ) = 4

-> Binding_squares cage # 2

-> bind_squares = 2

sum_array( 1 ) = 5

sum_array( 2 ) = 7

sum_array( 1 ) = 1

sum_array( 2 ) = 2

sum_array( 3 ) = 3

-> Binding_squares cage # 3

-> bind_squares = 4

sum_array( 1 ) = 16

sum_array( 2 ) = 17

sum_array( 3 ) = 18

sum_array( 4 ) = 17

sum_array( 5 ) = 18

sum_array( 6 ) = 19

sum_array( 7 ) = 18

sum_array( 8 ) = 19

sum_array( 9 ) = 20

sum_array( 10 ) = 19

sum_array( 11 ) = 20

sum_array( 12 ) = 21

sum_array( 13 ) = 17

sum_array( 14 ) = 18

sum_array( 15 ) = 19

sum_array( 16 ) = 18

sum_array( 17 ) = 19

sum_array( 18 ) = 20

sum_array( 19 ) = 20

sum_array( 20 ) = 21

sum_array( 21 ) = 22

sum_array( 22 ) = 21

sum_array( 23 ) = 22

sum_array( 24 ) = 23

sum_array( 25 ) = 18

sum_array( 26 ) = 19

sum_array( 27 ) = 20

sum_array( 28 ) = 19

sum_array( 29 ) = 20

.... etc

Your comment in code that "should never exceed 12" might be true for the number of

different values, but you don't check whether the sums being added to the list are already there. I had to bump the array to 1000 before I got through without error (cage #8 went up to 830 entries).

Since the main (in fact the only) purpose of this table is to get a min/max value for these sums, I made sum_table have 45 entries, and just flagged each sum being added, then Find_Min_Max just looks for the first and last non-zero entries.

Now I have successfully completed one pass of BINDING_SQUARES, I have a new error:

- Code: Select all
`At line 1058 of file moves-arithmetic.f90`

Fortran runtime error: Index '11' of dimension 1 of array

'non_overlap_cells_vertical' above upper bound of 10

And that's where I have to leave it, I'm afraid!