如何在Fortran程序中设置内部挂钟? [英] How to set internal wall clock in a Fortran program?

查看:305
本文介绍了如何在Fortran程序中设置内部挂钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Fortran来做一些科学计算。我使用HPC。正如我们所知,当我们在HPC作业调度程序中提交作业时,我们还指定了我们作业的挂钟时间限制。但是,如果时间到了,如果作业仍然在写输出数据,它将被终止,并且会在数据中产生一些'NUL'值,给后处理造成麻烦:



那么,我们可以设置一个内部机制,让我们的工作可以平静地停止HPC补贴时间结束之前的时间?

相关问题:如何跳过读取NUL MATLAB的textscan函数中的值?

解决方案

在意识到你问的问题后,我发现我实现了类似的功能我的程序最近(提交 https://bitbucket.org/LadaF/elmm/commits/f10a1b3421a3dd14fdcbe165aa70bf5c5001413f )。但我仍然必须手动设置时间限制。



最重要的部分:
$ b $ p $ time_stepping%clock_time_limit 是以秒为单位的时间限制。计算与之对应的系统时钟滴答的数量:

 调用system_clock(count_rate = timer_rate)
调用system_clock(count_max = timer_max_count)

timer_count_time_limit = int(min(time_stepping%clock_time_limit&
* real(timer_rate,knd),&b
real(timer_max_count,knd)* 0.999_dbl) &
,dbl)

启动计时器

 调用system_clock(count = time_steps_timer_count_start)

检查计时器并退出主循环,如果时间到了, error_exit 设置为 .true。

  if(mod(time_step,time_stepping%check_period)== 0)then 
if(master)then
error_exit = time_steps_timer_count_2 - time_steps_timer_count_start> timer_count_time_limit
if(error_exit)write(*,*)超过最大时钟时间。
end if

MPI_Bcast错误退出到其他进程

if(error_exit)exit
end if

现在,您可能希望自动从您的调度程序中获取时间限制。这在不同的作业调度软件之间会有所不同。会有一个像 $ PBS_WALLTIME 这样的环境变量。请参阅在PBS作业脚本中获取walltime ,但请检查您的日程安排手册。

您可以使用 GET_ENVIRONMENT_VARIABLE()


I use Fortran to do some scientific computation. I use HPC. As we know, when we submit jobs in a HPC job scheduler, we also specify the wall clock time limit for our jobs. However, when the time is up, if the job is still writing output data, it will be terminated and it will cause some 'NUL' values in the data, causing trouble for the post-processing:

So, could we set an internal mechanism that our job can stop itself peacefully some time before the end of HPC allowance time?

Related Question: How to skip reading "NUL" value in MATLAB's textscan function?

解决方案

After realizing what you are asking I found out that I implemented similar functionality in my program very recently (commit https://bitbucket.org/LadaF/elmm/commits/f10a1b3421a3dd14fdcbe165aa70bf5c5001413f). But I still have to set the time limit manually.

The most important part:

time_stepping%clock_time_limit is the time limit in seconds. Count the number of system clock ticks corresponding to that:

    call system_clock(count_rate = timer_rate)
    call system_clock(count_max = timer_max_count)   

    timer_count_time_limit = int( min(time_stepping%clock_time_limit &
                                        * real(timer_rate, knd),  &
                                      real(timer_max_count, knd) * 0.999_dbl) &
                                , dbl)  

Start the timer

call system_clock(count = time_steps_timer_count_start)  

Check the timer and exit the main loop with error_exit set to .true. if the time is up

  if (mod(time_step,time_stepping%check_period)==0) then
    if (master) then
      error_exit = time_steps_timer_count_2 - time_steps_timer_count_start > timer_count_time_limit
      if (error_exit) write(*,*) "Maximum clock time exceeded."
    end if

    MPI_Bcast the error exit to other processes

    if (error_exit) exit
  end if

Now, you may want to get the time limit from your scheduler automatically. That will vary between different job scheduling softwares. There will be an environment variable like $PBS_WALLTIME. See Get walltime in a PBS job script but check your scheduler's manual.

You can read this variable using GET_ENVIRONMENT_VARIABLE()

这篇关于如何在Fortran程序中设置内部挂钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆