Charge density is no longer read in parallel by different pools -

not yet the final version, needs to be merged with CP


git-svn-id: http://qeforge.qe-forge.org/svn/q-e/trunk/espresso@9434 c92efa57-630b-4861-b058-cf58834340f0
This commit is contained in:
giannozz 2012-09-19 08:05:29 +00:00
parent a3d1f55c21
commit ed96b21b71
2 changed files with 151 additions and 38 deletions

View File

@ -51,7 +51,7 @@ MODULE xml_io_base
write_efield, write_spin, write_magnetization, write_xc, &
write_exx, write_occ, write_bz, write_para, &
write_phonon, write_rho_xml, write_wfc, write_eig, &
read_wfc, read_rho_xml
read_wfc, read_rho_xml, read_rho_xml_
!
CONTAINS
!
@ -2105,6 +2105,126 @@ MODULE xml_io_base
ENDIF
!
END SUBROUTINE write_eig
!
!------------------------------------------------------------------------
SUBROUTINE read_rho_xml_( rho_file_base, rho, &
nr1, nr2, nr3, nr1x, nr2x, ipp, npp, &
intra_group_comm, intra_image_comm )
!------------------------------------------------------------------------
!
! ... Reads charge density rho, one plane at a time, to avoid
! ... collecting the entire charge density on a single proc.
!
USE io_files, ONLY : rhounit
USE io_global, ONLY : ionode, ionode_id
USE mp, ONLY : mp_put, mp_sum, mp_rank, mp_size
!
IMPLICIT NONE
!
CHARACTER(LEN=*), INTENT(IN) :: rho_file_base
INTEGER, INTENT(IN) :: nr1, nr2, nr3
INTEGER, INTENT(IN) :: nr1x, nr2x
REAL(DP), INTENT(OUT) :: rho(:)
INTEGER, INTENT(IN) :: ipp(:)
INTEGER, INTENT(IN) :: npp(:)
INTEGER, INTENT(IN) :: intra_group_comm, intra_image_comm
!
INTEGER :: ierr, i, j, k, kk, ldr, ip
INTEGER :: nr( 3 )
INTEGER :: me_group, nproc_group
CHARACTER(LEN=256) :: rho_file
REAL(DP), ALLOCATABLE :: rho_plane(:)
INTEGER, ALLOCATABLE :: kowner(:)
LOGICAL :: exst
!
me_group = mp_rank ( intra_group_comm )
nproc_group = mp_size ( intra_group_comm )
!
rho_file = TRIM( rho_file_base ) // ".dat"
exst = check_file_exst( TRIM(rho_file) )
!
IF ( .NOT. exst ) THEN
!
rho_file = TRIM( rho_file_base ) // ".xml"
exst = check_file_exst( TRIM(rho_file) )
!
ENDIF
!
IF ( .NOT. exst ) CALL errore('read_rho_xml', 'searching for '//TRIM(rho_file), 10)
!
IF ( ionode ) THEN
CALL iotk_open_read( rhounit, FILE = rho_file, IERR = ierr )
CALL errore( 'read_rho_xml', 'cannot open ' // TRIM( rho_file ) // ' file for reading', ierr )
END IF
!
IF ( ionode ) THEN
!
CALL iotk_scan_begin( rhounit, "CHARGE-DENSITY" )
!
CALL iotk_scan_empty( rhounit, "INFO", attr )
!
CALL iotk_scan_attr( attr, "nr1", nr(1) )
CALL iotk_scan_attr( attr, "nr2", nr(2) )
CALL iotk_scan_attr( attr, "nr3", nr(3) )
!
IF ( nr1 /= nr(1) .OR. nr2 /= nr(2) .OR. nr3 /= nr(3) ) &
CALL errore( 'read_rho_xml', 'dimensions do not match', 1 )
!
END IF
!
ALLOCATE( rho_plane( nr1*nr2 ) )
ALLOCATE( kowner( nr3 ) )
!
DO ip = 1, nproc_group
!
kowner((ipp(ip)+1):(ipp(ip)+npp(ip))) = ip - 1
!
END DO
!
ldr = nr1x*nr2x
!
! ... explicit initialization to zero is needed because the physical
! ... dimensions rho may exceed the true size of the FFT grid
!
rho(:) = 0.0_DP
!
DO k = 1, nr3
!
! ... only ionode reads the charge planes
!
IF ( ionode ) &
CALL iotk_scan_dat( rhounit, "z" // iotk_index( k ), rho_plane )
!
! ... planes are sent to the destination processor
!
CALL mp_bcast( rho_plane, ionode_id, intra_image_comm )
!
IF( kowner(k) == me_group ) THEN
!
kk = k - ipp( me_group + 1 )
DO j = 1, nr2
DO i = 1, nr1
rho(i+(j-1)*nr1x+(kk-1)*ldr) = rho_plane(i+(j-1)*nr1)
END DO
END DO
!
END IF
!
END DO
!
DEALLOCATE( rho_plane )
DEALLOCATE( kowner )
!
IF ( ionode ) THEN
!
CALL iotk_scan_end( rhounit, "CHARGE-DENSITY" )
!
CALL iotk_close_read( rhounit )
!
END IF
!
RETURN
!
END SUBROUTINE read_rho_xml_
END MODULE xml_io_base

View File

@ -11,7 +11,7 @@ MODULE io_rho_xml
!----------------------------------------------------------------------------
!
USE kinds, ONLY : DP
USE xml_io_base, ONLY : create_directory, write_rho_xml, read_rho_xml
USE xml_io_base, ONLY : create_directory, write_rho_xml, read_rho_xml_
!
PRIVATE
!
@ -112,11 +112,13 @@ MODULE io_rho_xml
LOGICAL :: lexist
INTEGER :: ierr
! Use the equivalent routine to write real space density
! Use the equivalent routine to read real space density
CALL read_rho_only( rho%of_r, nspin, extension )
! The occupations ns also need to be read in order to build up
! the potential
!
IF ( lda_plus_u ) THEN
!
! The occupations ns also need to be read in order to build up
! the potential
!
IF ( ionode ) THEN
CALL seqopn( iunocc, 'occup', 'FORMATTED', lexist )
@ -140,8 +142,10 @@ MODULE io_rho_xml
CALL mp_sum(rho%ns, intra_image_comm)
endif
END IF
! Also the PAW coefficients are needed:
!
IF ( okpaw ) THEN
!
! Also the PAW coefficients are needed:
!
IF ( ionode ) THEN
CALL seqopn( iunpaw, 'paw', 'FORMATTED', lexist )
@ -264,10 +268,12 @@ MODULE io_rho_xml
! ... this routine reads the charge-density in xml format from the
! ... files saved into the '.save' directory
!
USE io_files, ONLY : tmp_dir, prefix
USE fft_base, ONLY : dfftp
USE spin_orb, ONLY : domag
USE io_files, ONLY : tmp_dir, prefix
USE fft_base, ONLY : dfftp
USE spin_orb, ONLY : domag
USE mp_global, ONLY : intra_bgrp_comm, inter_bgrp_comm, root_pool, me_pool
USE mp_global, ONLY : intra_image_comm
USE io_global, ONLY : ionode
!
IMPLICIT NONE
!
@ -279,46 +285,33 @@ MODULE io_rho_xml
CHARACTER(LEN=256) :: ext
REAL(DP), ALLOCATABLE :: rhoaux(:)
!
LOGICAL :: my_ionode=.false.
!
! The first processor of each k-point pool reads the charge
! density. This will be distributed to the group of processors
! specified as arguments to read_rho_xml, i.e. the band group
! Note that this means that there will be concurrent read of the
! same file from different processors, unlike in v.<5.0
!
if(me_pool==root_pool) my_ionode=.true.
!
ext = ' '
!
dirname = TRIM( tmp_dir ) // TRIM( prefix ) // '.save'
!
ext = ' '
IF ( PRESENT( extension ) ) ext = '.' // TRIM( extension )
!
file_base = TRIM( dirname ) // '/charge-density' // TRIM( ext )
!
IF ( nspin == 1 ) THEN
!
CALL read_rho_xml( file_base, rho(:,1), dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rho(:,1), dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
ELSE IF ( nspin == 2 ) THEN
!
ALLOCATE( rhoaux( dfftp%nnr ) )
!
CALL read_rho_xml( file_base, rhoaux, dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rhoaux, dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
rho(:,1) = rhoaux(:)
rho(:,2) = rhoaux(:)
!
file_base = TRIM( dirname ) // '/spin-polarization' // TRIM( ext )
!
CALL read_rho_xml( file_base, rhoaux, dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rhoaux, dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
rho(:,1) = 0.5D0*( rho(:,1) + rhoaux(:) )
rho(:,2) = 0.5D0*( rho(:,2) - rhoaux(:) )
@ -327,29 +320,29 @@ MODULE io_rho_xml
!
ELSE IF ( nspin == 4 ) THEN
!
CALL read_rho_xml( file_base, rho(:,1), dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rho(:,1), dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
IF ( domag ) THEN
!
file_base = TRIM( dirname ) // '/magnetization.x' // TRIM( ext )
!
CALL read_rho_xml( file_base, rho(:,2), dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rho(:,2), dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
file_base = TRIM( dirname ) // '/magnetization.y' // TRIM( ext )
!
CALL read_rho_xml( file_base, rho(:,3), dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rho(:,3), dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
file_base = TRIM( dirname ) // '/magnetization.z' // TRIM( ext )
!
CALL read_rho_xml( file_base, rho(:,4), dfftp%nr1, dfftp%nr2, &
CALL read_rho_xml_( file_base, rho(:,4), dfftp%nr1, dfftp%nr2, &
dfftp%nr3, dfftp%nr1x, dfftp%nr2x, dfftp%ipp, dfftp%npp, &
my_ionode, intra_bgrp_comm, inter_bgrp_comm )
intra_bgrp_comm, intra_image_comm )
!
ELSE
!