[comp.lang.fortran] XLF function

fn@fractal.math.yale.edu (Francois Normant) (06/26/91)

In article <3186@lee.SEAS.UCLA.EDU> hdai@edison.seas.ucla.edu (HongXing Dai) writes:
>I wrote a Fortran program which used etime() to compute the elapsed
>system time of the process and it worked fine on DEC Ultrix and
>Sun SparcStation.  But AIX doesn't have equivalent function (so
>far as I can tell from the tiny manual comes with the system) in
>Fortran, nor in C.  XLF does have one MCLOCK() which returns time
>accounting (=current process's user time+user and system time of
>all chile processes) which differed a lot from ps said.  Could 
>anyone shed a light on how to deal with it in either XLC or XLF
>functions?  Thanks in advance.
>
>Dai 

I asked the same question yesterday evening on comp.lang.fortran.
Since then I received many answers telling me to use MCLOCK().
Nevertheless, I decided to recreate itime, idate, dtime and etime to be able
to keep original fortran sources (from sun or gould).
So here the result of half an hour of work, it's not very smart but as far
as I can tell, it seems to work.

Disclaimer: I'm not a fortran hacker, so the behavior of this new functions may
be different as those originally in /usr/lib/libU77.a (SUN).
Corrections are welcome.
I speak for my self ..... blah blah blah.



/*
*********************************************************************************
* File:         time.c
* Description: 	itime, idate, dtime and etime functions for xlf.
* Author:       Francois Normant, math department, Yale University
* E-Mail:       fn@math.yale.edu
* Created:      Tue Jun 25 1991 14:41:15 EDT 1991
* Modified:     91/01/24 (Francois Normant)
* Language:     C
* Package:	RS6000 tools
* Howto:	compile with 'cc -O -c time.c' and link time.o with your 
*		fortran files.
*
*********************************************************************************/

/*
* Copyright (c) 1991 by Francois Normant.
* All rights reserved.
*
* This file is provided for unrestricted use provided that this
* legend is included on all tape media and as a part of the
* software program in whole or part.  Users may copy, modify or
* distribute this file at will.
*/


#include<sys/time.h>
#include<sys/times.h>
#include<time.h>

long _last_user_time=0;
long _last_system_time=0;

void itime(time)
int time[3];
{
struct tm *tm;
struct timeval tp;
gettimeofday(&tp,NULL);
tm=localtime(&(tp.tv_sec));
time[0]=tm->tm_hour;
time[1]=tm->tm_min;
time[2]=tm->tm_sec;
}

void idate(date)
int date[3];
{
struct tm *tm;
struct timeval tp;
gettimeofday(&tp,NULL);
tm=localtime(&(tp.tv_sec));
date[0]=tm->tm_mday;
date[1]=tm->tm_mon+1; /* in C january = 0 */
date[2]=tm->tm_year+1900; /* in C 1900 = 0 */
}

float etime(time)
float time[2];
{
struct tms buffer;

times(&buffer);
time[0]=(float)(buffer.tms_utime)/100.;
time[1]=(float)(buffer.tms_stime)/100.;
return(time[0]+time[1]);
}

float dtime(time)
float time[2];
{
struct tms buffer;

times(&buffer);
time[0]=(float)(buffer.tms_utime-_last_user_time)/100.;
time[1]=(float)(buffer.tms_stime-_last_system_time)/100.;
_last_user_time=buffer.tms_utime;
_last_system_time=buffer.tms_stime;
return(time[0]+time[1]);
}


-- 
Francois Normant - fn@math.yale.edu
Yale University - Mathematics Department
Box 2155 - Yale Station
New Haven CT 06520