1
我試圖修改一個簡單的讀取代碼從serial到openmp。openmp fortran程序崩潰
我無法理解我有什麼樣的錯誤信息,如果代碼存在問題,請使用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
有人能幫助我,請???