1

我尝试将简单的阅读代码从串行修改为 openmp。

我无法理解我有什么样的错误消息,如果代码有问题,英特尔 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

有人可以帮助我吗???

4

1 回答 1

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

是这种情况的一部分并触发未指定的行为。我建议修改您的代码并将多个线程的访问同步到同一单元。

于 2013-05-19T15:23:21.893 回答