eig66_io.F90 6.57 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8
MODULE m_eig66_io
#include "juDFT_env.h"
9
  USE m_types
10 11 12
  USE m_eig66_data
  IMPLICIT NONE
  PRIVATE
13

14 15
  PUBLIC open_eig,close_eig,reset_eig
  PUBLIC read_eig,write_eig
16
CONTAINS
17

18
  FUNCTION open_eig(mpi_comm,nmat,neig,nkpts,jspins,&
19
                    l_noco,l_create,l_real,l_soc,l_readonly,n_size,mode_in,filename)&
20
           RESULT(id)
21 22 23 24 25
    USE m_eig66_hdf,ONLY:open_eig_hdf=>open_eig
    USE m_eig66_DA ,ONLY:open_eig_DA=>open_eig
    USE m_eig66_mem,ONLY:open_eig_mem=>open_eig
    USE m_eig66_MPI,ONLY:open_eig_mpi=>open_eig
    IMPLICIT NONE
26
    INTEGER,INTENT(IN)          :: nmat,neig,nkpts,jspins,mpi_comm
27
    LOGICAL,INTENT(IN)          :: l_noco,l_readonly,l_create,l_real,l_soc
28 29 30 31 32
    INTEGER,INTENT(IN),OPTIONAL :: n_size,mode_in
    CHARACTER(LEN=*),INTENT(IN),OPTIONAL :: filename
    INTEGER:: id,mode

    INTEGER:: neig_local,isize,err
33 34 35 36 37
    if (l_soc) THEN
       neig_local=2*neig
    else
       neig_local=neig
    endif
38
    mode=-1
39
    IF (PRESENT(mode_in)) mode=mode_in
40 41 42 43

    IF (mode<0) THEN
       !Use default mode
#ifdef CPP_MPI
44 45 46 47 48 49
       CALL MPI_COMM_SIZE(mpi_comm,isize,err)
       IF (isize>1) THEN
           mode=MPI_mode
        ELSE
           mode=MEM_mode
        ENDIF   
50 51 52 53
#else
       mode=MEM_mode
#endif
       !check if default was given on command-line
54 55 56 57
       IF (TRIM(juDFT_string_for_argument("-eig"))=="mpi") mode=MPI_mode
       IF (TRIM(juDFT_string_for_argument("-eig"))=="mem") mode=MEM_mode
       IF (TRIM(juDFT_string_for_argument("-eig"))=="da") mode=DA_mode
       IF (TRIM(juDFT_string_for_argument("-eig"))=="hdf") mode=HDF_mode
58 59 60
    ENDIF
    !Check if mode is available
#ifndef CPP_MPI
61
    IF (mode==MPI_mode) CALL juDFT_error("MPI-mode not available. Recompile with CPP_MPI",calledby="eig66_io")
62
#else
63 64 65
    CALL MPI_COMM_SIZE(mpi_comm,isize,err)
    IF (isize>1.AND.((mode==DA_mode.OR.mode==mem_mode))) &
         CALL juDFT_error("In a parallel calculation MEM/DA-mode are not available",calledby="eig66_io")
66 67
#endif
#ifndef CPP_HDF
68
    IF (mode==HDF_mode) CALL juDFT_error("HDF-mode not available. Recompile with CPP_HDF",calledby="eig66_io")
69 70
#endif

71
    id=eig66_data_newid(mode)
72

Daniel Wortmann's avatar
Daniel Wortmann committed
73
    !PRINT *,"open_eig:",id,mode
74

75
    CALL timestart("Open file/memory for IO of eig66")
76
    SELECT CASE (eig66_data_mode(id))
77
    CASE (DA_mode)
78
       CALL open_eig_DA(id,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,filename)
79
    CASE (hdf_mode)
80
       CALL open_eig_HDF(id,mpi_comm,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_readonly,filename)
81
    CASE (mem_mode)
82
       CALL open_eig_MEM(id,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_noco,filename)
83
    CASE (mpi_mode)
84
       CALL open_eig_MPI(id,mpi_comm,nmat,neig_local,nkpts,jspins,l_create,l_real,l_soc,l_noco,n_size,filename)
85 86
    CASE DEFAULT
       CALL juDFT_error("Invalid IO-mode in eig66_io")
87
    END SELECT
88 89
    CALL timestop("Open file/memory for IO of eig66")
  END FUNCTION open_eig
90

91
  SUBROUTINE close_eig(id,filename)
92 93 94 95 96 97 98 99 100
    USE m_eig66_hdf,ONLY:close_eig_hdf=>close_eig
    USE m_eig66_DA ,ONLY:close_eig_DA=>close_eig
    USE m_eig66_mem,ONLY:close_eig_MEM=>close_eig
    USE m_eig66_MPI,ONLY:close_eig_MPI=>close_eig
    IMPLICIT NONE
    INTEGER,INTENT(IN)                   :: id
    CHARACTER(LEN=*),INTENT(IN),OPTIONAL :: filename
    INTEGER  :: mode
    mode=eig66_data_mode(id)
Daniel Wortmann's avatar
Daniel Wortmann committed
101
    !PRINT*,"close_eig:",id,mode
102
    SELECT CASE (mode)
103 104 105 106 107 108 109 110 111 112
    CASE (DA_mode)
       CALL close_eig_DA(id,filename)
    CASE (hdf_mode)
       CALL close_eig_HDF(id,filename)
    CASE (mem_mode)
       CALL close_eig_Mem(id,filename=filename)
    CASE (MPI_mode)
       CALL close_eig_MPI(id,filename=filename)
    CASE (-1)
       CALL juDFT_error("ID not assigned in close_eig",calledby="eig66_io")
113 114
    END SELECT

115
  END SUBROUTINE close_eig
116

117
  SUBROUTINE read_eig(id,nk,jspin,neig,eig,w_iks,list,zmat)
118 119 120 121 122 123 124
    USE m_eig66_hdf,ONLY:read_eig_hdf=>read_eig
    USE m_eig66_DA ,ONLY:read_eig_DA=>read_eig
    USE m_eig66_mem,ONLY:read_eig_mem=>read_eig
    USE m_eig66_MPI,ONLY:read_eig_MPI=>read_eig
    IMPLICIT NONE
    INTEGER, INTENT(IN)            :: id,nk,jspin
    INTEGER, INTENT(OUT),OPTIONAL  :: neig
Daniel Wortmann's avatar
Daniel Wortmann committed
125
    REAL,    INTENT(OUT),OPTIONAL  :: eig(:),w_iks(:)
126
    INTEGER, INTENT(IN),OPTIONAL   :: list(:)
127
    TYPE(t_mat),INTENT(INOUT),OPTIONAL  :: zmat
128 129 130
    INTEGER::n
    CALL timestart("IO (read)")
    SELECT CASE (eig66_data_mode(id))
131
    CASE (DA_mode)
132
       CALL read_eig_DA(id,nk,jspin,neig,eig,w_iks,list,zmat)
133
    CASE (hdf_mode)
134
       CALL read_eig_hdf(id,nk,jspin,neig,eig,w_iks,list,zmat)
135
    CASE (mem_mode)
136
       CALL read_eig_mem(id,nk,jspin,neig,eig,w_iks,list,zmat)
137
    CASE (mpi_mode)
138
       CALL read_eig_mpi(id,nk,jspin,neig,eig,w_iks,list,zmat)
139
    CASE (-1)
140
       CALL juDFT_error("Could not read eig-file before opening", calledby = "eig66_io")
141
    END SELECT
142 143
    CALL timestop("IO (read)")
  END SUBROUTINE read_eig
144

145
  SUBROUTINE write_eig(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
146 147 148 149 150 151
    USE m_eig66_hdf,ONLY:write_eig_hdf=>write_eig
    USE m_eig66_DA ,ONLY:write_eig_DA=>write_eig
    USE m_eig66_mem,ONLY:write_eig_MEM=>write_eig
    USE m_eig66_MPI,ONLY:write_eig_MPI=>write_eig
    IMPLICIT NONE
    INTEGER, INTENT(IN) :: id,nk,jspin
152 153
    INTEGER, INTENT(IN),OPTIONAL :: neig,neig_total,n_start,n_end
    REAL,    INTENT(IN),OPTIONAL :: eig(:),w_iks(:)
154
    TYPE(t_Mat),INTENT(IN),OPTIONAL :: zmat
155 156 157
    CALL timestart("IO (write)")
    SELECT CASE (eig66_data_mode(id))
    CASE (da_mode)
158
       CALL write_eig_DA(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
159
    CASE (hdf_mode)
160
       CALL write_eig_HDF(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
161
    CASE (mem_mode)
162
       CALL write_eig_Mem(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
163
    CASE (MPI_mode)
164
       CALL write_eig_MPI(id,nk,jspin,neig,neig_total,eig,w_iks,n_start,n_end,zmat)
165
    CASE (-1)
166
       CALL juDFT_error("Could not write eig-file before opening", calledby = "eig66_io")
167 168 169 170
    END SELECT
    CALL timestop("IO (write)")
  END SUBROUTINE write_eig

171 172 173 174 175 176 177 178 179 180 181 182
  SUBROUTINE reset_eig(id,l_soc)
     USE m_eig66_MPI,ONLY:reset_eig_MPI=>reset_eig
     INTEGER, INTENT(IN) :: id
     LOGICAL, INTENT(IN) :: l_soc

     SELECT CASE (eig66_data_mode(id))
     CASE (MPI_mode)
        CALL reset_eig_MPI(id,l_soc)
     END SELECT

  END SUBROUTINE reset_eig

183
END MODULE m_eig66_io