Skip to content

Commit

Permalink
Merge pull request #116 from kohei-noda-qcrg/input-essential-variable…
Browse files Browse the repository at this point in the history
…-class, close #115

Input essential variable class
  • Loading branch information
kohei-noda-qcrg authored Nov 24, 2023
2 parents b9be4a7 + 2384017 commit 6f2049d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 34 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ if(MPI)
add_compile_options(-DHAVE_MPI) # Add MPI preprocessor flag
endif()

# set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "")
if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DINTEL -g -traceback -cpp -i8 -I$ENV{MKLROOT}/include -pad -mp1 -integer-size 64 -unroll -warn nounused -nogen-interface") # "-warn nounused" means "-warn all -warn nounused"
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -check -debug extended -debug-parameters -warn")
Expand All @@ -46,7 +45,6 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
# set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DGNU -fallow-argument-mismatch -g -fbacktrace -cpp -fdefault-integer-8 -m64 -I$ENV{MKLROOT}/include -Wall -Wno-unused-variable")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -fcheck=all")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
link_libraries(-fdefault-integer-8 -m64)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(dcaspt2_module_global STATIC

add_library(dcaspt2_module STATIC
module_2integrals.f90
module_essential_input.f90
module_file_manager.f90
module_index_utils.f90
module_intra.f90
Expand Down
1 change: 0 additions & 1 deletion src/module_error.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ subroutine stop_with_errorcode(errorcode)
#ifdef HAVE_MPI
call MPI_Barrier(MPI_COMM_WORLD, ierr)
#endif
print *, "Exit with error", errorcode
#ifdef INTEL
call TRACEBACKQQ("Exit with error", errorcode)
#endif
Expand Down
70 changes: 70 additions & 0 deletions src/module_essential_input.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module module_essential_input
use module_error, only: stop_with_errorcode
use module_global_variables, only: rank
implicit none
private
public :: add_essential_input, update_esesential_input, &
check_all_essential_inputs_specified, &
essential_inputs
type essential_input
character(:), allocatable :: name
logical :: is_specified
end type essential_input
type(essential_input), allocatable :: essential_inputs(:)
contains

subroutine add_essential_input(name)
implicit none
character(*), intent(in) :: name
integer :: idx
type(essential_input), allocatable :: tmp(:)

if (.not. allocated(essential_inputs)) then
! Allocate the first element
idx = 1
allocate (essential_inputs(idx))
else
! Reallocate the array with new_size = current_size + 1
idx = size(essential_inputs, 1) + 1
allocate (tmp(idx))
tmp(1:idx - 1) = essential_inputs
! essential_inputs is reallocated with size = idx
call move_alloc(tmp, essential_inputs)
end if
! Add the name and default is_specified value
essential_inputs(idx)%name = trim(adjustl(name))
essential_inputs(idx)%is_specified = .false.
end subroutine add_essential_input

subroutine update_esesential_input(name, is_specified)
implicit none
character(*), intent(in) :: name
logical, intent(in) :: is_specified
integer :: idx
character(:), allocatable :: trimmed_name

! Search the name in essential_inputs
trimmed_name = trim(adjustl(name))
do idx = 1, size(essential_inputs, 1)
if (essential_inputs(idx)%name == trimmed_name) then
essential_inputs(idx)%is_specified = is_specified
return
end if
end do
! If the name is not found, it is an error.
if (rank == 0) print *, "ERROR: Unknown input: ", trimmed_name
call stop_with_errorcode(1)
end subroutine update_esesential_input

subroutine check_all_essential_inputs_specified()
implicit none
integer :: idx
do idx = 1, size(essential_inputs, 1)
if (.not. essential_inputs(idx)%is_specified) then
if (rank == 0) print *, "ERROR: You must specify a variable '", trim(essential_inputs(idx)%name), "' before end."
call stop_with_errorcode(1)
end if
end do
end subroutine check_all_essential_inputs_specified

end module module_essential_input
64 changes: 33 additions & 31 deletions src/read_input_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ module read_input_module
!
! This is a utility module that interpret and parse input strings.
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
use module_essential_input, only: add_essential_input, update_esesential_input, &
check_all_essential_inputs_specified, essential_inputs
use module_global_variables, only: rank, len_convert_int_to_chr
use module_error, only: stop_with_errorcode
implicit none
private
public read_input, check_substring, ras_read, lowercase, uppercase
logical is_end
integer, parameter :: input_intmax = 10**9, max_str_length = 500

contains

subroutine init_essential_variables
call add_essential_input("ninact")
call add_essential_input("nact")
call add_essential_input("nsec")
call add_essential_input("nelec")
call add_essential_input("nroot")
call add_essential_input("selectroot")
call add_essential_input("totsym")
call add_essential_input("diracver")
end subroutine init_essential_variables

subroutine read_input(unit_num)
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
! This subroutine is the entry point to read active.inp
Expand All @@ -22,14 +37,13 @@ subroutine read_input(unit_num)
use module_index_utils, only: set_global_index
implicit none
integer, intent(in) :: unit_num
integer :: idx, iostat
integer :: iostat
character(len=max_str_length) :: string
character(len=10), parameter :: essential_variable_names(8) = (/"ninact ", "nact ", "nsec ", "nroot ", &
"nelec ", "selectroot", "totsym ", "diracver "/)
logical :: is_comment, is_config_sufficient, is_variable_filled(8) = &
(/.false., .false., .false., .false., .false., .false., .false., .false./)
logical :: is_comment
is_end = .false.

call init_essential_variables

do while (.not. is_end) ! Read the input file until the "end" is found
read (unit_num, "(a)", iostat=iostat) string
if (iostat < 0) then
Expand All @@ -41,28 +55,17 @@ subroutine read_input(unit_num)
end if
call is_comment_line(string, is_comment)
if (is_comment) cycle ! Read the next line
call check_input_type(unit_num, string, is_variable_filled)
call read_keyword_and_value(unit_num, string)
end do
! Check if the input is sufficient
is_config_sufficient = .true.
do idx = 1, size(is_variable_filled)
if (.not. is_variable_filled(idx)) then
if (rank == 0) print *, "ERROR: You must specify a variable ", trim(essential_variable_names(idx)), " before end."
is_config_sufficient = .false.
end if
end do
if (.not. is_config_sufficient) then! Error in input. Stop the Program
if (rank == 0) print *, "ERROR: Error in input, valiables you specified is insufficient!!. Stop the program."
call stop_with_errorcode(1)
end if
! Set the global index (global_[ninact, nact, nsec]_[start, end])

call check_all_essential_inputs_specified
call set_global_index
! Check the RAS configuration
if (ras1_size /= 0 .or. ras2_size /= 0 .or. ras3_size /= 0) call check_ras_is_valid

end subroutine read_input

subroutine check_input_type(unit_num, string, is_filled)
subroutine read_keyword_and_value(unit_num, string)
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
! This subroutine recognize the type of input that follows from the next line
! and calls the subroutine that we must call
Expand All @@ -73,37 +76,36 @@ subroutine check_input_type(unit_num, string, is_filled)
character(*), intent(inout) :: string
character(len=max_str_length) :: input
logical :: is_comment
logical, intent(inout) :: is_filled(:)
call lowercase(string)
select case (trim(string))
select case (trim(adjustl(string)))

case ("ninact")
call read_an_integer(unit_num, 0, input_intmax, ninact)
is_filled(1) = .true.
call update_esesential_input("ninact", .true.)

case ("nact")
call read_an_integer(unit_num, 0, input_intmax, nact)
is_filled(2) = .true.
call update_esesential_input("nact", .true.)

case ("nsec")
call read_an_integer(unit_num, 0, input_intmax, nsec)
is_filled(3) = .true.
call update_esesential_input("nsec", .true.)

case ("nelec")
call read_an_integer(unit_num, 0, input_intmax, nelec)
is_filled(4) = .true.
call update_esesential_input("nelec", .true.)

case ("nroot")
call read_an_integer(unit_num, 0, input_intmax, nroot)
is_filled(5) = .true.
call update_esesential_input("nroot", .true.)

case ("selectroot")
call read_an_integer(unit_num, 0, input_intmax, selectroot)
is_filled(6) = .true.
call update_esesential_input("selectroot", .true.)

case ("totsym")
call read_an_integer(unit_num, 0, input_intmax, totsym)
is_filled(7) = .true.
call update_esesential_input("totsym", .true.)

case ("ncore")
call read_an_integer(unit_num, 0, input_intmax, ncore)
Expand All @@ -120,7 +122,7 @@ subroutine check_input_type(unit_num, string, is_filled)

case ("diracver")
call read_an_integer(unit_num, 0, input_intmax, dirac_version)
is_filled(8) = .true.
call update_esesential_input("diracver", .true.)

case ("nhomo")
call read_an_integer(unit_num, 0, input_intmax, nhomo)
Expand Down Expand Up @@ -198,7 +200,7 @@ subroutine err_ivo_input
call stop_with_errorcode(1)
end subroutine err_ivo_input

end subroutine check_input_type
end subroutine read_keyword_and_value

subroutine ras_read(unit_num, ras_list, ras_num)
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
Expand Down

0 comments on commit 6f2049d

Please sign in to comment.