[Fortran] 纯文本查看 复制代码
PROGRAM Cs
IMPLICIT NONE
integer i,j,k,m,n,maxx,x1,x2,y1,y2,z1,z2
integer Num,iNum
real(kind=8) time1,time2,time3,time4,time5,time6
real(kind=8) numi
real(kind=8) con
real,allocatable :: Ex(:,:,:),Hy(:,:,:),Hz(:,:,:),indt(:,:,:)
maxx=70;numi=1.0;Num=10
time1=0.0;time2=0.0;time3=0.0;time4=0.0;time5=0.0;time6=0.0
allocate(Ex(maxx,maxx,maxx),Hy(maxx,maxx,maxx)
+ ,Hz(maxx,maxx,maxx),indt(maxx,maxx,maxx))
Ex=0;indt=0
x1=15;x2=30
y1=20;y2=35
z1=18;z2=30
do k=1,maxx
do j=1,maxx
do i=1,maxx
if(x1<=i.and.i<=x2) indt(i,j,k)=1
if(y1<=j.and.j<=y2) indt(i,j,k)=1
if(z1<=k.and.k<=z2) indt(i,j,k)=1
enddo
enddo
enddo
num=0
do k=1,maxx-1
do j=1,maxx-1
do i=1,maxx
if(indt(i,j,k)==1) num=num+1
enddo
enddo
enddo
print*,'筛选过后数目A',num
print*,'筛选过后数目(A)/总数(B)', 1.0*num/(maxx*(maxx-1)*(maxx-1))
time1=0.0
Ex=0
time1=0.0
time2=0.0
call cpu_time(time1)
do n= 1,10000
do k=1,maxx-1
do j=1,maxx-1
do i=1,maxx
Ex(i,j,k)=(Hy(i,j,k)-Hy(i,j,k+1))*0.1254
+ +(Hz(i,j,k)-Hz(i,j+1,k))*0.2948
enddo
enddo
enddo
enddo
call cpu_time(time2)
print*,'总迭代时间(B的耗时)',time2-time1,'s'
Ex=0
time3=0.0
time4=0.0
call cpu_time(time3)
do n= 1,10000
do k=1,maxx-1
do j=1,maxx-1
do i=1,maxx
if(indt(i,j,k).eq.1) cycle
Ex(i,j,k)=(Hy(i,j,k)-Hy(i,j,k+1))*0.1254
+ +(Hz(i,j,k)-Hz(i,j+1,k))*0.2948
enddo
enddo
enddo
enddo
call cpu_time(time4)
print*,'A的耗时',time4-time3,'s'
print*,'A/B的时间比',(time4-time3)/(time2-time1)
ENDPROGRAM Cs