98 public::
operator(+),
operator(-)
120 character(STRING):: name
121 real(
dp):: start_time
123 real(
dp):: elapsed_time
125 logical:: initialized = .false.
128 module procedure dcclockcreate0
131 module procedure dcclockclose0
134 module procedure dcclockstart0
137 module procedure dcclockstop0
140 module procedure dcclockputline0
143 module procedure dcclockgetr
144 module procedure dcclockgetd
147 module procedure dcclockevalsecd
150 module procedure dcclocktochar0
153 module procedure dcclockresult0
155 interface operator(+)
156 module procedure dcclockadd
158 interface operator(-)
159 module procedure dcclocksubtract
162 module procedure dcclocksetname0
165 module procedure dcclockpredict0
171 module procedure dcclockcreate0
174 module procedure dcclockclose0
177 module procedure dcclockstart0
180 module procedure dcclockstop0
183 module procedure dcclockputline0
186 module procedure dcclockgetr
187 module procedure dcclockgetd
190 module procedure dcclockevalsecd
193 module procedure dcclocktochar0
196 module procedure dcclockresult0
199 module procedure dcclocksetname0
202 module procedure dcclockpredict0
204 character(*),
parameter:: version = &
206 &
'$Id: dc_clock.F90,v 1.1 2009-03-20 09:09:53 morikawa Exp $'
227 subroutine dcclockcreate0(clk, name)
229 use dc_date,
only: dcdatetimecreate
231 type(
clock),
intent(out):: clk
232 character(*),
intent(in):: name
233 character(*),
parameter:: subname =
'DCClockCreate'
235 call beginsub(subname,
'name=%c', c1=trim(name), version=version)
236 if (clk % initialized)
then
237 call messagenotify(
'W', subname,
'This argument (type CLOCK) is already initialized.')
242 clk % elapsed_time = 0.0
243 clk % start_time = - 1.0
244 clk % initialized = .true.
245 call dcdatetimecreate(clk % start_date)
249 end subroutine dcclockcreate0
265 subroutine dcclockclose0(clk)
267 type(
clock),
intent(inout):: clk
268 character(*),
parameter:: subname =
'DCClockClose'
271 if (clk % initialized)
then
272 clk % initialized = .false.
276 end subroutine dcclockclose0
301 subroutine dcclockstart0(clk, err)
308 type(
clock),
intent(inout):: clk
309 logical,
intent(out),
optional:: err
310 character(STRING):: cause_c
312 character(*),
parameter:: subname =
'DCClockStart'
317 if (.not. clk % initialized)
then
318 call messagenotify(
'W', subname,
'Call Create before Start in dc_clock.')
319 call dbgmessage(
'Ignored because input argument was not initialized.')
323 call cpu_time(clk % start_time)
326 & c1=trim(clk % name), d=(/clk % start_time/) )
330 end subroutine dcclockstart0
355 subroutine dcclockstop0(clk, err)
364 type(
clock),
intent(inout):: clk
365 logical,
intent(out),
optional:: err
366 character(STRING):: cause_c
369 character(*),
parameter:: subname =
'DCClockStop'
374 if (.not. clk % initialized)
then
375 call messagenotify(
'W', subname,
'Call Create before Stop in dc_clock.')
376 call dbgmessage(
'Ignored because input argument was not initialized.')
379 elseif (clk % start_time < 0.0_dp)
then
380 call messagenotify(
'W', subname,
'Call Start before Stop in dc_clock.')
381 call dbgmessage(
'Ignored because input argument was not started.')
384 call cpu_time(stop_time)
386 clk % elapsed_time = clk % elapsed_time + stop_time - clk % start_time
387 clk % start_time = - 1.0
388 call dbgmessage(
'name=%c, cpu_time=%f, elapsed_time=%f', &
389 & c1=trim(clk % name), d=(/stop_time, clk % elapsed_time/))
393 end subroutine dcclockstop0
420 subroutine dcclockgetr(clk, sec, err)
426 type(
clock),
intent(in):: clk
427 real,
intent(out):: sec
428 logical,
intent(out),
optional:: err
429 character(STRING):: cause_c
431 character(*),
parameter:: subname =
'DCClockGetR'
436 if (.not. clk % initialized)
then
437 call messagenotify(
'W', subname,
'Call Create before Get in dc_clock.')
438 call dbgmessage(
'Ignored because input argument was not initialized.')
442 sec = real(clk % elapsed_time, kind=kind(sec))
444 & c1=trim(clk % name), r=(/sec/))
448 end subroutine dcclockgetr
475 subroutine dcclockgetd(clk, sec, err)
482 type(
clock),
intent(in):: clk
483 real(DP),
intent(out):: sec
484 logical,
intent(out),
optional:: err
485 character(STRING):: cause_c
487 character(*),
parameter:: subname =
'DCClockGetD'
492 if (.not. clk % initialized)
then
493 call messagenotify(
'W', subname,
'Call Create before Get in dc_clock.')
494 call dbgmessage(
'Ignored because input argument was not initialized.')
498 sec = clk % elapsed_time
500 & c1=trim(clk % name), d=(/sec/))
504 end subroutine dcclockgetd
525 function dcclockevalsecd(clk)
result(result)
528 type(
clock),
intent(in):: clk
532 call dcclockgetd(clk,
result, err)
534 end function dcclockevalsecd
555 function dcclocktochar0(clk)
result(result)
559 type(
clock),
intent(in):: clk
560 character(STRING)::
result
561 character(20):: clk_name
565 name_len = min(len(clk_name), len_trim(clk % name))
566 if (name_len > 0)
then
567 clk_name(1:name_len) = clk % name(1:name_len)
569 if (clk % initialized)
then
571 & c2=trim(result_value_form(clk % elapsed_time)), &
572 & c3=trim(fit_unit_value(clk % elapsed_time)))
576 end function dcclocktochar0
608 subroutine dcclockputline0(clk, unit, indent, err)
616 type(
clock),
intent(in):: clk
617 integer,
intent(in),
optional:: unit
618 character(*),
intent(in),
optional:: indent
619 logical,
intent(out),
optional:: err
621 character(STRING):: cause_c
624 character(STRING):: indent_str
625 character(*),
parameter:: subname =
'DCClockPutLine'
630 if (.not. clk % initialized)
then
631 call messagenotify(
'W', subname,
'Call Create before PutLine in dc_clock.')
632 call dbgmessage(
'Ignored because input argument was not initialized.')
636 if (
present(unit))
then
643 if (
present(indent))
then
644 if (len(indent) /= 0)
then
645 indent_len = len(indent)
646 indent_str(1:indent_len) = indent
650 & indent_str(1:indent_len) // &
651 &
'#<CLOCK:: @name=%c @clocking=%y @elapsed_time=%f sec. %c @start_date=%c>', &
652 & c1=trim(clk % name), l=(/clk % start_time > 0.0_dp/), &
653 & d=(/clk % elapsed_time/), &
654 & c2=trim(fit_unit_value(clk % elapsed_time)), &
655 & c3=trim(
tochar(clk % start_date)))
656 call dbgmessage(
'name=%c, output to device number %d', &
657 & c1=trim(clk % name), i=(/out_unit/))
661 end subroutine dcclockputline0
716 subroutine dcclockresult0(clks, unit, total_auto, clk_total, total_name, err)
723 type(
clock),
intent(in):: clks(:)
724 integer,
intent(in),
optional:: unit
725 logical,
intent(in),
optional:: total_auto
726 type(
clock),
intent(in),
optional:: clk_total
727 logical,
intent(out),
optional:: err
728 character(*),
intent(in),
optional:: total_name
729 integer:: out_unit, i, clks_size, ra
730 character(20):: clk_name
732 character(STRING):: cause_c
733 character(STRING):: total_name_work
734 type(
clock):: clk_auto_total
735 logical:: total_print_complete
736 real(DP):: elapsed_time_val_cor
738 character(*),
parameter:: total_time_mes =
' TOTAL TIME = '
739 logical:: initflag_mpi
741 integer:: myrank_mpi, nprocs_mpi
742 character(*),
parameter:: subname =
'DCClockResult'
747 clks_size =
size(clks)
749 if (.not. clks(i) % initialized)
then
750 call messagenotify(
'W', subname,
'Call Create before Result in dc_clock.')
751 call dbgmessage(
'Ignored because input argument was not initialized.')
756 if (
present(unit))
then
761 if (
present(total_name))
then
762 total_name_work =
' (' // trim(total_name) //
')'
768 call mpi_initialized(initflag_mpi, err_mpi)
769 if ( initflag_mpi )
then
770 call mpi_comm_rank(mpi_comm_world, myrank_mpi, err_mpi)
771 call mpi_comm_size(mpi_comm_world, nprocs_mpi, err_mpi)
773 do ra = 0, nprocs_mpi - 1
774 if ( initflag_mpi )
call mpi_barrier(mpi_comm_world, err_mpi)
775 if ( myrank_mpi > -1 .and. ra /= myrank_mpi ) cycle
777 if ( myrank_mpi < 0 )
then
779 &
' ############## CPU TIME SUMMARY%c################', &
780 & c1=trim(total_name_work) //
' ')
783 &
' ####### CPU TIME SUMMARY%c#### [rank=%06d] ####', &
784 & c1=trim(total_name_work) //
' ', &
785 & i = (/myrank_mpi/) )
789 name_len = min(len(clk_name), len_trim(clks(i) % name))
790 if (name_len > 0)
then
791 clk_name(1:name_len) = clks(i) % name(1:name_len)
793 elapsed_time_val_cor = clks(i) % elapsed_time
794 if (elapsed_time_val_cor < 0.0_dp) elapsed_time_val_cor = 0.0_dp
796 &
' %c%c %c', c1=clk_name, &
797 & c2=trim(result_value_form(elapsed_time_val_cor)), &
798 & c3=trim(fit_unit_value(clks(i) % elapsed_time)))
800 total_print_complete = .false.
801 if (
present(clk_total))
then
802 if (clk_total % initialized)
then
804 &
' ------------------------------------------------')
805 elapsed_time_val_cor = clk_total % elapsed_time
806 if (elapsed_time_val_cor < 0.0_dp) elapsed_time_val_cor = 0.0_dp
808 &
' %c%c %c', c1=total_time_mes, &
809 & c2=trim(result_value_form(elapsed_time_val_cor)), &
810 & c3=trim(fit_unit_value(clk_total % elapsed_time)))
811 total_print_complete = .true.
814 if (
present(total_auto) .and. .not. total_print_complete)
then
816 clk_auto_total = clks(1)
817 if (clks_size > 1)
then
819 clk_auto_total = clk_auto_total + clks(i)
823 &
' ------------------------------------------------')
824 elapsed_time_val_cor = clk_auto_total % elapsed_time
825 if (elapsed_time_val_cor < 0.0_dp) elapsed_time_val_cor = 0.0_dp
827 &
' %c%c %c', c1=total_time_mes, &
828 & c2=trim(result_value_form(elapsed_time_val_cor)), &
829 & c3=trim(fit_unit_value(clk_auto_total % elapsed_time)))
832 call dbgmessage(
'total results, output to device number %d', &
838 end subroutine dcclockresult0
842 function result_value_form(value)
result(result)
845 character(TOKEN):: result
846 real(DP),
intent(in):: value
848 write(
result,
"(e15.6)")
value
849 end function result_value_form
858 function fit_unit_value(sec, diff)
result(result)
861 use dc_date,
only: dcdifftimecreate, evalday, evalhour, evalmin,
evalsec
863 character(TOKEN):: result
864 real(DP),
intent(in):: sec
867 character(TOKEN):: unit
869 character(TOKEN):: cval
871 if (
present(diff) )
then
874 call dcdifftimecreate( diffw, sec = sec )
876 if (evalday(diffw) > 1.0_dp)
then
878 value = evalday(diffw)
879 elseif (evalhour(diffw) > 1.0_dp)
then
881 value = evalhour(diffw)
882 elseif (evalmin(diffw) > 1.0_dp)
then
884 value = evalmin(diffw)
889 cval = printf_g5_2(
value)
890 result =
'(' // trim(adjustl(cval)) // trim(unit) //
')'
891 end function fit_unit_value
897 function printf_g5_2(value)
result(result)
901 character(TOKEN):: result
902 real(DP),
intent(in):: value
903 character(TOKEN):: int_part, dem_part
906 write(int_part,
"(i20)") int(
value)
907 dem_int = nint((
value - int(
value)) * 100)
908 if (dem_int < 0) dem_int = - dem_int
909 if (dem_int == 100)
then
911 write(int_part,
"(i20)") int(
value) + 1
913 dem_part =
cprintft(
'%02d', i=(/dem_int/))
914 result = trim(adjustl(int_part)) //
'.' // trim(dem_part)
915 end function printf_g5_2
940 function dcclockadd(clk1, clk2)
result(clk_total)
942 use dc_date,
only:
operator(+),
operator(<)
944 type(
clock),
intent(in):: clk1
945 type(
clock),
intent(in):: clk2
946 type(
clock):: clk_total
948 if (.not. clk1 % initialized .or. .not. clk2 % initialized)
then
949 clk_total % initialized = .false.
952 clk_total % name =
cprintf(
'%c+%c', &
953 & c1=trim(clk1 % name), c2=trim(clk2 % name))
954 clk_total % start_time = - 1.0
955 clk_total % initialized = .true.
956 clk_total % elapsed_time = 0.0
957 if (clk1 % start_date < clk2 % start_date)
then
958 clk_total % start_date = clk1 % start_date
960 clk_total % start_date = clk2 % start_date
962 clk_total % elapsed_time = &
963 & clk1 % elapsed_time + clk2 % elapsed_time
964 end function dcclockadd
989 function dcclocksubtract(clk1, clk2)
result(clk_total)
991 use dc_date,
only:
operator(-),
operator(<)
993 type(
clock),
intent(in):: clk1
994 type(
clock),
intent(in):: clk2
995 type(
clock):: clk_total
997 if (.not. clk1 % initialized .or. .not. clk2 % initialized)
then
998 clk_total % initialized = .false.
1001 clk_total % name =
cprintf(
'%c-%c', &
1002 & c1=trim(clk1 % name), c2=trim(clk2 % name))
1003 clk_total % start_time = - 1.0
1004 clk_total % initialized = .true.
1005 clk_total % elapsed_time = 0.0
1006 if (clk1 % start_date < clk2 % start_date)
then
1007 clk_total % start_date = clk1 % start_date
1009 clk_total % start_date = clk2 % start_date
1011 clk_total % elapsed_time = &
1012 & clk1 % elapsed_time - clk2 % elapsed_time
1013 end function dcclocksubtract
1042 subroutine dcclocksetname0(clk, name, err)
1047 type(
clock),
intent(inout):: clk
1048 character(*),
intent(in):: name
1049 logical,
intent(out),
optional:: err
1050 character(STRING):: cause_c
1052 character(*),
parameter:: subname =
'DCClockSetName'
1057 if (.not. clk % initialized)
then
1058 call messagenotify(
'W', subname,
'Call Create before Set_Name in dc_clock.')
1059 call dbgmessage(
'Ignored because input argument was not initialized.')
1064 call dbgmessage(
'set new name "%c"', c1=trim(clk % name))
1068 end subroutine dcclocksetname0
1137 subroutine dcclockpredict0(clk, progress, unit, err)
1146 type(
clock),
intent(in):: clk
1147 real,
intent(in):: progress
1148 integer,
intent(in),
optional:: unit
1149 logical,
intent(out),
optional:: err
1150 character(STRING):: cause_c
1151 integer:: stat, out_unit
1154 character(7):: prog_percent
1155 character(25):: prog_bar
1156 integer:: prog_bar_ptr
1158 logical:: initflag_mpi
1159 integer:: err_mpi, myrank_mpi
1160 character(*),
parameter:: subname =
'DCClockPredict'
1165 if (.not. clk % initialized)
then
1166 call messagenotify(
'W', subname,
'Call Create before Predict in dc_clock.')
1167 call dbgmessage(
'Ignored because input argument was not initialized.')
1171 if (progress <= 0.0)
then
1172 call messagenotify(
'W', subname,
'Specify 0.0 -- 1.0 value to "progress"')
1174 elseif (progress > 1.0)
then
1175 call messagenotify(
'W', subname,
'Over 1.0 value to "progress" was modified to 1.0')
1178 prog_valid = progress
1180 if (
present(unit))
then
1185 call dcdifftimecreate( remain_diff, &
1186 & sec = real(nint(
evalsec(clk) / prog_valid * (1.0 - prog_valid)),
dp) )
1187 call dcdatetimecreate(cur_date)
1188 comp_date = cur_date + remain_diff
1190 prog_percent = adjustr(trim(printf_g5_2(real(prog_valid * 100,
dp))) //
'%')
1192 prog_bar_ptr = int(prog_valid * 25)
1193 if (prog_bar_ptr > 0) prog_bar(1:prog_bar_ptr) =
'*************************'
1194 call mpi_initialized(initflag_mpi, err_mpi)
1195 if ( initflag_mpi )
then
1196 call mpi_comm_rank(mpi_comm_world, myrank_mpi, err_mpi)
1197 if ( myrank_mpi /= 0 )
goto 999
1199 call printf(out_unit,
'')
1201 &
' ########## PREDICTION OF CALCULATION ###########')
1203 &
' Start Date %c', c1=trim(
tochar(clk % start_date)))
1205 &
' Current Date %c', c1=trim(
tochar(cur_date)))
1207 &
' Progress %c [%c]', c1=prog_percent, c2=prog_bar)
1209 &
' Remaining CPU TIME %c %c', &
1210 & c1=trim(result_value_form(
evalsec(remain_diff))), &
1211 & c2=trim(fit_unit_value(0.0_dp, remain_diff)))
1213 &
' Completion Date %c', c1=trim(
tochar(comp_date)))
1217 end subroutine dcclockpredict0
Derived types and parameters for date and time.
Date and time manipulation module.
subroutine, public storeerror(number, where, err, cause_c, cause_i)
integer, parameter, public dc_noerr
Error storage variables
integer, parameter, public dc_enotinit
-400 or less: DC utilities errors
Handling character types.
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Provides kind type parameter values.
integer, parameter, public stdout
Unit number for Standard OUTPUT
integer, parameter, public token
Character length for word, token
integer, parameter, public dp
Double Precision Real number
integer, parameter, public string
Character length for string