TABLE OF CONTENTS


ABINIT/multibinit [ Programs ]

[ Top ] [ Programs ]

NAME

 multibinit

FUNCTION

 Main routine MULTIBINIT.

COPYRIGHT

 Copyright (C) 1999-2024 ABINIT group (AM)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .
 For the initials of contributors, see ~abinit/doc/developers/contributors.txt .

INPUTS

  (main routine)

OUTPUT

  (main routine)

SOURCE

 23 #if defined HAVE_CONFIG_H
 24 #include "config.h"
 25 #endif
 26 
 27 #include "abi_common.h"
 28 
 29 program multibinit
 30 
 31   use defs_basis
 32   use defs_abitypes
 33   use m_xmpi
 34   use m_xomp
 35   use m_abicore
 36   use m_errors
 37   use m_argparse
 38   use m_effective_potential
 39   use m_fit_polynomial_coeff
 40   use m_multibinit_dataset
 41   use m_effective_potential_file
 42   use m_abihist
 43 
 44   use m_build_info, only : abinit_version
 45   use m_specialmsg, only : specialmsg_getcount
 46   use m_io_tools,   only : flush_unit, open_file
 47   use m_time,       only : asctime, timein
 48   use m_dtfil,      only : isfile
 49 
 50   !use m_generate_training_set, only : generate_training_set
 51   !use m_compute_anharmonics, only : compute_anharmonics
 52   use m_init10,              only : init10
 53   use m_multibinit_unittest, only: mb_test_main
 54   use m_multibinit_driver
 55   use m_multibinit_main2, only: multibinit_main2, herald_multibinit
 56 
 57   implicit none
 58 
 59   !Arguments -----------------------------------
 60 
 61   !Local variables-------------------------------
 62   ! Set array dimensions
 63   real(dp) :: tcpu,tcpui,twall,twalli
 64   real(dp) :: tsec(2)
 65   character(len=24) :: codename,start_datetime
 66   character(len=fnlen) :: filnam(18),tmpfilename
 67   character(len=500) :: message
 68   type(args_t) :: args
 69   integer :: ii
 70   integer :: master, my_rank, comm, nproc, ierr
 71   logical :: iam_master
 72 
 73   !TEST_AM
 74   ! integer :: natom_sp
 75   ! real(dp),allocatable :: dynmat(:,:,:,:,:)
 76   !TEST_AM
 77   !******************************************************************
 78 
 79   !Change communicator for I/O (mandatory!)
 80   call abi_io_redirect(new_io_comm=xmpi_world)
 81 
 82   !Initialize MPI
 83   call xmpi_init()
 84 
 85   master = 0
 86   comm = xmpi_world
 87   nproc = xmpi_comm_size(comm)
 88   my_rank = xmpi_comm_rank(comm)
 89   iam_master = (my_rank == master)
 90 
 91   ! Parse command line arguments.
 92   args = args_parser(); if (args%exit /= 0) goto 100
 93 
 94 
 95  ! Initialize memory profiling if activated at configure time.
 96  ! if a full report is desired, set the argument of abimem_init to "2" instead of "0" via the command line.
 97  ! note that the file can easily be multiple GB in size so don't use this option normally
 98 #ifdef HAVE_MEM_PROFILING
 99  call abimem_init(args%abimem_level, limit_mb=args%abimem_limit_mb)
100 #endif
101 
102   !Initialisation of the timing
103   call timein(tcpui,twalli)
104 
105   if (iam_master) then
106      codename='MULTIBINIT'//repeat(' ',14)
107      call herald_multibinit(codename,abinit_version,std_out, args%multibinit_F03_mode/=1)
108   end if
109 
110   start_datetime = asctime()
111   !Print the number of cpus in log file
112   write(message,'(a,i5,a)') '-  nproc =',nproc,ch10
113   call wrtout(std_out,message,'COLL')
114 
115   !Initialise the code : write heading, and read names of files.
116   call init10(args%input_path, filnam,comm)
117 
118   ! set filnam(2), and (3) from input path
119   if (len_trim(args%input_path)/=0) then
120      call invars_multibinit_filenames_from_input_file(args%input_path, filnam(2), filnam(3))
121   end if
122 
123   !******************************************************************
124 
125   call timein(tcpu,twall)
126 
127   write(message, '(a,f11.3,a,f11.3,a)' )'-begin at tcpu',tcpu-tcpui,'  and twall',twall-twalli,' sec'
128   call wrtout(std_out,message,'COLL')
129 
130   ! Open output files and ab_out (might change its name if needed)
131   ! MJV 1/2010 : now output file is open, but filnam(2) continues unmodified
132   ! so the other output files are overwritten instead of accumulating.
133   if (iam_master) then
134      tmpfilename = filnam(2)
135      call isfile(tmpfilename,'new')
136      if (open_file(tmpfilename,message,unit=ab_out,form="formatted",status="new",&
137           &   action="write") /= 0) then
138         ABI_ERROR(message)
139      end if
140      !  Call open_file(unit=ab_out,file=tmpfilename,form='formatted',status='new')
141      rewind (unit=ab_out)
142      call herald_multibinit(codename,abinit_version,ab_out, args%multibinit_F03_mode/=1)
143      !  Print the number of cpus in output
144      write(message,'(a,i5,a)') '-  nproc =',nproc
145      call wrtout(ab_out,message,'COLL')
146   else
147      ab_out = dev_null
148   end if
149 
150   write(message, '(a,(80a),a)' ) ch10,&
151        & ('=',ii=1,80),ch10
152   call wrtout(ab_out,message,'COLL')
153   call wrtout(std_out,message,'COLL')
154 
155 
156   !***************************************************************************************
157   !***************************************************************************************
158   if(args%multibinit_F03_mode==1) then
159      ! Use the F03 mode, which has only spin and a simple harmonic lattice now
160      ! After everything is migrated, it will becomes default and multibinit_main will be deprecated.
161      call multibinit_main2(args%input_path,filnam, args%dry_run)
162   else
163      call multibinit_main(args%input_path, filnam, args%dry_run)
164   end if
165   ! Final message
166   !****************************************************************************************
167 
168   write(message,'(a,a,a,(80a))') ch10,('=',ii=1,80),ch10
169   call wrtout(ab_out,message,'COLL')
170   call wrtout(std_out,message,'COLL')
171 
172   call timein(tcpu,twall)
173   tsec(1)=tcpu-tcpui
174   tsec(2)=twall-twalli
175 
176   write(message, '(a,i4,a,f13.1,a,f13.1)' )' Proc.',my_rank,' individual time (sec): cpu=',&
177        &   tsec(1),'  wall=',tsec(2)
178   call wrtout(std_out,message,"COLL")
179 
180   if (iam_master) then
181      write(ab_out, '(a,a,a,i4,a,f13.1,a,f13.1)' )'-',ch10,&
182           &     '- Proc.',my_rank,' individual time (sec): cpu=',tsec(1),'  wall=',tsec(2)
183   end if
184 
185    call xmpi_sum(tsec,comm,ierr)
186 
187    write(message, '(a,(80a),a,a,a,f11.3,a,f11.3,a,a,a,a)' ) ch10,&
188 &   ('=',ii=1,80),ch10,ch10,&
189 &   '+Total cpu time',tsec(1),&
190 &   '  and wall time',tsec(2),' sec',ch10,ch10,&
191 &   ' multibinit : the run completed succesfully.'
192    call wrtout(std_out,message,'COLL')
193    call wrtout(ab_out,message,'COLL')
194 
195    if (iam_master) then
196    ! Write YAML document with the final summary.
197    ! we use this doc to test whether the calculation is completed.
198      write(std_out,"(a)")"--- !FinalSummary"
199      write(std_out,"(a)")"program: multibinit"
200      write(std_out,"(2a)")"version: ",trim(abinit_version)
201      write(std_out,"(2a)")"start_datetime: ",start_datetime
202      write(std_out,"(2a)")"end_datetime: ",asctime()
203      write(std_out,"(a,f13.1)")"overall_cpu_time: ",tsec(1)
204      write(std_out,"(a,f13.1)")"overall_wall_time: ",tsec(2)
205      write(std_out,"(a,i0)")"mpi_procs: ",xmpi_comm_size(xmpi_world)
206      write(std_out,"(a,i0)")"omp_threads: ",xomp_get_num_threads(open_parallel=.True.)
207    !write(std_out,"(a,i0)")"num_warnings: ",nwarning
208    !write(std_out,"(a,i0)")"num_comments: ",ncomment
209      write(std_out,"(a)")"..."
210      call flush_unit(std_out)
211    end if
212 
213 !Write information on file about the memory before ending mpi module, if memory profiling is enabled
214    call abinit_doctor("__multibinit")
215 
216    call flush_unit(ab_out)
217    call flush_unit(std_out)
218 
219    if (iam_master) close(ab_out)
220 
221    100 call xmpi_end()
222 
223    end program multibinit