openmp fortran程序崩溃

时间:2013-05-16 00:54:06

标签: openmp

我尝试将一个简单的读取代码从serial修改为openmp。

我无法理解我有什么样的错误信息,如果代码有问题,请使用intel fotran编译器或其他内容。

program lettura
implicit none

INTEGER*8::n,i,j,m,s,t,q
CHARACTER*70:: filename,k
REAL*8::sum,dummy
REAL*8,ALLOCATABLE::dati(:,:),dats(:,:)
CHARACTER*120::nomefile


open(10,file='bin.txt')
n=0
!$OMP PARALLEL PRIVATE(q)


do
read(10,*,end=100)
n=n+1
end do
100 continue
rewind(10)

allocate(dati(11,n))

!$OMP DO SCHEDULE(STATIC)
do i=1,n
read(10,*) dati(1,i),dati(2,i),dati(3,i),dati(4,i),dati(5,i),dati(6,i),dati(7,i) &
&,dati(8,i),dati(9,i),dati(10,i),dati(11,i)
end do
!$OMP END DO




j=1

!$OMP DO SCHEDULE(STATIC)
do i=1, n-1
     if (dati(3,i+1) > dati(3,i)) then
            write(k,*) j
        k=adjustl(k)
        filename='where'//trim(k)//'.txt'
        open(2,file=filename)
        close(2)
            j=j+1
         end if
end do
!$OMP END DO




j=1
open(2,file='where1.txt')

!$OMP DO SCHEDULE(STATIC)
do i=1, n-1
     if (dati(3,i+1) == dati(3,i)) then
        write(2,*) dati(1,i),dati(2,i),dati(3,i),dati(4,i),dati(5,i),dati(6,i),dati(7,i) &
                &,dati(8,i),dati(9,i),dati(10,i),dati(11,i)
            else
        write(2,*) dati(1,i),dati(2,i),dati(3,i),dati(4,i),dati(5,i),dati(6,i),dati(7,i) &
                &,dati(8,i),dati(9,i),dati(10,i),dati(11,i)
        close(2)
        j=j+1
        write(k,*) j
        k=adjustl(k)
        filename='where'//trim(k)//'.txt'
        open(2,file=filename)
print *,j,"/ 54"
     end if
end do
!$OMP END DO
open(3,file='Sigma.txt')


!$OMP DO SCHEDULE(STATIC)
do i=1, j-1
    write(k,*) i
    k=adjustl(k)
    nomefile='where'//trim(k)//'.txt'
    open(4,file=nomefile)

!print *,i contatore del numero di file
!calcolare righe del file
m=0
    do 
      read(4,*,end=101)
      m=m+1
    end do
      101 continue
      rewind(4)
! fine righe file
! scrive la matrice del file dats(11,m), m: # di righe
    allocate(dats(11,m))

! fa il calcolo sulla matrice
        sum=0
    do s=1, m-1
      read(4,*) dummy,dummy,dummy,dats(4,s),dats(5,s)
      sum=sum+(1/(dats(4,s))*((2/(dats(5,s)-1))-1)**2)
        end do
! scrive sul file 3
print *, sum
    WRITE(3,*) (sum/(m-1))
    close(4)
    deallocate(dats)

end do
!$OMP END DO
 close(3)
!$OMP END PARALLEL
end program lettura

当我尝试编译它时:

ifort -openmp -w dati_omp.f90
export OMP_NUM_THREDS=2
./a.out

我收到此消息:

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              000000000045AA90  Unknown               Unknown  Unknown
a.out              0000000000453BBC  Unknown               Unknown  Unknown
a.out              000000000041E7E8  Unknown               Unknown  Unknown
a.out              00000000004037C3  Unknown               Unknown  Unknown
libiomp5.so        00007F413793F4F3  Unknown               Unknown  Unknown

有人可以帮我吗???

1 个答案:

答案 0 :(得分:0)

从OpenMP标准,第2.4节:

  

多个线程对Fortran I / O语句的不同步使用   同一单位有不明确的行为。

查看您的代码,似乎语句如下:

!$OMP DO SCHEDULE(STATIC)
do i=1,n
read(10,*) dati(1,i),dati(2,i),dati(3,i),dati(4,i),dati(5,i),dati(6,i),dati(7,i) &
&,dati(8,i),dati(9,i),dati(10,i),dati(11,i)
end do
!$OMP END DO

是此案例的一部分,会触发未指定的行为。我建议修改你的代码并将多个线程的访问同步到同一个单元。