Branch data Line data Source code
1 : : !!****p* ABINIT/conducti
2 : : !! NAME
3 : : !! conducti
4 : : !!
5 : : !! FUNCTION
6 : : !! This program computes the elements of the optical frequency dependent
7 : : !! conductivity tensor and the conductivity along the three principal axes
8 : : !! from the Kubo-Greenwood formula.
9 : : !!
10 : : !! COPYRIGHT
11 : : !! Copyright (C) 2006-2026 ABINIT group (FJ,SMazevet)
12 : : !! This file is distributed under the terms of the
13 : : !! GNU General Public License, see ~abinit/COPYING
14 : : !! or http://www.gnu.org/copyleft/gpl.txt .
15 : : !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
16 : : !!
17 : : !! SOURCE
18 : :
19 : : #if defined HAVE_CONFIG_H
20 : : #include "config.h"
21 : : #endif
22 : :
23 : : #include "abi_common.h"
24 : : #include "nvtx_macros.h"
25 : :
26 : 34 : program conducti
27 : :
28 : 34 : use defs_basis
29 : : USE_MPI
30 : : use m_xmpi
31 : : use m_errors
32 : : #ifdef HAVE_MEM_PROFILING
33 : : use m_abicore
34 : : #endif
35 : : use m_conducti
36 : :
37 : : use m_io_tools, only : open_file
38 : : use m_time, only : timein,timab,time_accu
39 : : use m_fstrings, only : sjoin, itoa
40 : : use m_nctk, only : nctk_test_mpiio
41 : : use m_paw_optics,only : linear_optics_paw
42 : : use m_argparse, only : get_arg
43 : : use m_xomp, only : xomp_get_num_devices
44 : : #if defined(HAVE_GPU_MARKERS)
45 : : use m_nvtx_data
46 : : #endif
47 : : #ifdef HAVE_GPU
48 : : use m_gpu_toolbox
49 : : #endif
50 : :
51 : : implicit none
52 : :
53 : : !Local variables-------------------------------
54 : : !scalars
55 : : integer,parameter :: master=0
56 : : integer :: incpaw,nproc,comm,inunt,my_rank,mpierr,itim,ncount,gpu_option
57 : : logical :: use_gpu
58 : : real(dp) :: tcpu,tcpui,twall,twalli,wall_min,wall_max,flops
59 : : character(len=fnlen) :: filnam,filnam_out
60 : : character(len=500) :: msg
61 : : !arrays
62 : : integer,parameter :: tim_slots(3)=[1186,1187,1188]
63 : : character(len=17),parameter :: tim_names(3)=[character(len=17) :: 'conducti_paw','conducti_paw_core','conducti']
64 : : #if defined HAVE_GPU && defined HAVE_OPENMP_OFFLOAD
65 : : integer :: gpu_devices(12)
66 : : #endif
67 : : real(dp) :: tsec(2),tottim(2),ftimes(2)
68 : : ! *********************************************************************************
69 : :
70 : : !Change communicator for I/O (mandatory!)
71 : 34 : call abi_io_redirect(new_io_comm=xmpi_world)
72 : :
73 : : !Start, MPI init, ...
74 : 34 : call xmpi_init()
75 : :
76 : : !Start timers
77 : 34 : call timein(tcpui,twalli)
78 : 34 : call timab(1,0,tsec)
79 : :
80 : : ! Nominal conducti timer (abinit is 1)
81 : : ! We don't call timana and report manually here
82 : 34 : call timab(1188,1,tsec)
83 : :
84 : : !Initialize memory profiling if it is activated
85 : : !if a full abimem.mocc report is desired, set the argument of abimem_init to "2" instead of "0"
86 : : !note that abimem.mocc files can easily be multiple GB in size so don't use this option normally
87 : : #ifdef HAVE_MEM_PROFILING
88 : : call abimem_init(0)
89 : : #endif
90 : :
91 : : !Test if the netcdf library supports MPI-IO
92 : 34 : call nctk_test_mpiio(print_warning=.false.)
93 : :
94 : : !Enable GPU markers (NVTX/ROCTX) if required
95 : : #if defined(HAVE_GPU_MARKERS)
96 : : NVTX_INIT()
97 : : #endif
98 : :
99 : : !Extract MPI parallelization data
100 : 34 : comm = xmpi_world
101 : 34 : nproc = xmpi_comm_size(comm)
102 : 34 : my_rank = xmpi_comm_rank(comm)
103 : :
104 : : #if defined FC_NVHPC
105 : : if (nproc == -1) write(std_out, *)"NVHPC raises an internal compiler error that is fixed by this print statement."
106 : : #endif
107 : :
108 : : !Parse command line options
109 : : ! --use-gpu: use GPU (OpenMP offload) for the Kubo-Greenwood formula
110 [ - + ]: 34 : ABI_CHECK(get_arg("use-gpu",use_gpu,msg,default=.false.)==0,msg)
111 : :
112 : : !Activate GPU if required
113 : 34 : gpu_option=ABI_GPU_DISABLED
114 [ - + ]: 34 : if (use_gpu) gpu_option=ABI_GPU_OPENMP
115 : : #if defined HAVE_GPU && defined HAVE_OPENMP_OFFLOAD
116 : : !As in abinit (gpu_option), stop if no GPU is visible by OpenMP: never fall back silently on CPU
117 : : if (use_gpu.and.xomp_get_num_devices()==0) then
118 : : write(msg,'(11a)')&
119 : : '--use-gpu is given but no GPU is visible by OpenMP.',ch10,&
120 : : 'It usually happens when env variable OMP_TARGET_OFFLOAD is set to DISABLED (not default) ',ch10,&
121 : : 'or if there are inconsistencies between GPU driver and compiler ',ch10,&
122 : : 'as to which CUDA version is supported.',ch10,&
123 : : 'Action: check the value OMP_TARGET_OFFLOAD is not set to DISABLED,',ch10,&
124 : : ' otherwise make sure CUDA/HIP version you use is supported by BOTH your driver and compiler.'
125 : : ABI_ERROR(msg)
126 : : end if
127 : : gpu_devices(:)=-1
128 : : call setdevice_cuda(gpu_devices,gpu_option)
129 : : if (use_gpu.and.gpu_option==ABI_GPU_DISABLED) then
130 : : ABI_ERROR("--use-gpu is given but no GPU device has been found.")
131 : : end if
132 : : #else
133 [ - + ]: 34 : if (use_gpu) then
134 : 0 : ABI_ERROR("--use-gpu requires ABINIT built with GPU and OpenMP offload support.")
135 : : end if
136 : : #endif
137 : 34 : use_gpu=(gpu_option==ABI_GPU_OPENMP)
138 [ - + ]: 34 : if (my_rank==master.and.use_gpu) write(std_out,'(a)') ' Using GPU (OpenMP offload)'
139 : :
140 : : !Read some input data
141 [ + + ]: 34 : if (my_rank==master) then
142 : :
143 : : ! Read data file name
144 : 22 : write(std_out,'(a)')' Please, give the name of the data file ...'
145 : 22 : read(std_in, '(a)') filnam
146 [ + - ]: 22 : write(std_out,'(2a)')' The name of the data file is: ',trim(filnam)
147 : :
148 : : #if defined FC_NVHPC
149 : : if (nproc == -1) write(std_out, *)"NVHPC raises an internal compiler error that is fixed by this print statement."
150 : : #endif
151 : :
152 : : ! Read type of calculation
153 [ + - ]: 22 : if (open_file(filnam,msg,newunit=inunt,form='formatted')==0) then
154 : 22 : rewind(inunt)
155 : 22 : read(inunt,*) incpaw
156 : 22 : close(inunt)
157 : : else
158 : 0 : ABI_ERROR('Error opening data file!')
159 : : end if
160 : :
161 : : ! Read output file name
162 : 22 : write(std_out,'(a)')' Give the name of the output file ...'
163 : 22 : read(std_in, '(a)') filnam_out
164 : 22 : write(std_out,'(2a)')' The name of the output file is: ',filnam_out
165 : : end if
166 : :
167 : : !Broadcast input data
168 : 34 : call xmpi_bcast(incpaw,master,comm,mpierr)
169 : 34 : call xmpi_bcast(filnam,master,comm,mpierr)
170 : 34 : call xmpi_bcast(filnam_out,master,comm,mpierr)
171 : :
172 : : !Call main routine
173 : 2 : select case (incpaw)
174 : : case (1)
175 [ + - ]: 4 : if (my_rank==master) then
176 : 2 : call conducti_nc(filnam,filnam_out)
177 : : end if
178 : : case (2)
179 : 4 : call conducti_paw(filnam,filnam_out,use_gpu=use_gpu)
180 : : case (3)
181 [ # # ]: 0 : if (my_rank==master) then
182 : 0 : call linear_optics_paw(filnam,filnam_out)
183 : : end if
184 : : case (4)
185 : 24 : call conducti_paw(filnam,filnam_out,use_gpu=use_gpu)
186 : 24 : call conducti_paw_core(filnam,filnam_out,with_absorption=.true.,with_emissivity=.true.)
187 : : case (5)
188 : 4 : call conducti_paw_core(filnam,filnam_out,with_absorption=.true.)
189 : : case (6)
190 : 0 : call conducti_paw_core(filnam,filnam_out,with_absorption=.true.,with_emissivity=.true.)
191 : : case (42)
192 : 0 : call conducti_paw(filnam,filnam_out,varocc=1,use_gpu=use_gpu)
193 : : case default
194 [ + + - + : 34 : ABI_ERROR(sjoin("Wrong incpaw:", itoa(incpaw)))
+ - - - ]
195 : : end select
196 : :
197 : : ! End of all operations
198 : 34 : call timab(1188,2,tsec)
199 : :
200 : : !Report timers of the routines that have been called
201 [ + + ]: 136 : do itim=1,size(tim_slots)
202 : 102 : call time_accu(tim_slots(itim),ncount,tottim,flops,ftimes)
203 [ + + ]: 136 : if (ncount>0) then
204 : 90 : call xmpi_min(tottim(2),wall_min,comm,mpierr)
205 : 90 : call xmpi_max(tottim(2),wall_max,comm,mpierr)
206 [ + + ]: 90 : if (my_rank==master) then
207 : : write(std_out,'(a,a17,a,f13.1,a,f13.1,a,f13.1)') &
208 : 54 : '- ',tim_names(itim),' time (sec): cpu(proc 0)=',tottim(1), &
209 : 108 : ' wall(min/max over procs)=',wall_min,' /',wall_max
210 : : end if
211 : : end if
212 : : end do
213 : :
214 : : !End, memory cleaning
215 : 34 : call timein(tcpu,twall)
216 : 34 : tsec(1)=tcpu-tcpui
217 : 34 : tsec(2)=twall-twalli
218 [ + + ]: 34 : if (my_rank==0) then
219 : : write(std_out, '(a,a,a,f13.1,a,f13.1)' ) &
220 : 22 : '-',ch10,'- Proc. 0 individual time (sec): cpu=',tsec(1),' wall=',tsec(2)
221 : : end if
222 : :
223 : : #if defined HAVE_GPU && defined HAVE_OPENMP_OFFLOAD
224 : : call unsetdevice_cuda(gpu_option)
225 : : #endif
226 : :
227 : 34 : call abinit_doctor("__conducti")
228 : 34 : call xmpi_end()
229 : :
230 : 0 : end program conducti
231 : : !!***
|