Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

how to convert character string into integer

maria
Beginner
1,075 Views
Hi,

I want to find the run time fora section of program in microseconds. Iput call date_and_time(data,time1)
and data_and_time(data,time2) at the beginning and the end of this section.
I know time1(8:10) and time2 (8:10) is the microseconds of the clock. Since this section is inside of a do loop, I want to calculate the total timewithin this session from the complete do loop.
How can I get time calculation with something like
t = t+ time2(8:10) - time1(8:10) if I set t = 0. outside of the do loop? In other words, how do I convert the character into integer here?

Thanks.
0 Kudos
6 Replies
mecej4
Honored Contributor III
1,075 Views
You could do the following (read up on "internal files" in a Fortran book):

[fortran]    real :: t1,t2
    ...
    call date_and_time (data,time1)
    ...
    ...
    call date_and_time (data,time2)

    read(time1,123)t1
    read(time2,123)t2
123 format(F10.3)

    t_run = t2 - t1[/fortran]
Note, however, that it may be more appropriate for you to call CPU_TIME rather than using the wall-clock time as you have done, especially if you are using a multi-user/multi-process OS.
0 Kudos
TimP
Honored Contributor III
1,075 Views
For wall-clock time, system_clock() may be more appropriate, although the resolution for Intel Windows compiler is limited to 60 Hz.
0 Kudos
Steven_L_Intel1
Employee
1,075 Views
Quoting tim18
the resolution for Intel Windows compiler is limited to 60 Hz.

Not true.

0 Kudos
TimP
Honored Contributor III
1,075 Views
Then it would be useful to know how to change it, and why it doesn't just work as it does for linux.
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,075 Views

An easy way to do this is to build with OpenMP enabled (you do not need to use OpenMP within the application). add use omp_lib then

real(8) :: T1

...
T1 = OMP_GET_WTIME()

Returns a double-precision value equal to the elapsed wallclock time (in seconds) relative to an arbitrary reference time.

Jim Dempsey

0 Kudos
TimP
Honored Contributor III
1,075 Views
In fact, Jim's suggestion is the way I do it for Windows, although I could get somewhat better results on most machines with QueryPerformance.
0 Kudos
Reply