Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/fem/src/CPUTime.c
3203 views
1
/*****************************************************************************
2
! *
3
! * Elmer, A Finite Element Software for Multiphysical Problems
4
! *
5
! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6
! *
7
! * This library is free software; you can redistribute it and/or
8
! * modify it under the terms of the GNU Lesser General Public
9
! * License as published by the Free Software Foundation; either
10
! * version 2.1 of the License, or (at your option) any later version.
11
! *
12
! * This library is distributed in the hope that it will be useful,
13
! * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
! * Lesser General Public License for more details.
16
! *
17
! * You should have received a copy of the GNU Lesser General Public
18
! * License along with this library (in file ../LGPL-2.1); if not, write
19
! * to the Free Software Foundation, Inc., 51 Franklin Street,
20
! * Fifth Floor, Boston, MA 02110-1301 USA
21
! *
22
! *****************************************************************************
23
!
24
! ******************************************************************************
25
! *
26
! * Provide system time / memory usage.
27
! *
28
! ******************************************************************************
29
! *
30
! * Authors: Juha Ruokolainen
31
! * Email: [email protected]
32
! * Web: http://www.csc.fi/elmer
33
! * Address: CSC - IT Center for Science Ltd.
34
! * Keilaranta 14
35
! * 02101 Espoo, Finland
36
! *
37
! * Original Date: 02 Jun 1997
38
! *
39
! *****************************************************************************/
40
41
#include "../config.h"
42
43
#if defined(MINGW32) || defined(WIN32)
44
45
#include <sys/types.h>
46
#include <time.h>
47
48
double STDCALLBULL FC_FUNC(realtime,REALTIME) ( )
49
{
50
return clock() / (double)CLOCKS_PER_SEC;
51
}
52
53
double STDCALLBULL FC_FUNC(cputime,CPUTIME) ( )
54
{
55
return clock() / (double)CLOCKS_PER_SEC;
56
}
57
58
double STDCALLBULL FC_FUNC(cpumemory,CPUMEMORY) ( )
59
{
60
return 0.0;
61
}
62
63
#else
64
65
#include <sys/types.h>
66
#include <sys/times.h>
67
#include <sys/param.h>
68
69
#include <sys/time.h>
70
#include <sys/resource.h>
71
72
static struct rusage usage;
73
74
static struct timeval tp;
75
static struct timezone tzp;
76
77
#ifdef USE_ISO_C_BINDINGS
78
double cputime ()
79
{
80
getrusage( RUSAGE_SELF, &usage );
81
return (double) usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1.0e-6;
82
}
83
84
double realtime()
85
{
86
gettimeofday( &tp,&tzp );
87
return (double) tp.tv_sec + tp.tv_usec*1.0e-6;
88
}
89
90
double cpumemory()
91
{
92
getrusage( RUSAGE_SELF, &usage );
93
return (double) 1.0 * usage.ru_maxrss;
94
}
95
#else
96
double FC_FUNC(cputime,CPUTIME) ()
97
{
98
getrusage( RUSAGE_SELF, &usage );
99
return (double) usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1.0e-6;
100
}
101
102
double FC_FUNC(realtime,REALTIME) ()
103
{
104
gettimeofday( &tp,&tzp );
105
return (double) tp.tv_sec + tp.tv_usec*1.0e-6;
106
}
107
108
double FC_FUNC(cpumemory,CPUMEMORY) ()
109
{
110
getrusage( RUSAGE_SELF, &usage );
111
return (double) 1.0 * usage.ru_maxrss;
112
}
113
#endif /* USE_ISO_C_BINDINGS*/
114
115
#endif // WIN32
116
117