~nickpapior/siesta/trunk-kovalp

« back to all changes in this revision

Viewing changes to Src/compute_max_diff.F90

  • Committer: Nick Papior
  • Date: 2016-08-18 05:56:45 UTC
  • Revision ID: nickpapior@gmail.com-20160818055645-judotnqdl75x5y9b
Run all tests, solved merge problems and updated convergence criteria

- Re-run all tests.

  This showed a couple of interesting things.

  1. There was a mistake in the compute_dm code after
  the PEXSI merge when spin-orbit coupling was introduced
  2. I have removed Hprev as it essentially is the same as
  Hold. Either way it shouldn't produce a huge difference
  in the tracking of the dEbs, etc. (after all they are
  not physically used other than for convergence criteria)
  3. The change to SCF.Mix Hamiltonian resulted in a huge
  number of changes in the output. This is because the first
  step prints out the energies at INIT. However, the Hamiltonian
  is different because it is initialized after the compute_dm step.

- Changed the logic in convergence criteria.
  Now the convergence criterias are additive and may be fully controlled.
  However, at least one convergence criteria must be used.

  Now the default convergence criteria is both the Hamiltonian and the density
  matrix.

  This is updated in the manual and the compatibility note.

- Initially I thought the above differences in the energies was
  due to inconsistencies after r538. Hence I have created some
  simple routines in the m_energies.f90 code which updates a selected
  few of the energies.
  I think this should be adopted in the future to ensure that all
  calls to update energies are consistent.
  This will make changes to energy calculations less error-prone.

- Implemented the spin-type in the following routines:
   compute_dm
   final_H_f_stress
   state_init

- Changed the m_compute_max_diff to an interface code with appropriate
  size calculations. There was no reason for explicitly using the
  sparse pattern.

- Fixed a bug in the molecularmechanics code (introduced by Nick r542)

- Added a cyclediffs.sh script which loops on OUT.diffs files and
  it lets one easily cycle the diffs, simply do:

  cd Tests
  make check
  ./cyclediffs.sh

  and answer all the questions. Basically it makes deletes OUT.diffs
  which you have agreed isn't really a change.

- The tests may now be runned via:

   make MPI="mpirun -np 4"
   
  which then uses the default SIESTA location.

  Currently the script checks whether mpirun/mpiexec
  is in SIESTA variable, and if so, does not use MPI variable.
  This makes it easier to decide on the number of cores without
  writing the full path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
!  or http://www.gnu.org/copyleft/gpl.txt .
6
6
! See Docs/Contributors.txt for a list of contributors.
7
7
! ---
8
 
      module m_compute_max_diff
9
 
      use precision,         only: dp
10
 
      real(dp) :: dDmax_current
11
 
      public   :: compute_max_diff
12
 
      public   :: dDmax_current
13
 
      CONTAINS
14
 
      subroutine compute_max_diff(Xin,Xout,MaxDiff)
15
 
 
16
 
      use sparse_matrices,   only: numh, listhptr
17
 
      use m_spin,            only: nspin
18
 
      use atomlist,          only: no_l
19
 
#ifdef MPI
20
 
      use m_mpi_utils,           only: globalize_max
21
 
#endif
22
 
 
23
 
      real(dp), intent(in)    :: Xin(:,:), Xout(:,:)
24
 
      real(dp), intent(out)   :: MaxDiff
25
 
 
26
 
      integer   :: is, i, ind, in
27
 
#ifdef MPI
28
 
      real(dp)              :: buffer1
29
 
#endif
30
 
 
31
 
      MaxDiff = 0.0_dp
32
 
      do is = 1,nspin
33
 
         do i = 1,no_l
34
 
            do in = 1,numh(i)
35
 
               ind = listhptr(i) + in
36
 
               MaxDiff = max(MaxDiff, abs(Xout(ind,is) - Xin(ind,is)))
37
 
            enddo
38
 
         enddo
39
 
      enddo
40
 
 
41
 
#ifdef MPI
42
 
!     Ensure that MaxDiff is the same on all nodes 
43
 
      call globalize_max(MaxDiff,buffer1)
44
 
      MaxDiff = buffer1
45
 
#endif
46
 
 
47
 
      dDmax_current = MaxDiff
48
 
 
49
 
      end subroutine compute_max_diff
50
 
      end module m_compute_max_diff
 
8
module m_compute_max_diff
 
9
  use precision,         only: dp
 
10
 
 
11
  !> Temporary for storing the old maximum change
 
12
  real(dp), public, save :: dDmax_current
 
13
 
 
14
  interface compute_max_diff
 
15
     module procedure compute_max_diff_1d
 
16
     module procedure compute_max_diff_2d
 
17
  end interface compute_max_diff
 
18
  public   :: compute_max_diff
 
19
  
 
20
contains
 
21
  
 
22
  subroutine compute_max_diff_2d(X1,X2, max_diff)
 
23
    
 
24
#ifdef MPI
 
25
    use m_mpi_utils, only: globalize_max
 
26
#endif
 
27
    
 
28
    real(dp), intent(in)  :: X1(:,:), X2(:,:)
 
29
    real(dp), intent(out) :: max_diff
 
30
    
 
31
    integer :: n1, n2
 
32
    integer :: i1, i2
 
33
#ifdef MPI
 
34
    real(dp) :: buffer1
 
35
#endif
 
36
    
 
37
    n1 = size(X1, 1)
 
38
    n2 = size(X1, 2)
 
39
    if ( size(X2, 1) /= n1 ) then
 
40
       call die('compute_max_diff: Sizes of the arrays are not &
 
41
            &conforming (1-D)')
 
42
    end if
 
43
    if ( size(X2, 2) /= n2 ) then
 
44
       call die('compute_max_diff: Sizes of the arrays are not &
 
45
            &conforming (2-D)')
 
46
    end if
 
47
    
 
48
    max_diff = 0.0_dp
 
49
!$OMP parallel do default(shared), private(i2,i1), &
 
50
!$OMP& reduction(max:max_diff), collapse(2)
 
51
    do i2 = 1 , n2
 
52
       do i1 = 1 , n1
 
53
          max_diff = max(max_diff, abs(X1(i1,i2) - X2(i1,i2)) )
 
54
       end do
 
55
    end do
 
56
!$OMP end parallel do
 
57
    
 
58
#ifdef MPI
 
59
    ! Ensure that max_diff is the same on all nodes 
 
60
    call globalize_max(max_diff, buffer1)
 
61
    max_diff = buffer1
 
62
#endif
 
63
 
 
64
    dDmax_current = max_diff
 
65
 
 
66
  end subroutine compute_max_diff_2d
 
67
 
 
68
  subroutine compute_max_diff_1d(X1, X2, max_diff)
 
69
    
 
70
#ifdef MPI
 
71
    use m_mpi_utils, only: globalize_max
 
72
#endif
 
73
    
 
74
    real(dp), intent(in)  :: X1(:), X2(:)
 
75
    real(dp), intent(out) :: max_diff
 
76
    
 
77
    integer :: n1
 
78
    integer :: i1
 
79
#ifdef MPI
 
80
    real(dp) :: buffer1
 
81
#endif
 
82
    
 
83
    n1 = size(X1, 1)
 
84
    if ( size(X2, 1) /= n1 ) then
 
85
       call die('compute_max_diff: Sizes of the arrays are not &
 
86
            &conforming (1-D)')
 
87
    end if
 
88
    
 
89
    max_diff = 0.0_dp
 
90
!$OMP parallel do default(shared), private(i1), reduction(max:max_diff)
 
91
    do i1 = 1 , n1
 
92
       max_diff = max(max_diff, abs(X1(i1) - X2(i1)) )
 
93
    end do
 
94
!$OMP end parallel do
 
95
    
 
96
#ifdef MPI
 
97
    ! Ensure that max_diff is the same on all nodes 
 
98
    call globalize_max(max_diff, buffer1)
 
99
    max_diff = buffer1
 
100
#endif
 
101
 
 
102
    dDmax_current = max_diff
 
103
 
 
104
  end subroutine compute_max_diff_1d
 
105
  
 
106
end module m_compute_max_diff