Octopus
global.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module global_oct_m
22 use, intrinsic :: iso_c_binding, only: c_int
23 use, intrinsic :: iso_fortran_env
25 use loct_oct_m
26 use mpi_oct_m
27 use string_oct_m
29#ifdef HAVE_OPENMP
30 use omp_lib
31#endif
32
33 implicit none
34
35 private
36
38 public :: &
39 conf_t, &
41 global_end, &
44 assert_die, &
46 operator(+), &
47 bitand, &
48 int32, int64, &
49 real32, real64, &
50 i4_to_i8, &
52 ! Make these kind variables from kind_oct_m public here so that they are
53 ! available basically everywhere in the code. They still need to be in a
54 ! separate module because they are also needed in some low-level modules.
55
56 interface
57 function openblas_get_version(major, minor, patch) bind(C) result(ierr)
58 use, intrinsic :: iso_c_binding, only: c_int
59 integer(c_int), intent(inout) :: major, minor, patch
60 integer(c_int) :: ierr
61 end function
62 end interface
63
64 integer, public, parameter :: MAX_PATH_LEN=512
65 integer, public, parameter :: MAX_OUTPUT_TYPES=46
66
68 type conf_t
69 logical :: devel_version
70 logical :: report_memory
71 character(len=256) :: share = share_dir
72 character(len=256) :: build_dir = build_dir
73 character(len=256) :: git_commit = git_commit
74 character(len=50) :: config_time = build_time
75 character(len=20) :: version = package_version
76 character(len=256) :: cc = cc
77 character(len=256) :: cxx = cxx
78 character(len=256) :: fc = fc
79 ! Split flag definitions in case they don`t fit in one line, following preprocessing
80 character(len=256) :: cflags = &
81 cflags //&
82 cflags_extra
83 character(len=256) :: cxxflags = &
84 cxxflags //&
85 cxxflags_extra
86 character(len=512) :: fcflags = &
87 fcflags //&
88 fcflags_extra
89 integer :: target_states_block_size = -1
90 contains
91 procedure :: init => conf_init
92 end type conf_t
93
95 type(conf_t), public :: conf
96
97 real(real64), public, parameter :: R_SMALL = 1e-8_real64
98
100 real(real64), public, parameter :: R_MIN_ATOM_DIST = 1e-3_real64
101
103 real(real64), public, parameter :: M_Pi = 3.1415926535897932384626433832795029_real64
104 real(real64), public, parameter :: M_E = 2.7182818284590452353602874713526625_real64
105 real(real64), public, parameter :: M_ZERO = 0.0_real64
106 real(real64), public, parameter :: M_ONE = 1.0_real64
107 real(real64), public, parameter :: M_TWO = 2.0_real64
108 real(real64), public, parameter :: M_THREE = 3.0_real64
109 real(real64), public, parameter :: M_FOUR = 4.0_real64
110 real(real64), public, parameter :: M_FIVE = 5.0_real64
111 real(real64), public, parameter :: M_HALF = 0.5_real64
112 real(real64), public, parameter :: M_THIRD = m_one/m_three
113 real(real64), public, parameter :: M_TWOTHIRD = m_two/m_three
114 real(real64), public, parameter :: M_FOURTH = m_one/m_four
115 complex(real64), public, parameter :: M_z0 = (0.0_real64, 0.0_real64)
116 complex(real64), public, parameter :: M_z1 = (1.0_real64, 0.0_real64)
117 complex(real64), public, parameter :: M_z2 = (2.0_real64, 0.0_real64)
118 complex(real64), public, parameter :: M_z2I = (0.0_real64, 2.0_real64)
119 complex(real64), public, parameter :: M_zI = (0.0_real64, 1.0_real64)
120
121 real(real64), public, parameter :: M_EPSILON = epsilon(m_one)
122 real(real64), public, parameter :: M_TINY = tiny(m_one)
123 real(real64), public, parameter :: M_HUGE = huge(m_one)
124 real(real64), public, parameter :: M_MIN_EXP_ARG = -650_real64
125 real(real64), public, parameter :: M_MAX_EXP_ARG = 700_real64
126 real(real64), public, protected :: M_PINF
127 real(real64), public, protected :: M_NINF
128 real(real64), public, protected :: M_SNAN
129 real(real64), public, protected :: M_QNAN
130
132 real(real64), public, parameter :: M_MIN_OCC = 1.0e-10_real64
134 real(real64), public, parameter :: M_MIN_DENSITY = 1.0e-20_real64
136 real(real64), public, parameter :: M_DEGENERARY_THRESHOLD = 1.0e-6_real64
137
139 real(real64), public, parameter :: LMM_R_SINGLE_ATOM = 100.0_real64
140
142 real(real64), public, parameter :: P_a_B = 0.52917720859_real64
143 real(real64), public, parameter :: P_Ang = m_one / p_a_b
144 real(real64), public, parameter :: P_Ry = 13.60569193_real64
145 real(real64), public, parameter :: P_eV = m_one / p_ry
146 real(real64), public, parameter :: P_Kb = 8.617343e-5_real64/(m_two*p_ry)
147 real(real64), public, parameter :: P_c = 137.035999679_real64
148
149 real(real64), public, parameter :: P_g = 2.00231930436118_real64
150 real(real64), public, parameter :: P_PROTON_CHARGE = -1.0_real64
151 real(real64), public, parameter :: P_ep = m_one/(m_four*m_pi)
152 real(real64), public, parameter :: p_mu = m_four*m_pi/(p_c**2)
153
155 integer, public, parameter :: &
157 hartree = 1, &
158 hartree_fock = 3, &
161 rdmft = 7
162
164 integer, public :: stderr, stdin, stdout
167 integer, public :: s_epoch_sec, s_epoch_usec
170 character(len=80), public :: sub_stack(50)
171 real(real64), public :: time_stack(50)
172 integer, public :: no_sub_stack = 0
175 logical, public :: in_profiling_mode = .false.
176
177 integer, public :: global_alloc_err
178 integer(int64), public :: global_sizeof
179 character(len=100), public :: global_alloc_errmsg
180 !$omp threadprivate(global_alloc_err, global_sizeof, global_alloc_errmsg)
182 ! The code directories should be defined here, and not hard coded in the Fortran files.
183 character(len=*), public, parameter :: gs_dir = "gs/"
184 character(len=*), public, parameter :: td_dir = "td/"
185 character(len=*), public, parameter :: static_dir = "static/"
186 character(len=*), public, parameter :: em_resp_dir = "em_resp/"
187 character(len=*), public, parameter :: em_resp_fd_dir = "em_resp_fd/"
188 character(len=*), public, parameter :: kdotp_dir = "kdotp/"
189 character(len=*), public, parameter :: vib_modes_dir = "vib_modes/"
190 character(len=*), public, parameter :: vdw_dir = "vdw/"
191 character(len=*), public, parameter :: casida_dir = "casida/"
192 character(len=*), public, parameter :: oct_dir = "opt-control/"
193 character(len=*), public, parameter :: pcm_dir = "pcm/"
194 character(len=*), public, parameter :: partition_dir = "partition/"
195 character(len=*), public, parameter :: iteration_dir = "iteration/"
196 character(len=*), public, parameter :: dm_dir = "dm/"
197
200 type(mpi_comm), public, parameter :: serial_dummy_comm = mpi_comm_undefined
202 ! End of declaration of public objects.
203 ! ---------------------------------------------------------
208 end interface optional_default
212 interface
213 subroutine assert_die(s, f, l)
214 implicit none
215 character(len=*), intent(in) :: s, f
216 integer, intent(in) :: l
217 end subroutine assert_die
218 end interface
220 interface operator (+)
221 module procedure cat
222 end interface operator (+)
224 interface bitand
225 module procedure bitand48
226 module procedure bitand84
227 module procedure bitand88
228 module procedure bitand44
229 end interface bitand
230
231 interface i4_to_i8
232 module procedure i4_to_i8_0, i4_to_i8_1
233 end interface i4_to_i8
235 interface i8_to_i4
236 module procedure i8_to_i4_0, i8_to_i4_1
237 end interface i8_to_i4
239contains
242 subroutine conf_init(this)
243 class(conf_t), intent(inout) :: this
245 character(len=MAX_PATH_LEN) :: share
246 character(len=MAX_PATH_LEN) :: path_exe, dir_exe
248 ! First, get the environment variable OCTOPUS_SHARE that overrides the default
249 call loct_getenv("OCTOPUS_SHARE", share)
250 if (trim(share) /= "") then
251 this%share = trim(share)
252 return
253 end if
254 ! Second, try a share directory next to the binary; this makes it work in the build tree
255 call loct_executable_path(path_exe)
256 if (trim(path_exe) /= "") then
257 ! we got a useable path, search for the share folder
258 call loct_dirname(path_exe, dir_exe)
259 share = trim(dir_exe) // "/share"
260 if (loct_dir_exists(share)) then
261 this%share = trim(share)
262 return
263 end if
264 end if
265 ! Third, take the value from the configuration step, check if it exists
266 if (.not.loct_dir_exists(conf%share)) then
267 write(*, "(A)") "Error: could not find share directory."
268 write(*, "(A, A)") "Configured location: ", trim(conf%share)
269 stop
270 end if
271
272 end subroutine conf_init
280 subroutine global_init(communicator)
281 type(mpi_comm), intent(in), optional :: communicator
283 type(mpi_comm) :: comm
285 if (present(communicator)) then
286 comm = communicator
288 else
289 call mpi_init_comm(comm)
290 endif
292 call init_octopus_globals(comm)
293
296 ! Order of call is important. mpi_world is used implicitly by blacs_init
297 call blacs_init()
298
299 end subroutine global_init
301
307
308 integer(c_int) :: ierr, major, minor, patch
309
310 major = 0
311 minor = 0
312 patch = 0
313 ierr = openblas_get_version(major, minor, patch)
314
315 if (ierr == 0) then
316 ! Implies that the formatting of the config message has changed
317 error stop "openblas_get_config failed to return a version"
318 endif
319 if (ierr == 1 .and. major == 0 .and. minor == 3 .and. patch == 32) then
320 error stop "Octopus is linked to OpenBLAS 0.3.32, which is buggy"
321 end if
322
323 end subroutine global_check_openblas_version
324
325
337 subroutine init_octopus_globals(comm)
338 type(mpi_comm), intent(in) :: comm
339
340 character(len=256) :: path
341
342 call mpi_grp_init(mpi_world, comm)
343
344 call mpi_world%barrier()
345 ! Get epoch time at node startup, just after the barrier to synchronize nodes first.
347
348 ! These defaults are initialised here because the Intel 2022a compiler complains:
349 ! "This array or function or substring is invalid in constant expressions"
350 ! This is not a problem with Intel 2023a, and so can be returned to hardware.F90
351 ! once Intel 2022a support is dropped
352 default_l1 = cache_t( 32*1024, 64)
353 default_l2 = cache_t(4096*1024, 64)
354
355 ! TODO(Alex) Issue 1013. Change hardware class to a free function, and make cache_t instance global.
357
358 call conf%init()
359
360 ! initialize info for the input variables
361 path = trim(conf%share)//'/varinfo'
362 call varinfo_init(string_f_to_c(path))
363
364 block
365 use, intrinsic :: ieee_arithmetic, only: &
366 ieee_negative_inf, &
367 ieee_positive_inf, &
368 ieee_quiet_nan, &
369 ieee_signaling_nan, &
370 ieee_support_inf, &
371 ieee_support_nan, &
372 ieee_value
373 if (ieee_support_inf(m_pinf)) then
374 m_pinf = ieee_value(m_pinf, ieee_positive_inf)
375 else
376 m_pinf = huge(m_pinf)
377 end if
378 if (ieee_support_inf(m_ninf)) then
379 m_ninf = ieee_value(m_ninf, ieee_negative_inf)
380 else
381 m_ninf = -huge(m_ninf)
382 end if
383 if (ieee_support_nan(m_qnan)) then
384 m_qnan = ieee_value(m_qnan, ieee_quiet_nan)
385 else
386 m_qnan = real(0.0, kind(m_qnan))
387 end if
388 if (ieee_support_nan(m_snan)) then
389 m_snan = ieee_value(m_snan, ieee_signaling_nan)
390 else
391 m_snan = real(0.0, kind(m_snan))
392 end if
393 end block
394
395 end subroutine init_octopus_globals
396
397
399 subroutine global_end()
400
402 call mpi_mod_end()
403
404 end subroutine global_end
405
406
407 real(real64) pure function doptional_default(opt, def) result(val)
408 real(real64), optional, intent(in) :: opt
409 real(real64), intent(in) :: def
410
411 val = def
412 if (present(opt)) val = opt
413 end function doptional_default
414
415 !----------------------------------------------------------
416
417 complex(real64) pure function zoptional_default(opt, def) result(val)
418 complex(real64), optional, intent(in) :: opt
419 complex(real64), intent(in) :: def
420
421 val = def
422 if (present(opt)) val = opt
423 end function zoptional_default
424
425 !----------------------------------------------------------
426
427 integer pure function ioptional_default(opt, def) result(val)
428 integer, optional, intent(in) :: opt
429 integer, intent(in) :: def
430
431 val = def
432 if (present(opt)) val = opt
433 end function ioptional_default
434
435 !----------------------------------------------------------
436
437 integer(int64) pure function loptional_default(opt, def) result(val)
438 integer(int64), optional, intent(in) :: opt
439 integer(int64), intent(in) :: def
440
441 val = def
442 if (present(opt)) val = opt
443 end function loptional_default
444
445 !----------------------------------------------------------
446
447 logical pure function looptional_default(opt, def) result(val)
448 logical, optional, intent(in) :: opt
449 logical, intent(in) :: def
450
451 val = def
452 if (present(opt)) val = opt
453 end function looptional_default
454
455 !----------------------------------------------------------
456
457 character(len=80) pure function soptional_default(opt, def) result(val)
458 character(len=*), optional, intent(in) :: opt
459 character(len=*), intent(in) :: def
460
461 val = def
462 if (present(opt)) val = opt
463 end function soptional_default
464
465 !-----------------------------------------------------------
466
467 logical &
468#ifndef have_openmp
469 pure &
470#endif
471 function not_in_openmp()
472
473#ifdef HAVE_OPENMP
474 not_in_openmp = .not. omp_in_parallel()
475#else
477#endif
478
479 end function not_in_openmp
480
481 !-----------------------------------------------------------
482
483 function cat(str1, str2)
484 character(len=*), intent(in) :: str1
485 character(len=*), intent(in) :: str2
486
487 character(len=len(str1) + len(str2)) :: cat
488 cat = str1//str2
489
490 end function cat
491
492 ! -----------------------------------------------------------
493
494 integer(int64) pure function bitand48(val1, val2)
495 integer(int32), intent(in) :: val1
496 integer(int64), intent(in) :: val2
497
498 bitand48 = iand(int(val1, int64), val2)
499
500 end function bitand48
501
502 ! -----------------------------------------------------------
503
504 integer(int64) pure function bitand84(val1, val2)
505 integer(int64), intent(in) :: val1
506 integer(int32), intent(in) :: val2
507
508 bitand84 = iand(val1, int(val2, int64))
509
510 end function bitand84
511
512 ! -----------------------------------------------------------
513
514 integer(int64) pure function bitand88(val1, val2)
515 integer(int64), intent(in) :: val1
516 integer(int64), intent(in) :: val2
517
518 bitand88 = iand(val1, val2)
519
520 end function bitand88
521
522 ! -----------------------------------------------------------
523
524 integer(int32) pure function bitand44(val1, val2)
525 integer(int32), intent(in) :: val1
526 integer(int32), intent(in) :: val2
527
528 bitand44 = iand(val1, val2)
529
530 end function bitand44
531
532 ! -----------------------------------------------------------
533
534 integer(int64) pure function i4_to_i8_0(ii)
535 integer(int32), intent(in) :: ii
536
537 i4_to_i8_0 = int(ii, int64)
538 end function i4_to_i8_0
539
540 ! -----------------------------------------------------------
541
542 integer(int32) pure function i8_to_i4_0(ii)
543 integer(int64), intent(in) :: ii
544
545 i8_to_i4_0 = int(ii, int32)
546 end function i8_to_i4_0
547
548 ! -----------------------------------------------------------
549
550 pure function i4_to_i8_1(ii)
551 integer(int32), intent(in) :: ii(:)
552 integer(int64) :: i4_to_i8_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
553
554 i4_to_i8_1 = int(ii, int64)
555 end function i4_to_i8_1
556
557 ! -----------------------------------------------------------
558
559 pure function i8_to_i4_1(ii)
560 integer(int64), intent(in) :: ii(:)
561 integer(int32) :: i8_to_i4_1(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64))
563 i8_to_i4_1 = int(ii, int32)
564 end function i8_to_i4_1
565
566end module global_oct_m
567
568!! Local Variables:
569!! mode: f90
570!! coding: utf-8
571!! End:
This function is defined in messages.F90.
Definition: global.F90:308
Public types, variables and procedures.
Definition: global.F90:152
character(len= *), parameter, public em_resp_fd_dir
Definition: global.F90:282
integer(int32) pure function bitand44(val1, val2)
Definition: global.F90:620
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:495
pure integer(int32) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i8_to_i4_1(ii)
Definition: global.F90:655
character(len= *), parameter, public gs_dir
Definition: global.F90:278
integer(int64) pure function bitand88(val1, val2)
Definition: global.F90:610
integer(int64) pure function i4_to_i8_0(ii)
Definition: global.F90:630
character(len= *), parameter, public iteration_dir
Definition: global.F90:290
integer, public s_epoch_sec
global epoch time (time at startup)
Definition: global.F90:262
integer pure function ioptional_default(opt, def)
Definition: global.F90:523
integer, public no_sub_stack
Definition: global.F90:267
character(len= *), parameter, public casida_dir
Definition: global.F90:286
integer, parameter, public rdmft
Definition: global.F90:250
integer(int64), public global_sizeof
Definition: global.F90:273
character(len= *), parameter, public pcm_dir
Definition: global.F90:288
integer(int64) pure function bitand84(val1, val2)
Definition: global.F90:600
real(real64), parameter, public p_mu
Definition: global.F90:247
integer, parameter, public hartree_fock
Definition: global.F90:250
character(len= *), parameter, public vib_modes_dir
Definition: global.F90:284
character(len= *), parameter, public partition_dir
Definition: global.F90:289
integer(int64) pure function loptional_default(opt, def)
Definition: global.F90:533
character(len= *), parameter, public kdotp_dir
Definition: global.F90:283
character(len= *), parameter, public dm_dir
Definition: global.F90:291
integer, parameter, public independent_particles
Theory level.
Definition: global.F90:250
character(len=len(str1)+len(str2)) function cat(str1, str2)
Definition: global.F90:579
type(mpi_comm), parameter, public serial_dummy_comm
Alias MPI_COMM_UNDEFINED for the specific use case of initialising Octopus utilities with no MPI supp...
Definition: global.F90:295
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:433
real(real64), dimension(50), public time_stack
Definition: global.F90:266
logical pure function, public not_in_openmp()
Definition: global.F90:567
real(real64) pure function doptional_default(opt, def)
Definition: global.F90:503
logical pure function looptional_default(opt, def)
Definition: global.F90:543
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
integer(int32) pure function i8_to_i4_0(ii)
Definition: global.F90:638
character(len=80), dimension(50), public sub_stack
The stack.
Definition: global.F90:265
integer, public s_epoch_usec
Definition: global.F90:262
character(len= *), parameter, public em_resp_dir
Definition: global.F90:281
character(len=100), public global_alloc_errmsg
Definition: global.F90:274
logical, public in_profiling_mode
Same for profiling mode.
Definition: global.F90:270
integer, public global_alloc_err
Definition: global.F90:272
subroutine global_check_openblas_version()
Check OpenBLAS version and terminate if Octopus is linked to version 0.3.32.
Definition: global.F90:402
character(len=80) pure function soptional_default(opt, def)
Definition: global.F90:553
character(len= *), parameter, public td_dir
Definition: global.F90:279
pure integer(int64) function, dimension(lbound(ii, 1, kind=int64):ubound(ii, 1, kind=int64)) i4_to_i8_1(ii)
Definition: global.F90:646
character(len= *), parameter, public static_dir
Definition: global.F90:280
subroutine, public global_init(communicator)
Initialise Octopus.
Definition: global.F90:376
complex(real64) pure function zoptional_default(opt, def)
Definition: global.F90:513
subroutine conf_init(this)
Initialiser for conf_t.
Definition: global.F90:338
integer, parameter, public hartree
Definition: global.F90:250
character(len= *), parameter, public vdw_dir
Definition: global.F90:285
character(len= *), parameter, public oct_dir
Definition: global.F90:287
integer(int64) pure function bitand48(val1, val2)
Definition: global.F90:590
type(hardware_t), public cpu_hardware
Global instance of CPU hardware specification.
Definition: hardware.F90:61
type(cache_t), public default_l2
Definition: hardware.F90:65
type(cache_t), public default_l1
Defaults covers common chip specification for (l1, l2) cache.
Definition: hardware.F90:64
System information (time, memory, sysname)
Definition: loct.F90:117
subroutine, public loct_getenv(var, val)
Definition: loct.F90:364
subroutine, public loct_dirname(path, dir)
Definition: loct.F90:442
logical function, public loct_dir_exists(dirname)
Definition: loct.F90:349
character(kind=c_char, len=1) function, dimension(len_trim(f_string)+1), private string_f_to_c(f_string)
convert a Fortran string to a C string
Definition: loct.F90:240
subroutine, public loct_executable_path(fpath)
Definition: loct.F90:425
subroutine blacs_init()
Initialize BLACS to enable use of SCALAPACK.
Definition: mpi.F90:316
subroutine check_threading_support(comm)
Check that the threading support of the MPI library is consistent with the requested support from Oct...
Definition: mpi.F90:306
type(mpi_comm), parameter, public mpi_comm_undefined
used to indicate a communicator has not been initialized
Definition: mpi.F90:138
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:272
subroutine mpi_grp_init(grp, comm)
Initialize MPI group instance.
Definition: mpi.F90:341
subroutine mpi_init_comm(comm)
Wrapper for MPI_COMM_WORLD initialisation.
Definition: mpi.F90:295
static double f(double w, void *p)
Build configuration type.
Definition: global.F90:163
int true(void)
void varinfo_end()
Definition: varinfo_low.c:2982