TABLE OF CONTENTS


ABINIT/ioprof [ Programs ]

[ Top ] [ Programs ]

NAME

 ioprof

FUNCTION

 Tool for frofiling and and testing the IO routines used in abinit

COPYRIGHT

 Copyright (C) 2004-2018 ABINIT group (MG)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .

INPUTS

  (main program)

NOTES

PARENTS

CHILDREN

      abi_io_redirect,abimem_init,abinit_doctor,delete_file
      get_command_argument,hdr_echo,hdr_free,hdr_read_from_fname,herald
      wfk_check_wfkfile,wfk_close,wfk_create_wfkfile,wfk_nc2fort
      wfk_open_read,wfk_print,wfk_prof,wrtout,xmpi_init

SOURCE

 30 #if defined HAVE_CONFIG_H
 31 #include "config.h"
 32 #endif
 33 
 34 #include "abi_common.h"
 35 
 36 program ioprof
 37 
 38  use defs_basis
 39  use m_build_info
 40  use m_errors
 41  use m_xmpi
 42  use m_wfk
 43  use m_abicore
 44  use m_hdr
 45 #ifdef HAVE_NETCDF
 46  use netcdf
 47 #endif
 48 
 49  use defs_abitypes,    only : hdr_type
 50  use m_specialmsg,     only : specialmsg_getcount, herald
 51  use m_fstrings,       only : lower, sjoin, itoa
 52  use m_io_tools,       only : delete_file, file_exists, iomode_from_fname, get_unit
 53 
 54 !This section has been created automatically by the script Abilint (TD).
 55 !Do not modify the following lines by hand.
 56 #undef ABI_FUNC
 57 #define ABI_FUNC 'ioprof'
 58 !End of the abilint section
 59 
 60  implicit none
 61 
 62 !Local variables-------------------------------
 63 !scalars
 64  integer,parameter :: master=0,MAX_NFILES=50
 65  integer :: comm,my_rank,nprocs,iomode,formeig,ierr,fform
 66  integer :: ii,io,check_iomode,method,feg,ount,nband2read,nargs
 67  logical :: verbose=.FALSE.
 68  character(len=24) :: codename
 69  character(len=500) :: msg,command,arg
 70  character(len=fnlen) :: new_fname,wfk_source,wfk_dest,wfk_path
 71  type(hdr_type) :: hdr
 72  type(wfk_t) :: wfk
 73 !arrays
 74  integer,parameter :: formeigs(2) = (/0,1/)
 75  integer,parameter :: io_modes(1) = (/IO_MODE_FORTRAN/)
 76  !integer,parameter :: io_modes(1) = (/IO_MODE_MPI/)
 77  !integer,parameter :: io_modes(1) = (/IO_MODE_ETSF/)
 78  !integer,parameter :: io_modes(2) = (/IO_MODE_FORTRAN, IO_MODE_MPI/)
 79  !integer,parameter :: io_modes(3) = (/IO_MODE_FORTRAN, IO_MODE_MPI, IO_MODE_ETSF/)
 80  real(dp) :: cwtimes(2)
 81  type(kvars_t),allocatable :: Kvars(:)
 82  character(len=fnlen) :: hdr_fnames(MAX_NFILES) = ABI_NOFILE
 83 
 84 ! *************************************************************************
 85 
 86  ! Change communicator for I/O (mandatory!)
 87  call abi_io_redirect(new_io_comm=xmpi_world)
 88 
 89  ! Initialize MPI
 90  call xmpi_init()
 91  comm = xmpi_world; my_rank = xmpi_comm_rank(comm); nprocs  = xmpi_comm_size(comm)
 92 
 93 !Initialize memory profiling if it is activated
 94 !if a full abimem.mocc report is desired, set the argument of abimem_init to "2" instead of "0"
 95 !note that abimem.mocc files can easily be multiple GB in size so don't use this option normally
 96 #ifdef HAVE_MEM_PROFILING
 97  call abimem_init(0)
 98 #endif
 99 
100  codename='ABIWFK'//REPEAT(' ',17)
101  call herald(codename,abinit_version,std_out)
102 
103  !verbose = .TRUE.
104  ount = dev_null; if (verbose) ount = std_out
105 
106  if (nprocs>1) then
107    MSG_ERROR("not programmed for parallel execution, Run it in sequential")
108  end if
109 
110  nargs = command_argument_count()
111 
112  ! Command line options.
113  do ii=1,command_argument_count()
114    call get_command_argument(ii, arg)
115    if (arg == "-v" .or. arg == "--version") then
116      write(std_out,"(a)") trim(abinit_version); goto 100
117 
118    else if (arg == "-h" .or. arg == "--help") then
119      ! Document the options.
120      write(std_out,*)"-v, --version                 Show version number and exit."
121      write(std_out,*)"info wfk_file                 Print info on WFK file"
122      write(std_out,*)"nc2fort ncfile fortran_file   Convert WFK ncfile to Fortran WFK file"
123      write(std_out,*)"-h, --help                    Show this help and exit."
124      goto 100
125    end if
126  end do
127 
128  call get_command_argument(1, command)
129 
130  select case (command)
131 
132  case ("info")
133    ! Print info
134    ABI_CHECK(nargs == 2, "Usage: info wfk_file")
135    call get_command_argument(2, wfk_path)
136    if (my_rank == master) then
137      formeig = 0
138      call wfk_open_read(wfk, wfk_path, formeig, iomode_from_fname(wfk_path), get_unit(), xmpi_comm_self)
139      call wfk_print(wfk)
140      call wfk_close(wfk)
141    end if
142 
143  case ("nc2fort")
144    ! Converter: netcdf --> Fortran
145    ABI_CHECK(nargs == 3, "Usage: nc2form wfk_source wfk_dest")
146    call get_command_argument(2, wfk_source)
147    call get_command_argument(3, wfk_dest)
148 
149    if (file_exists(wfk_dest)) then
150      MSG_ERROR(sjoin("Cannot overwrite:", wfk_dest, ". Remove file and rerun"))
151    end if
152 
153    if (my_rank == master) call wfk_nc2fort(wfk_source, wfk_dest)
154 
155  case ("prof")
156    ! Profile
157    ABI_CHECK(nargs > 1, "Usage: bench wfk_path")
158    call get_command_argument(2, wfk_path)
159    formeig = 0
160    nband2read = 1500
161    call wfk_prof(wfk_path, formeig, nband2read, comm)
162    ! TO CREATE new file
163    !call wfk_create_wfkfile(new_fname,hdr,iomode,formeig,Kvars,cwtimes,xmpi_comm_self)
164 
165  case ("unittests")
166    ! Unit tests.
167    do ii=1,count(hdr_fnames/=ABI_NOFILE)
168 
169      ! Read the header from an external netcdf file
170      ! This trick is needed because the initialization of
171      ! the header is *IMPOSSIBLE* if we don't have a full ABINIT input file!
172      !
173      call hdr_read_from_fname(hdr,hdr_fnames(ii),fform,comm)
174      ABI_CHECK(fform/=0,"fform==0")
175 
176      call hdr_echo(hdr,fform,4,unit=std_out)
177 
178      do feg=1,size(formeigs)
179        formeig = formeigs(feg)
180        do io=1,size(io_modes)
181          iomode = io_modes(io)
182 
183          new_fname = "NEW_WFK"
184          if (iomode==IO_MODE_ETSF) new_fname = "NEW_WFK.nc"
185 
186          if (file_exists(new_fname)) then
187            call delete_file(new_fname,ierr)
188          end if
189 
190          ! TODO
191          if (formeig==1 .and. iomode==IO_MODE_ETSF) then
192            MSG_WARNING("iomode==1 with ETSF_IO not coded yet")
193            CYCLE
194          end if
195 
196          ABI_DT_MALLOC(Kvars, (hdr%nkpt))
197 
198          if (my_rank == master) then
199            call wrtout(ount,"Calling wfk_create_wfkfile","COLL")
200            call wfk_create_wfkfile(new_fname,hdr,iomode,formeig,Kvars,cwtimes,xmpi_comm_self)
201            !call wfk_create_wfkfile(new_fname,hdr,IO_MODE_FORTRAN,formeig,Kvars,cwtimes,xmpi_comm_self)
202            call wrtout(ount,"Done wfk_create_wfkfile","COLL")
203          end if
204 
205          if (nprocs > 1) then
206            MSG_ERROR("Not coded")
207            !call kvars_mpicast(Kvars,master,comm)
208          end if
209 
210          method = 0
211 
212          call wrtout(std_out,sjoin("Checking file:",new_fname,", with iomode=",itoa(iomode)))
213          call wfk_check_wfkfile(new_fname,hdr,iomode,method,formeig,Kvars,cwtimes,comm,ierr)
214 
215          write(msg,'(2(a,i2),2(a,f8.2))')&
216          " Read with iomode: ",iomode,", nproc: ",nprocs,", cpu: ",cwtimes(1),", wall:",cwtimes(2)
217          call wrtout(ount,msg,"COLL")
218 
219          if (ierr/=0) then
220            MSG_ERROR(sjoin("wfk_check_wfkfile returned ierr ",itoa(ierr)))
221          end if
222 
223          ! If not netcdf file, try to read the file with the other mode that is compatible with it.
224          check_iomode = -100
225          if (iomode == IO_MODE_FORTRAN) check_iomode = IO_MODE_MPI
226          if (iomode == IO_MODE_MPI)     check_iomode = IO_MODE_FORTRAN
227 
228          if (check_iomode /= -100) then
229            call wrtout(std_out,sjoin("Trying to read file:",new_fname,", with check_iomode=",itoa(check_iomode)))
230 
231            call wfk_check_wfkfile(new_fname,hdr,check_iomode,method,formeig,Kvars,cwtimes,comm,ierr)
232 
233            write(msg,'(2(a,i2),2(a,f8.2))')&
234            " Read with iomode: ",iomode,", nproc: ",nprocs,", cpu: ",cwtimes(1),", wall:",cwtimes(2)
235            call wrtout(ount,msg,"COLL")
236 
237            if (ierr/=0) then
238              MSG_ERROR(sjoin("wfk_check_wfkfile returned ierr ",itoa(ierr)))
239            end if
240          end if
241 
242          ABI_DT_FREE(Kvars)
243        end do ! iomode
244      end do ! formeig
245 
246      call hdr_free(hdr)
247    end do
248 
249  case default
250    MSG_ERROR(sjoin("Unknown command:", command))
251  end select
252 
253  !call wrtout(std_out,ch10//" Analysis completed.","COLL")
254 
255 !Writes information on file about the memory before ending mpi module, if memory profiling is enabled
256  !ABI_ALLOCATE(nband, (2))
257  call abinit_doctor("__ioprof")
258 
259  100 call xmpi_end()
260 
261  end program ioprof