|
[Sponsors] |
April 19, 2005, 12:53 |
Elapsed time
|
#1 |
Guest
Posts: n/a
|
It should be a simple question for experts, but as a beginner I need to ask. How can I get the total elapsed rum time of my computational code in FORTRAN with g77 compiler. I used "mclock", but it is just good for cpu time, not the real elapsed time in seconds. Also, RTC() command is not recognized by this compiler. Anyone can help me on this. Thank you.
|
|
April 19, 2005, 12:55 |
Re: Elapsed time
|
#2 |
Guest
Posts: n/a
|
I forgot to say LINUX is the OS of my computer, if important.
|
|
April 19, 2005, 13:35 |
Re: Elapsed time
|
#3 |
Guest
Posts: n/a
|
use dtime() at the beginning and ending of your code and subtract the results.
-H |
|
April 20, 2005, 08:13 |
Re: Elapsed time
|
#4 |
Guest
Posts: n/a
|
Thanks, but g77 does not DTIME() command either. Any clue?
|
|
April 20, 2005, 09:26 |
Re: Elapsed time
|
#5 |
Guest
Posts: n/a
|
Hi,
It is a rather dirty work around, but can't you include MPI? MPI has some subroutines for performance measurements. Tom |
|
April 20, 2005, 10:43 |
Re: Elapsed time
|
#6 |
Guest
Posts: n/a
|
If your program is called myprog type
time myprog This will print out the elapsed cpu time (user and system). |
|
April 20, 2005, 11:05 |
Re: Elapsed time
|
#7 |
Guest
Posts: n/a
|
Compile the code as g77 -ff90 ..........
Try etime() if dtime() does not work -H |
|
April 20, 2005, 11:10 |
Re: Elapsed time
|
#8 |
Guest
Posts: n/a
|
Tom, how can I get this subroutine?
|
|
April 20, 2005, 11:19 |
Re: Elapsed time
|
#9 |
Guest
Posts: n/a
|
Thanks Tom. It worked, but I thought that there would be a more sophosticated way to do this.
|
|
April 20, 2005, 12:07 |
Re: Elapsed time
|
#10 |
Guest
Posts: n/a
|
Another way of doing this is to use, assuming your version of g77 supports it, the f90 subroutine cpu_time; e.g. add the line
call cpu_time(start_time) at the start of the code and call cpu_time(end_time) print*,'cpu time is ',end_time-cpu_time at the end of your code then compile with the -ff90 option. The cpu_time from this should be the same as that printed under user time as I suggested in my earlier post. |
|
April 20, 2005, 13:08 |
Re: Elapsed time
|
#11 |
Guest
Posts: n/a
|
I added this and tried to compile my program as:
g77 -ff90 myprog myprog.f and also g77 -o -ff90 myprog myprog.f but the message is: Invalid decleration of or reference to symbol 'cpu_time' , which means the subroutine "cpu_time" cannot be found. Have you ever tried yourself this with g77 ? And linux OS? Pam |
|
April 20, 2005, 14:10 |
Re: Elapsed time
|
#12 |
Guest
Posts: n/a
|
Yes (I tried it before posting). The problem is likely to be that you've got an old version of g77/gcc installed on your computer. I've just tried it again and it actually works without the -ff90 flag on my home machine! Check the version of your compiler (type g77 --version) mine is 3.3.4
You can download the latest version of g77/gcc (you need to be root to install it) form http://www.gnu.org/software/gcc/gcc.html You could also try replacing, for example, "call cpu_time(x)" by by "call second(x)" |
|
April 20, 2005, 18:56 |
Re: Elapsed time
|
#13 |
Guest
Posts: n/a
|
The version of mine is 3.3.1 (linux). I will try the new version asap, but in the meantime, I tries this second(x). It worked but it is not the equivalent to "time myprog" ie. elapsed time, it just gives "cpu time" times 1e-4.
|
|
April 21, 2005, 04:43 |
Re: Elapsed time
|
#14 |
Guest
Posts: n/a
|
seconds and cpu_time are supposed to be the same function so I'm not too sure why it's not giving the right answer? Also, now I'm back at work I've tested the commands on our version of g77 (gcc 3.2.2 - so it appears to be older than yours!).
You could also try downloading g95 or gfortran which gives you access to other f90 programming features as well as cpu_time (for noncommercial use you can also download the intel f90 compiler). |
|
April 22, 2005, 22:06 |
Re: Elapsed time
|
#15 |
Guest
Posts: n/a
|
The easiest way would be to use a Fortran90 compiler. However, if you need to use g77 and nothing in fortran seems to work, there is a very simple way to make it work with a C function called from fortran. Here's a short example:
///////////////////////////////////////////// // paste into file ctim.c and compile by // gcc -c ctim.c ///////////////////////////////////////////// #include <sys/time.h> #include <sys/resource.h> double ctim_(void) { struct rusage rusage; double utime,stime; getrusage(0,&rusage); utime = (rusage.ru_utime.tv_sec +1e-6*rusage.ru_utime.tv_usec); stime = (rusage.ru_stime.tv_sec +1e-6*rusage.ru_stime.tv_usec); return(utime +stime); } ///////////////////////////////////////////// ccccccccccccccccccccccccccccccccccccccccccccc c paste into file test.f and compile by c g77 test.f ctim.o ccccccccccccccccccccccccccccccccccccccccccccc program test implicit none integer i,j double precision x,t,ctim external ctim t = ctim() x = 0d0 do i=1,10000 do j=1,10000 x=exp(x)-1d0 enddo enddo t = ctim() print *,t,' sec' end |
|
April 22, 2005, 22:09 |
Re: Elapsed time
|
#16 |
Guest
Posts: n/a
|
what a mess! got mangled. let me know if you want the files.
|
|
April 23, 2005, 10:44 |
Re: Elapsed time
|
#17 |
Guest
Posts: n/a
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
TimeVaryingMappedFixedValue | irishdave | OpenFOAM Running, Solving & CFD | 32 | June 16, 2021 06:55 |
Time step size and max iterations per time step | pUl| | FLUENT | 33 | October 23, 2020 22:50 |
Problems with simulating TurbFOAM | barath.ezhilan | OpenFOAM | 13 | July 16, 2009 05:55 |
Computational time | sunnysun | OpenFOAM Running, Solving & CFD | 5 | March 16, 2009 03:32 |
Modeling in micron scale using icoFoam | m9819348 | OpenFOAM Running, Solving & CFD | 7 | October 27, 2007 00:36 |