Page 1 of 1
					
				Something about ewald fortran code
				Posted: Fri Jan 29, 2016 2:42 am
				by Yecheng_Zhou
				Dear all,
I am new here. I try to understand the CASINO code related to ewald summation, but I confused about one question. 
The demenstion of 
vecji in subroutine
 ewald_2d code and some called 
ewald_2d is different.:
SUBROUTINE 
Code: Select all
 
SUBROUTINE ewald_2d(n,vecji,pote,field)
 IMPLICIT NONE
 INTEGER,INTENT(in) :: n
 REAL(dp),INTENT(in) :: vecji(4,n)
....
 do loop=1,n
  d=vecji(1:2,loop)
  z=vecji(3,loop)
.....
calling for example, line 911 in interactions.f90 :
Code: Select all
     if(ie>1)then
      call ewald_2d(ie-1,vecji(1,1),pote1)
     else
      pote1=0.d0
In SUBROUTINE , 
vecji(4,n) at least has 4 elements. But in the calling part, it only has one element. 
How does it work?
Thanks!
Yecheng
 
			
					
				Re: Something about ewald fortran code
				Posted: Fri Jan 29, 2016 12:59 pm
				by Pablo_Lopez_Rios
				Hi Yecheng,
Referring to an element of a contiguous array is one way of passing array arguments in Fortran, which results in the called subroutine receiving the array starting at the element in question, not just the element. The call you quote is equivalent to:
Code: Select all
call ewald_2d(ie-1,vecji(1:4,1:ie-1),pote1)
but is potentially faster since the compiler does not check array bounds (it couldn't even if it wanted to) and does not risk an array copy operation which could happen when passing potentially non-contiguous array sections.  Calls of this type are common throughout the CASINO code.
Best,
Pablo
 
			
					
				Re: Something about ewald fortran code
				Posted: Sat Jan 30, 2016 4:36 pm
				by Mike Towler
				Hi Yecheng,
I remembered that Steve Lionel - otherwise known as 
Doctor Fortran - had a nice article on this sort of thing which has some further details:
https://software.intel.com/en-us/blogs/ ... n-argument
Cheers,
Mike
 
			
					
				Re: Something about ewald fortran code
				Posted: Sun Jan 31, 2016 10:57 pm
				by Yecheng_Zhou
				Pablo_Lopez_Rios wrote:Hi Yecheng,
Referring to an element of a contiguous array is one way of passing array arguments in Fortran, which results in the called subroutine receiving the array starting at the element in question, not just the element. The call you quote is equivalent to:
Code: Select all
call ewald_2d(ie-1,vecji(1:4,1:ie-1),pote1)
but is potentially faster since the compiler does not check array bounds (it couldn't even if it wanted to) and does not risk an array copy operation which could happen when passing potentially non-contiguous array sections.  Calls of this type are common throughout the CASINO code.
Best,
Pablo
 
Hi Pablo,
Got it. It is surprising that it maybe faster! Thank you very much!
Best wishes,
Yecheng
 
			
					
				Re: Something about ewald fortran code
				Posted: Sun Jan 31, 2016 11:07 pm
				by Yecheng_Zhou
				
Hi Mike,
Nice to meet you again! 
I read it. It explained very well.  Thank you for your help!
Best wish,
Yecheng