Skip to content

Commit

Permalink
fixed issue compiling with mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
Simkern committed Jul 18, 2024
1 parent 7946dd7 commit 8e0d638
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 23 additions & 6 deletions src/Constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ module LightKrylov_Constants
complex(dp), parameter, public :: zero_cdp = cmplx(0.0_dp, 0.0_dp, kind=dp)

! Getter/setter routines
public :: get_rank
public :: set_comm_size
public :: set_rank
public :: set_io_rank
public :: get_rank
public :: get_comm_size
public :: io_rank

contains

subroutine set_rank(rank)
integer :: rank
nid = rank
end subroutine set_rank

subroutine set_comm_size(c_size)
integer :: c_size
comm_size = c_size
end subroutine set_comm_size

subroutine set_io_rank(rk)
integer, intent(in) :: rk
if (rk > comm_size .or. rk < 0) then
Expand All @@ -46,15 +59,19 @@ subroutine set_io_rank(rk)
nio = rk
if (io_rank()) print *, 'I/O rank --> rank ', nio
end if
end
end

integer function get_rank() result(rank)
rank = nid
end function get_rank

integer function get_comm_size() result(c_size)
c_size = comm_size
end function get_comm_size

logical function io_rank() result(is_io)
is_io = .false.
if (nid == nio) is_io = .true.
end function io_rank

integer function get_rank() result(rank)
rank = nid
end function get_rank

end module LightKrylov_Constants
8 changes: 5 additions & 3 deletions src/Logger.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end subroutine logger_setup

subroutine comm_setup()
! internal
integer :: ierr
integer :: ierr, nid, comm_size
logical :: mpi_is_initialized
character(len=128) :: msg
#ifdef MPI
Expand All @@ -104,12 +104,14 @@ subroutine comm_setup()
else
call logger%log_debug('MPI already initialized.', module='LightKrylov', procedure='comm_setup')
end if
call MPI_Comm_rank(MPI_COMM_WORLD, nid, ierr)
call MPI_Comm_size(MPI_COMM_WORLD, comm_size, ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, nid, ierr); call set_rank(nid)
call MPI_Comm_size(MPI_COMM_WORLD, comm_size, ierr); call set_comm_size(comm_size)
write(msg, '(A,I4,A,I4)') 'rank', nid, ', comm_size = ', comm_size
call logger%log_debug(trim(msg), module='LightKrylov', procedure='comm_setup')
#else
write(msg, *) 'Setup serial run'
call set_rank(0)
call set_comm_size(1)
call logger%log_debug(trim(msg), module='LightKrylov', procedure='comm_setup')
#endif
return
Expand Down

0 comments on commit 8e0d638

Please sign in to comment.