本文介绍了二维数组上的分割错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码。当我取消注释 temperature(i,j)=阳极温度时,我SegFault。

 <$ c $ (1),j = 0:单元(2),j> = nint(upperBoundary(i * delta(1))/ delta(2)))
phi(i = i,j)= Anode_Voltage
!温度(i,j)=阳极温度
结束全部

然而,我可以访问每个元素使用下面的代码。

  do i = 0,Cells(1)
do j = 0,Cells(2 )
温度(i,j)=阳极温度
写(*,*)i,j,温度(i,j)
enddo
enddo

这是一个自包含的程序。由于有人提到他们使用了ifort,我正在使用ifort 14。

pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
REAL,PARAMETER :: Pi = 3.14159265359
integer,parameter :: ND = 2

real,parameter :: RL = 1.0E-6!边界半径
real ,参数:: HN = 5.0E-6!包含针的长度
实数,参数:: HL = 2.0E-6!提示高度

实数,参数:: LTT = 3E- 6!小费距离

real,parameter :: RU = 0.5E-6!边界半径
real,参数:: HU = 1.5E-6!特征高度

real,parameter :: zLen = HN + HL + LTT + HU

real,parameter,dimension(ND):: Length =(/ 20E-6,zLen /)!计算域大小(r,z)

! Grid Spacing
real,parameter,dimension(ND):: delta =(/ 1.0E-8,1.0E-8 /)
整数,PARAMETER,dimension(ND):: cells = Length / delta

real,parameter :: VApplied = -150

REAL,PARAMETER :: cathode_temperature = 1473.14!阴极温度[K]
REAL,parameter :: anode_temperature = 973.14!阳极温度[K]
真:: Cathode_Voltage,Anode_Voltage

REAL,维(0:单元格(1),0:单元格(2)):: phi
REAL,维(0:单元格(1),0:单元格(2))::温度!网格气体温度

整数:: i,j

phi = 0.0
temperature = 0.0

Cathode_Voltage = VApplied
Anode_Voltage = 0

forall(i = 0:Cells(1),j = 0:单元(2),j≤nint(lowerBoundary(i * delta(1))/ delta(2)))
phi(i,j)= Cathode_Voltage
temperature(i,j)= (1),j = 0:单元(2),j> = nint(upperBoundary(i * delta(1))) / del ta(2)))
phi(i,j)=阳极_电压
温度(i,j)=阳极温度
结束全部

!forall(i = 0 :单元(1),j = 0:单元(2),(j> nint(lowerBoundary(i * delta(1))/ delta(2)))和。 (j ! phi(i,j)= Cathode_Voltage +(Anode_Voltage_ Cathode_Voltage)*((delta(2)* j- lowerBoundary(i * delta(1)))/(upperBoundary(i * delta(1)) - lowerBoundary(i * delta(1))))
!温度(i,j)=阴极温度+(阳极温度 - 阴极温度)*((delta(2)* j-下部边界(i * delta(1)))/(upperBoundary(i * delta(1) delta(1))))
!end forall

包含
pure函数LowerRegion(r)结果(k)

隐式无$ b $如果(r k = 0
elseif(r 整数:: k

)然后
k = 1
elseif(r> = RL)然后
k = 2
elseif(r> R)然后
k = 3
endif
结束函数LowerRegion

纯函数UpperRegion(r)结果(k)

隐含无
实数,意图(in):: r
integer :: k

if(r k = 0
elseif(r k = 1
elseif(r> = RU),则
k = 2
elseif(r> R)then
k = 3
endif
end function UpperRegion


!!!!!!!!!!!!为各个区域定义几何图形的几何图形!!!!!!!!!!!!!!!!!!
pure函数lowerBoundary(r)结果(z)

隐式无
实数,意图(in):: r
real :: z

if if(LowerRegion(r)== 1)then
z = HN + HL *(1.0 - (r / RL))
elseif(LowerRegion(r)== 2)then
z = 0.0
endif
!end function lowerBoundary_Scalar
结束函数lowerBoundary

纯函数upperBoundary(r)结果(z)

隐式none
real,intent(in):: r
real :: z
$ b $ if(UpperRegion(r)== 1)then
z = zLen - HU * (1.0 - (r / RU))
elseif(UpperRegion(r)== 2)然后
z = zLen
结束如果
结束函数upperBoundary

end program Main


解决方案

正如@haraldkl所建议的那样,有一个编译器错误。 forall 循环与 -g 编译器标志(或更具体地说 - > O0 标志这会自动导致)。这是我在英特尔论坛上发布的帖子。




I have the code below. When I uncomment temperature(i,j) = anode_temperature, I SegFault.

forall(i=0:Cells(1), j=0:Cells(2), j >= nint(upperBoundary(i * delta(1)) / delta(2)))
    phi(i,j) = Anode_Voltage
!   temperature(i,j) = anode_temperature
end forall

However, I can access every element using the code below.

do i = 0,Cells(1)
    do j = 0,Cells(2)
        temperature(i,j) = anode_temperature
        write(*,*) i,j,temperature(i,j)
    enddo
enddo

Here is a self-contained program. Since someone mentioned they used ifort, I am using ifort 14.

program Main
implicit none

REAL, PARAMETER :: Pi = 3.14159265359
integer,parameter :: ND = 2

real, parameter :: RL = 1.0E-6  !Boundary radius
real, parameter :: HN = 5.0E-6  !Length of included needle
real, parameter :: HL = 2.0E-6  !Tip height

real, parameter :: LTT = 3E-6   !Tip-to-tip distance

real, parameter :: RU = 0.5E-6  !Boundary radius
real, parameter :: HU = 1.5E-6  !feature height

real, parameter :: zLen = HN + HL + LTT + HU

real,parameter,dimension(ND) :: Length = (/ 20E-6, zLen /)          !computational domain size (r,z)

! Grid Spacing
real, parameter, dimension(ND) :: delta = (/ 1.0E-8 , 1.0E-8 /)
integer, PARAMETER, dimension(ND) :: cells = Length / delta

real,parameter :: VApplied = -150

REAL, PARAMETER :: cathode_temperature = 1473.14        !Cathode Temperature [K]
REAL, parameter :: anode_temperature = 973.14           !Anode Temperature [K]
real :: Cathode_Voltage, Anode_Voltage

REAL, dimension(0:cells(1), 0:cells(2)) :: phi
REAL, dimension(0:cells(1), 0:cells(2)) :: temperature              !grid-wise gas temperature

integer:: i,j

phi = 0.0
temperature = 0.0

    Cathode_Voltage = VApplied
    Anode_Voltage = 0

forall(i=0:Cells(1), j=0:Cells(2), j <= nint(lowerBoundary(i * delta(1)) / delta(2)))
    phi(i,j) = Cathode_Voltage
    temperature(i,j) = cathode_temperature
end forall

forall(i=0:Cells(1), j=0:Cells(2), j >= nint(upperBoundary(i * delta(1)) / delta(2)))
    phi(i,j) = Anode_Voltage
    temperature(i,j) = anode_temperature
end forall

!forall(i=0:Cells(1), j=0:Cells(2), (j > nint(lowerBoundary(i * delta(1)) / delta(2))) .and. (j < nint(upperBoundary(i * delta(1)) / delta(2))))
!   phi(i,j) = Cathode_Voltage + (Anode_Voltage - Cathode_Voltage) * ((delta(2) * j - lowerBoundary(i * delta(1)) ) / ( upperBoundary(i * delta(1)) - lowerBoundary(i * delta(1)) ))
!   temperature(i,j) = cathode_temperature + (anode_temperature - cathode_temperature) * ((delta(2) * j - lowerBoundary(i * delta(1)) ) / ( upperBoundary(i * delta(1)) - lowerBoundary(i * delta(1)) ))
!end forall

contains
    pure function LowerRegion(r) result(k)

    implicit none
        real,intent(in) :: r
        integer :: k

        if (r < 0) then
            k = 0
        elseif (r < RL) then
            k = 1
        elseif (r >= RL) then
            k = 2
        elseif (r > R) then
            k = 3
        endif
    end function LowerRegion

    pure function UpperRegion(r) result(k)

    implicit none
        real,intent(in) :: r
        integer :: k

        if (r < 0) then
            k = 0
        elseif (r < RU) then
            k = 1
        elseif (r >= RU) then
            k = 2
        elseif (r > R) then
            k = 3
        endif
    end function UpperRegion


!!!!!!!!!!!! Define geometry for regions radially !!!!!!!!!!!!!!!!!!
    pure function lowerBoundary(r) result(z)

    implicit none
        real,intent(in) :: r
        real :: z

        if (LowerRegion(r) == 1) then
            z = HN + HL * (1.0 - (r / RL))
        elseif (LowerRegion(r) == 2) then
            z = 0.0
        endif
    !end function lowerBoundary_Scalar
    end function lowerBoundary

    pure function upperBoundary(r) result(z)

    implicit none
        real,intent(in) :: r
        real :: z

        if (UpperRegion(r) == 1) then
            z = zLen - HU * (1.0 - (r / RU))
        elseif (UpperRegion(r) == 2) then
            z = zLen
        end if
    end function upperBoundary

end program Main
解决方案

As was suggested by @haraldkl, there was a compiler bug. The combination of the forall loops and the -g compiler flag (or more specifically the -O0 flag this automatically causes). This is the post I made on the Intel forum.

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/593599

这篇关于二维数组上的分割错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:29