bruce@seismo.gps.caltech.edu (Bruce Worden) (08/17/90)
In article <1990Aug16.190428.1@csc.fi> sbs@csc.fi writes: >I have problem on our SUN/3 or SUN/4 that I cannot get correct elapsed >time (real time, wall clock time) from function times(). Following >code works on Cray/UNICOS and Iris-4D (under SYSTEM V): > [code deleted] >And I will get that elapsed time (variable e) is equal to zero on our SUNs. >What is going wrong here (on SUN)? The problem appears to be that you are using the /usr/ucb cc, whose times() call returns 0 on success or -1 on failure. If you want to use times() as you have it here, you can use the cc in /usr/5bin, which uses the sysV libraries and works the way you want. -------------------------------------------------------------------------- Bruce Worden bruce@seismo.gps.caltech.edu 252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125 --------------------------------------------------------------------------
sbs@csc.fi (08/17/90)
I have problem on our SUN/3 or SUN/4 that I cannot get correct elapsed time (real time, wall clock time) from function times(). Following code works on Cray/UNICOS and Iris-4D (under SYSTEM V): #include <stdio.h> #include <sys/types.h> #include <sys/times.h> #include <sys/param.h> time_t init_elapsed_time; /* usually time_t is typedefed to long */ struct tms timebuffer; /* extern time_t times(); */ void starttime() /* retrieve (elapsed) time since boot etc. */ { init_elapsed_time = times(&timebuffer); } void cputime(elapsed,usercpu,systemcpu) /* retrieve CPU etc times spent after doing something */ float *elapsed,*usercpu,*systemcpu; { *elapsed = (float) (times(&timebuffer)-init_elapsed_time) / HZ; *usercpu = (float) timebuffer.tms_utime/HZ; *systemcpu = (float) timebuffer.tms_stime/HZ; return; } main() { float e,u,s; starttime(); /* initialize init_elapsed_time (may not be zero!) */ /* do something */ cputime(&e,&u,&s); /* print times */ } And I will get that elapsed time (variable e) is equal to zero on our SUNs. What is going wrong here (on SUN)? Please answer me directly (to sbs@csc.fi) or via NEWS . --------- Sami Saarinen Centre for Scientific Computing