0
program array
 implicit none

 integer(8)::i,j
 real(8):: dt
 real(8):: RR(1317,26123),t(26123),IR(1317,26123),f(8,26123)
 complex(8):: sum(1317),factor(1317),fnl(1317)
 complex(8),dimension(:,:),allocatable::R
 allocate( R(1317,26123))
 
j=0.
sum(j)=0.
factor(j)=0.

  Open(0 , File ='/Users/clyrionchen/Desktop/result1-4.log')
  Open(11 , File ='/Users/clyrionchen/Desktop/ReR' )
  Open(22 , File ='/Users/clyrionchen/Desktop/ImR' )

do i=1,26123
  read(11,*) RR(:,i)
  read(0,*)  f(:,i)
  read(22,*) IR(:,i)
end do

 t(:)=f(1,:)
 r(:,:)=cmplx(Rr(:,:),IR(:,:),kind=16)           
 
do j=1,1317
  do i=2,26123

factor(j)=(r(j,i)+r(j,i-1))/2. *(t(i)-t(i-1))


sum(j)=sum(j)+factor(j)

   end do
end do

do j=1,1317
 write(*,*)  sum(j)
end do

end program

“Rr” and “Dr” Form a complex number, and now we need to integrate the complex number, the trapezoidal integral I wrote myself (top base plus bottom base, divided by 2, times the time interval). There are 1317 groups of points, and each group needs to be integrated to get the result. But it turns out that the value of the integral doesn't match the result. Is it the parallel error, or is it the numerical integration error? How should I write this program? Thank you very much for your answer.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
  • 2
    Well first comment is there is no parallelism in the above code, unless your compiler has a flag to autoparallelise. So did you use such a flag? Or if not why do you think the above code will use more than one thread or process? – Ian Bush Aug 30 '21 at 09:41
  • 1
    Secondly do you mean Ir instead of Dr when you say '“Rr” and “Dr” Form a complex number'. – Ian Bush Aug 30 '21 at 09:43
  • 2
    Also note Real( 8 ) and complex( 8 ) is bad practice, might not be supported by another compiler, and might not do what you expect. See https://stackoverflow.com/questions/838310/fortran-90-kind-parameter - I would suggest the `iso_fortran_env` route mentioned in the comments nowadays. – Ian Bush Aug 30 '21 at 09:45
  • 3
    Finally for now without telling us what the right answer is and providing a cut down version of the input files it will be difficult to confirm any suggestions about the error you are seeing. Can you provide such a cut down example with the expected answer, and also the answer you observe? – Ian Bush Aug 30 '21 at 09:47
  • 3
    Do you mean `sum=0` and `factor=0` rather than `j=0` `sum(j)=0` `factor(j)=0`? – veryreverie Aug 30 '21 at 14:04
  • I agree with @IanBush that `real(8)` and `complex(8)` are bad practices. What makes it worse is that you then do `(:,:)=cmplx(Rr(:,:),IR(:,:),kind=16) `. If you're using gfortran `kind=16` will give you quad precision, which is likely not what you want. – steve Aug 30 '21 at 16:26
  • Thank you for your suggestions. I will modify it according to your suggestions. Is there any problem with my parallel calculation and integration method? – ClyrionChen Aug 31 '21 at 03:57
  • Yes, there is problem if speed is important. Your nested do-loops are backwards. – steve Aug 31 '21 at 14:37

0 Answers0