Something about ewald fortran code

General discussion of the Cambridge quantum Monte Carlo code CASINO; how to install and setup; how to use it; what it does; applications.
Post Reply
Yecheng_Zhou
Posts: 3
Joined: Tue Jan 26, 2016 1:48 pm

Something about ewald fortran code

Post 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
Pablo_Lopez_Rios
Posts: 53
Joined: Thu Jan 30, 2014 1:25 am

Re: Something about ewald fortran code

Post 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
Hey there! I am using CASINO.
Mike Towler
Posts: 239
Joined: Thu May 30, 2013 11:03 pm
Location: Florence
Contact:

Re: Something about ewald fortran code

Post 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
Yecheng_Zhou
Posts: 3
Joined: Tue Jan 26, 2016 1:48 pm

Re: Something about ewald fortran code

Post 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
Yecheng_Zhou
Posts: 3
Joined: Tue Jan 26, 2016 1:48 pm

Re: Something about ewald fortran code

Post by Yecheng_Zhou »

Mike Towler wrote: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
Hi Mike,
Nice to meet you again!
I read it. It explained very well. Thank you for your help!
Best wish,
Yecheng
Post Reply