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