Elapsed time
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.
|
Re: Elapsed time
I forgot to say LINUX is the OS of my computer, if important.
|
Re: Elapsed time
use dtime() at the beginning and ending of your code and subtract the results.
-H |
Re: Elapsed time
Thanks, but g77 does not DTIME() command either. Any clue?
|
Re: Elapsed time
Hi,
It is a rather dirty work around, but can't you include MPI? MPI has some subroutines for performance measurements. Tom |
Re: Elapsed time
If your program is called myprog type
time myprog This will print out the elapsed cpu time (user and system). |
Re: Elapsed time
Compile the code as g77 -ff90 ..........
Try etime() if dtime() does not work -H |
Re: Elapsed time
Tom, how can I get this subroutine?
|
Re: Elapsed time
Thanks Tom. It worked, but I thought that there would be a more sophosticated way to do this.
|
Re: Elapsed time
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. |
Re: Elapsed time
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 |
Re: Elapsed time
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)" |
Re: Elapsed time
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.
|
Re: Elapsed time
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). |
Re: Elapsed time
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 |
Re: Elapsed time
what a mess! got mangled. let me know if you want the files.
|
Re: Elapsed time
|
All times are GMT -4. The time now is 12:21. |