I want to share data in an array between two programs. In another question I was advised to use an unformatted file for this, but I run into a problem when attempting this.
When I include this
OPEN(UNIT=10,FILE='all_paths.direct',FORM='UNFORMATTED', ACCESS='sequential', STATUS='unknown')
in the code, I get a Segmentation fault?
EDIT: Here the programme:
PROGRAM POSS_PATHS
use omp_lib
IMPLICIT NONE
INTERFACE
RECURSIVE SUBROUTINE bridge(start, goal, combined, a, b, interm, first)
USE hash_integer
USE locs_table
IMPLICIT NONE
INTEGER, DIMENSION(1:2), INTENT(IN) :: start, goal
INTEGER, DIMENSION(:,:), INTENT(INOUT) :: combined
INTEGER, DIMENSION(100), INTENT(INOUT) :: interm
INTEGER, INTENT(INOUT) :: a
INTEGER, INTENT(IN) :: b
INTEGER :: c
INTEGER :: i, k, j
INTEGER, DIMENSION(1:2) :: remainder, exact
INTEGER, DIMENSION(1:6) :: next, dflt
LOGICAL, INTENT(IN) :: first
END SUBROUTINE bridge
END INTERFACE
INTEGER, DIMENSION(1:8) :: beginning, ending
INTEGER, DIMENSION(1:2) :: start, goal
INTEGER, DIMENSION(100, 300000) :: combined
INTEGER, DIMENSION(100) :: interm
INTEGER :: i, j, k, l, a, b
OPEN(UNIT=33, FILE='all_paths', FORM='UNFORMATTED', ACCESS='sequential', STATUS='unknown')
DATA (beginning(i), i=1, 7) / 1, 2, 3, 4, 5, 6, 7 /
DATA (ending(i), i=1, 8) / 217, 225, 226, 227, 228, 231, 232, 233 /
a = 0
!$omp parallel
!$omp do
DO i=1, 7
DO j = 1, 7
DO k = 1, 8
DO l = 1, 8
a = a + 1
b = 1
start(1) = beginning(i)
start(2) = beginning(j)
goal(1) = ending(k)
goal(2) = ending(l)
combined(1:2,a) = start
CALL bridge(start, goal, combined, a, b, interm, .TRUE.)
END DO
END DO
END DO
END DO
!$omp end do
!$omp end parallel
WRITE(33, '(100I3)') combined
CLOSE(UNIT=10)
END PROGRAM
RECURSIVE SUBROUTINE bridge(start, goal, combined, a, b, interm, first)
USE hash_integer
USE locs_table
IMPLICIT NONE
INTEGER, DIMENSION(1:2), INTENT(IN) :: start, goal
INTEGER, DIMENSION(:,:), INTENT(INOUT) :: combined
INTEGER, DIMENSION(100), INTENT(INOUT) :: interm
INTEGER, INTENT(INOUT) :: a
INTEGER, INTENT(IN) :: b
INTEGER :: c
INTEGER :: i, k, j
INTEGER, DIMENSION(1:2) :: remainder, exact
INTEGER, DIMENSION(1:6) :: next, dflt
LOGICAL, INTENT(IN) :: first
remainder(1)= mod(start(1),8)
exact(1) = start(1) / 8
remainder(2) = mod(start(2),8)
exact(2) = start(2) / 8
DATA (dflt(i), i=1, 6) / 1000, 1000, 1000, 1000, 1000, 1000 /
c = b + 2
CALL hash_get(remainder, next, dflt)
DO k=1, 6, 2
next(k) = next(k)+(exact(1)*8)
next(k+1) = next(k+1)+(exact(2)*8)
IF((next(k) > goal(1) .AND. next(k+1) > goal(2)) .OR. next(k) > 233 .OR. next(k+1) > 233) THEN
CYCLE
END IF
interm(c:c+1) = next(k:k+1)
IF (next(k) == goal(1) .AND. next(k+1) == goal(2)) THEN
combined(1:c+1,a) = interm(1:c+1)
a = a + a
ELSE IF (next(k) > goal(1) .OR. next(k+1) > goal(2)) THEN
IF (first) THEN
CALL bridge(next(k:k+1), goal, combined, a, c, interm, .FALSE.)
ELSE
CYCLE
END IF
ELSE
CALL bridge(next(k:k+1), goal, combined, a, c, interm, .TRUE.)
END IF
END DO
END SUBROUTINE bridge
Using the same opening statement in another test programme does not cause a segfault