1! --- 2! Copyright (C) 1996-2016 The SIESTA group 3! This file is distributed under the terms of the 4! GNU General Public License: see COPYING in the top directory 5! or http://www.gnu.org/copyleft/gpl.txt . 6! See Docs/Contributors.txt for a list of contributors. 7! --- 8 module m_norm 9 CONTAINS 10 function compute_norm(DM,nnz,nspin) result(norm) 11 use precision, only: dp 12 use sparse_matrices, only: S 13 use m_spin, only: spinor_dim 14#ifdef MPI 15 use m_mpi_utils, only: globalize_sum 16#endif 17 18 integer, intent(in) :: nnz, nspin 19 real(dp), intent(in) :: DM(:,:) 20 real(dp) :: norm 21 22#ifdef MPI 23 real(dp):: buffer1 ! Temporary for the result of a globalize operation 24#endif 25 integer :: io, ispin 26 27 norm = 0.0_dp 28 do ispin = 1,spinor_dim 29 do io = 1,nnz 30 norm = norm + DM(io,ispin) * s(io) 31 enddo 32 enddo 33#ifdef MPI 34 call globalize_sum(norm,buffer1) 35 norm = buffer1 36#endif 37 end function compute_norm 38 end module m_norm 39