<commit_before>!
!  Copyright 2016 ARTED developers
!
!  Licensed under the Apache License, Version 2.0 (the "License");
!  you may not use this file except in compliance with the License.
!  You may obtain a copy of the License at
!
!      http://www.apache.org/licenses/LICENSE-2.0
!
!  Unless required by applicable law or agreed to in writing, software
!  distributed under the License is distributed on an "AS IS" BASIS,
!  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
!  See the License for the specific language governing permissions and
!  limitations under the License.
!
subroutine prep_backup_values(is_backup)
  use global_variables
  use timer,           only: timer_reentrance_read, timer_reentrance_write
  use opt_variables,   only: opt_vars_initialize_p1, opt_vars_initialize_p2
  use backup_routines, only: backup_value
  use misc_routines,   only: get_wtime
  use communication,   only: comm_sync_all, comm_bcast, comm_is_root, comm_set_level2_group, &
                             procid, proc_group
  implicit none
  logical, intent(in) :: is_backup

  integer, parameter :: iounit = 500
  character(256)     :: reent_filename, dump_filename
  real(8) :: beg_time, end_time

  call comm_sync_all; beg_time = get_wtime()

  if (is_backup) then
    ! backup
    if (comm_is_root()) then
      ! create entry input file.
      write(reent_filename,'(A,A,I6.6,A)') trim(SYSname),'_re_',iter_now,'.dat'
      write(dump_filename,'(A,A,A,I6.6)') 'dump_',trim(SYSname),'_',iter_now
      open(iounit, file=gen_filename(reent_filename))
      write(iounit,*) 'reentrance'
      write(iounit,*) Time_shutdown
      write(iounit,*) "'"//trim(directory)//"'"
      write(iounit,*) "'"//trim(dump_filename)//"'"
      close(iounit)
    end if
    call comm_bcast(dump_filename, proc_group(1))
    open(iounit, status='replace', form='unformatted', file=gen_filename(dump_filename, procid(1)))
  else
    ! restore
    if(comm_is_root()) then
      read(*,*) directory
      read(*,*) dump_filename
    end if
    call comm_bcast(directory, proc_group(1))
    call comm_bcast(dump_filename, proc_group(1))
    write (process_directory,'(A,A,I5.5,A)') trim(directory),'/work_p',procid(1),'/'
    open(iounit, status='old', form='unformatted', file=gen_filename(dump_filename, procid(1)))
  end if

!============= backup values ==============
#define BACKUP(TARGET_VAR) call backup_value(is_backup, iounit, TARGET_VAR)

  BACKUP(iter_now)
  BACKUP(entrance_iter)

! grid
  BACKUP(NLx)
  BACKUP(NLy)
  BACKUP(NLz)
  BACKUP(Nd)
  BACKUP(NL)
  BACKUP(NG)
  BACKUP(NKx)
  BACKUP(NKy)
  BACKUP(NKz)
  BACKUP(NK)
  BACKUP(Sym)
  BACKUP(nGzero)
  BACKUP(NKxyz)
  BACKUP(aL)
  BACKUP(ax)
  BACKUP(ay)
  BACKUP(az)
  BACKUP(aLx)
  BACKUP(aLy)
  BACKUP(aLz)<commit_msg>Enable unbuffered IO in checkpoint/restart.<commit_after>!
!  Copyright 2016 ARTED developers
!
!  Licensed under the Apache License, Version 2.0 (the "License");
!  you may not use this file except in compliance with the License.
!  You may obtain a copy of the License at
!
!      http://www.apache.org/licenses/LICENSE-2.0
!
!  Unless required by applicable law or agreed to in writing, software
!  distributed under the License is distributed on an "AS IS" BASIS,
!  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
!  See the License for the specific language governing permissions and
!  limitations under the License.
!
subroutine prep_backup_values(is_backup)
  use global_variables
  use timer,           only: timer_reentrance_read, timer_reentrance_write
  use opt_variables,   only: opt_vars_initialize_p1, opt_vars_initialize_p2
  use backup_routines, only: backup_value
  use misc_routines,   only: get_wtime
  use communication,   only: comm_sync_all, comm_bcast, comm_is_root, comm_set_level2_group, &
                             procid, proc_group
  implicit none
  logical, intent(in) :: is_backup

  integer, parameter :: iounit = 500
  character(256)     :: reent_filename, dump_filename
  real(8) :: beg_time, end_time

  call comm_sync_all; beg_time = get_wtime()

  if (is_backup) then
    ! backup
    if (comm_is_root()) then
      ! create entry input file.
      write(reent_filename,'(A,A,I6.6,A)') trim(SYSname),'_re_',iter_now,'.dat'
      write(dump_filename,'(A,A,A,I6.6)') 'dump_',trim(SYSname),'_',iter_now
      open(iounit, file=gen_filename(reent_filename))
      write(iounit,*) 'reentrance'
      write(iounit,*) Time_shutdown
      write(iounit,*) "'"//trim(directory)//"'"
      write(iounit,*) "'"//trim(dump_filename)//"'"
      close(iounit)
    end if
    call comm_bcast(dump_filename, proc_group(1))
    open(iounit, status='replace', form='unformatted', file=gen_filename(dump_filename, procid(1)), buffered='no')
  else
    ! restore
    if(comm_is_root()) then
      read(*,*) directory
      read(*,*) dump_filename
    end if
    call comm_bcast(directory, proc_group(1))
    call comm_bcast(dump_filename, proc_group(1))
    write (process_directory,'(A,A,I5.5,A)') trim(directory),'/work_p',procid(1),'/'
    open(iounit, status='old', form='unformatted', file=gen_filename(dump_filename, procid(1)), buffered='no')
  end if

!============= backup values ==============
#define BACKUP(TARGET_VAR) call backup_value(is_backup, iounit, TARGET_VAR)

  BACKUP(iter_now)
  BACKUP(entrance_iter)

! grid
  BACKUP(NLx)
  BACKUP(NLy)
  BACKUP(NLz)
  BACKUP(Nd)
  BACKUP(NL)
  BACKUP(NG)
  BACKUP(NKx)
  BACKUP(NKy)
  BACKUP(NKz)
  BACKUP(NK)
  BACKUP(Sym)
  BACKUP(nGzero)
  BACKUP(NKxyz)
  BACKUP(aL)
  BACKUP(ax)
  BACKUP(ay)
  BACKUP(az)
  BACKUP(aLx)
  BACKUP(aLy)
  BACKUP(aLz)
{'fraction_non_alphanumeric': 0.12681544456252214, 'fraction_numerical': 0.010626992561105207, 'mean_word_length': 4.223866790009251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7620041', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2003, 'n_words': 457}