OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [intrinsics/] [etime.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Implementation of the ETIME intrinsic.
2
   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3
   Contributed by Steven G. Kargl <kargls@comcast.net>.
4
 
5
This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
 
7
Libgfortran is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
11
 
12
In addition to the permissions in the GNU General Public License, the
13
Free Software Foundation gives you unlimited permission to link the
14
compiled version of this file into combinations with other programs,
15
and to distribute those combinations without any restriction coming
16
from the use of this file.  (The General Public License restrictions
17
do apply in other respects; for example, they cover modification of
18
the file, and distribution when not linked into a combine
19
executable.)
20
 
21
Libgfortran is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
GNU General Public License for more details.
25
 
26
You should have received a copy of the GNU General Public
27
License along with libgfortran; see the file COPYING.  If not,
28
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29
Boston, MA 02110-1301, USA.  */
30
 
31
#include "config.h"
32
#include <sys/types.h>
33
#include "libgfortran.h"
34
 
35
#include <stdio.h>
36
 
37
#if defined (HAVE_SYS_TIME_H) && defined (HAVE_SYS_RESOURCE_H)
38
#include <sys/time.h>
39
#include <sys/resource.h>
40
#endif
41
 
42
extern void etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result);
43
iexport_proto(etime_sub);
44
 
45
void
46
etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
47
{
48
  GFC_REAL_4 tu, ts, tt, *tp;
49
 
50
#if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
51
  struct rusage rt;
52
 
53
  if (getrusage(RUSAGE_SELF, &rt) == 0)
54
    {
55
      tu = (GFC_REAL_4)(rt.ru_utime.tv_sec + 1.e-6 * rt.ru_utime.tv_usec);
56
      ts = (GFC_REAL_4)(rt.ru_stime.tv_sec + 1.e-6 * rt.ru_stime.tv_usec);
57
      tt = tu + ts;
58
    }
59
  else
60
    {
61
      tu = -1.;
62
      ts = -1.;
63
      tt = -1.;
64
    }
65
#else
66
  tu = -1.;
67
  ts = -1.;
68
  tt = -1.;
69
#endif
70
 
71
  if (((t->dim[0].ubound + 1 - t->dim[0].lbound)) < 2)
72
    runtime_error ("Insufficient number of elements in TARRAY.");
73
 
74
  if (t->dim[0].stride == 0)
75
    t->dim[0].stride = 1;
76
 
77
  tp = t->data;
78
 
79
  *tp = tu;
80
  tp += t->dim[0].stride;
81
  *tp = ts;
82
  *result = tt;
83
}
84
iexport(etime_sub);
85
 
86
extern GFC_REAL_4 etime (gfc_array_r4 *t);
87
export_proto(etime);
88
 
89
GFC_REAL_4
90
etime (gfc_array_r4 *t)
91
{
92
  GFC_REAL_4 val;
93
  etime_sub (t, &val);
94
  return val;
95
}
96
 
97
/* LAPACK's test programs declares ETIME external, therefore we
98
   need this.  */
99
 
100
extern GFC_REAL_4 etime_ (GFC_REAL_4 *t);
101
export_proto_np(etime_);
102
 
103
GFC_REAL_4
104
etime_ (GFC_REAL_4 *t)
105
{
106
  gfc_array_r4 desc;
107
  GFC_REAL_4 val;
108
 
109
  /* We only fill in the fields that are used in etime_sub.  */
110
  desc.dim[0].lbound = 0;
111
  desc.dim[0].ubound = 1;
112
  desc.dim[0].stride = 1;
113
  desc.data = t;
114
 
115
  etime_sub (&desc, &val);
116
  return val;
117
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.