f2py随机崩溃

时间:2017-06-29 20:12:14

标签: python python-2.7 fortran fortran77 f2py

我对f2py有一个非常烦人的问题,我的代码崩溃了

Segmentation fault: 11

或不太常见

python(7444,0x7fff7c9aa000) malloc: *** error for object 0x102187580: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug Abort trap: 6

但是在随机的情况下并不总是!

在我的代码中更具体一点我正在做一个for循环,在每个循环中我调用以下Fortran代码

C FILE: ANGULAR_CORRELATION_FUNCTION_ROUTINES.F

  SUBROUTINE PAIRS_DR(N_SOURCES,X_PIXEL,Y_PIXEL,N_SOURCES_RANDOM,X_PIXEL_RANDOM,Y_PIXEL_RANDOM,PIXEL_SCALE,N_BINS,ANGULAR_DISTANCE_MIN,ANGULAR_DISTANCE_MAX,DR)

  INTEGER N_SOURCES
  REAL*8 X_PIXEL(N_SOURCES)
  REAL*8 Y_PIXEL(N_SOURCES)
  INTEGER N_SOURCES_RANDOM
  REAL*8 X_PIXEL_RANDOM(N_SOURCES_RANDOM)
  REAL*8 Y_PIXEL_RANDOM(N_SOURCES_RANDOM)
  REAL*8 PIXEL_SCALE
  INTEGER N_BINS
  REAL*8 ANGULAR_DISTANCE_MIN
  REAL*8 ANGULAR_DISTANCE_MAX
  INTEGER BIN
  INTEGER DR(N_BINS-1)
Cf2py intent(in) N_SOURCES
Cf2py intent(in) X_PIXEL
Cf2py intent(in) Y_PIXEL
Cf2py intent(in) N_SOURCES_RANDOM
Cf2py intent(in) X_PIXEL_RANDOM
Cf2py intent(in) Y_PIXEL_RANDOM
Cf2py intent(in) PIXEL_SCALE
Cf2py intent(in) N_BINS
Cf2py intent(in) ANGULAR_DISTANCE_MIN
Cf2py intent(in) ANGULAR_DISTANCE_MAX
Cf2py intent(out) DR
Cf2py depend(N_SOURCES) X_PIXEL
Cf2py depend(N_SOURCES) Y_PIXEL
Cf2py depend(N_SOURCES_RANDOM) X_PIXEL_RANDOM
Cf2py depend(N_SOURCES_RANDOM) Y_PIXEL_RANDOM
Cf2py depend(N_BINS) DR

  DLOG_ANGULAR_DISTANCE = (
 >  LOG10(ANGULAR_DISTANCE_MAX) -
 >  LOG10(ANGULAR_DISTANCE_MIN) ) /
 >  (N_BINS - 1)
  ! INITIALIZE
  DO I=1,N_BINS-1
    DR(I) = 0
  ENDDO
  ! COMPUTE DD PAIRS
  DO I=1,N_SOURCES
    DO J=1,N_SOURCES_RANDOM
      ANGULAR_DISTANCE_TEMP = ANGULAR_DISTANCE_APPROX(
 >     X_PIXEL(I) * PIXEL_SCALE,
 >     Y_PIXEL(I) * PIXEL_SCALE,
 >     X_PIXEL_RANDOM(J) * PIXEL_SCALE,
 >     Y_PIXEL_RANDOM(J) * PIXEL_SCALE)
      IF (ANGULAR_DISTANCE_TEMP.ge.ANGULAR_DISTANCE_MIN.and.
 >        ANGULAR_DISTANCE_TEMP.le.ANGULAR_DISTANCE_MAX) THEN
        BIN = INT( ( LOG10(ANGULAR_DISTANCE_TEMP) -
 >                   LOG10(ANGULAR_DISTANCE_MIN) ) /
 >                   DLOG_ANGULAR_DISTANCE ) + 1
        DR(BIN) = DR(BIN) + 1
      ELSE
      ENDIF
    ENDDO
  ENDDO
  END

C END FILE: ANGULAR_CORRELATION_FUNCTION_ROUTINES.F

  REAL FUNCTION ANGULAR_DISTANCE_APPROX(X_1, Y_1, X_2, Y_2)
    REAL*8 X_1, Y_1
    REAL*8 X_2, Y_2
    ANGULAR_DISTANCE_APPROX = SQRT(
 > (X_1 - X_2)**2.0 + (Y_1 - Y_2)**2.0)
  RETURN
  END

我的代码有时会运行没有错误,但有时会在崩溃中运行。有关为什么会发生这种情况的任何建议以及如何确定问题?

0 个答案:

没有答案