write_rng_state_file Subroutine

public subroutine write_rng_state_file(out_dir, mpi_rank, mpi_size, mpi)

現在の Fortran 乱数状態をファイルへ保存する。

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: out_dir

出力ディレクトリ。

integer(kind=i32), intent(in), optional :: mpi_rank
integer(kind=i32), intent(in), optional :: mpi_size
type(mpi_context), intent(in), optional :: mpi

Calls

proc~~write_rng_state_file~~CallsGraph proc~write_rng_state_file write_rng_state_file proc~mpi_get_rank_size mpi_get_rank_size proc~write_rng_state_file->proc~mpi_get_rank_size proc~restart_rng_state_path restart_rng_state_path proc~write_rng_state_file->proc~restart_rng_state_path proc~restart_rng_state_path->proc~mpi_get_rank_size

Called by

proc~~write_rng_state_file~~CalledByGraph proc~write_rng_state_file write_rng_state_file program~main main program~main->proc~write_rng_state_file

Source Code

  subroutine write_rng_state_file(out_dir, mpi_rank, mpi_size, mpi)
    character(len=*), intent(in) :: out_dir
    integer(i32), intent(in), optional :: mpi_rank, mpi_size
    type(mpi_context), intent(in), optional :: mpi

    character(len=1024) :: path
    integer :: n, u, ios, i
    integer, allocatable :: seed(:)
    integer(i32) :: local_rank, world_size

    call resolve_parallel_rank_size(local_rank, world_size, mpi_rank, mpi_size, mpi, 'write_rng_state_file')
    call random_seed(size=n)
    allocate (seed(n))
    call random_seed(get=seed)

    path = restart_rng_state_path(trim(out_dir), mpi_rank=local_rank, mpi_size=world_size)
    open (newunit=u, file=trim(path), status='replace', action='write', iostat=ios)
    if (ios /= 0) error stop 'Failed to open rng_state.txt.'

    write (u, '(i0)') n
    do i = 1, n
      write (u, '(i0)') seed(i)
    end do
    close (u)
  end subroutine write_rng_state_file