OpenCMISS-Iron Internal API Documentation
timer_c.c
Go to the documentation of this file.
1 /* \file
2  * \author Chris Bradley
3  * \brief This file provides c utility routines for the timer module.
4  *.
5  * \section LICENSE
6  *
7  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.1 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
16  * License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * The Original Code is OpenCMISS
20  *
21  * The Initial Developer of the Original Code is University of Auckland,
22  * Auckland, New Zealand, the University of Oxford, Oxford, United
23  * Kingdom and King's College, London, United Kingdom. Portions created
24  * by the University of Auckland, the University of Oxford and King's
25  * College, London are Copyright (C) 2007-2010 by the University of
26  * Auckland, the University of Oxford and King's College, London.
27  * All Rights Reserved.
28  *
29  * Contributor(s):
30  *
31  * Alternatively, the contents of this file may be used under the terms of
32  * either the GNU General Public License Version 2 or later (the "GPL"), or
33  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34  * in which case the provisions of the GPL or the LGPL are applicable instead
35  * of those above. If you wish to allow use of your version of this file only
36  * under the terms of either the GPL or the LGPL, and not to allow others to
37  * use your version of this file under the terms of the MPL, indicate your
38  * decision by deleting the provisions above and replace them with the notice
39  * and other provisions required by the GPL or the LGPL. If you do not delete
40  * the provisions above, a recipient may use your version of this file under
41  * the terms of any one of the MPL, the GPL or the LGPL.
42  *
43  */
44 
45 /*
46 File: timer_c.c
47 ===================
48 
49 This file provides c utility routines for the timer module.
50 
51 Functions included:
52 
53 CPUTimer Returns the CPU time
54 
55 */
56 
57 /* Included files */
58 
59 #include <limits.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <time.h>
64 #ifdef VMS
65 #include <time.h>
66 #include <types.h>
67 #endif
68 #ifdef mips
69 #include <sys/times.h>
70 #include <sys/types.h>
71 #endif
72 #ifdef WIN32
73 #include <time.h>
74 #endif
75 #ifdef linux
76 #include <time.h>
77 #include <sys/times.h>
78 #include <unistd.h>
79 #endif
80 #ifdef _AIX
81 #include <time.h>
82 #include <sys/times.h>
83 #include <unistd.h>
84 #endif
85 
86 /* Type definitions */
87 
88 /* Function Definitions */
89 
90 void CPUTimer(double *return_time,
91  int *flag,
92  int *err,
93  char error_string[])
94 
95 /* keep these up to date with timer_f.f90 */
96 
97 #define USER_CPU 1
98 #define SYSTEM_CPU 2
99 #define TOTAL_CPU 3
100 
101 {
102  double system_time,total_time,user_time;
103 #if defined VMS
104  struct tbuffer current_time;
105 
106  times(&current_time);
107  user_time = ((double)(current_time.proc_user_time))/100.0;
108  system_time = ((double)(current_time.proc_system_time))/100.0;
109 #endif
110 #if defined mips
111  struct tms current_time;
112 
113  times(&current_time);
114  user_time = ((double)(current_time.tms_utime))/((double)(CLOCKS_PER_SEC));
115  system_time = ((double)(current_time.tms_stime))/((double)(CLOCKS_PER_SEC));
116 #endif
117 #if defined WIN32
118  clock_t current_time;
119 
120  current_time = clock();
121  user_time = ((double)(current_time)/(double)(CLOCKS_PER_SEC));
122  system_time = 0.0;
123 #endif
124 #if defined linux
125  struct tms current_time;
126 
127  times(&current_time);
128  user_time = ((double)(current_time.tms_utime))/((double)sysconf(_SC_CLK_TCK));
129  system_time = ((double)(current_time.tms_stime))/((double)sysconf(_SC_CLK_TCK));
130 #endif
131 #if defined _AIX
132  struct tms current_time;
133 
134  times(&current_time);
135  user_time = ((double)(current_time.tms_utime))/((double)sysconf(_SC_CLK_TCK));
136  system_time = ((double)(current_time.tms_stime))/((double)sysconf(_SC_CLK_TCK));
137 #endif
138 
139  total_time = user_time+system_time;
140  *err=0;
141  switch(*flag)
142  {
143  case TOTAL_CPU:
144  {
145  *return_time = total_time;
146  }; break;
147  case USER_CPU:
148  {
149  *return_time = user_time;
150  }; break;
151  case SYSTEM_CPU:
152  {
153  *return_time = system_time;
154  }; break;
155  default:
156  {
157  *err=1;
158  strcpy(error_string,"Invalid operation code");
159  *return_time = -99999.0; /* get some attention! */
160  }
161  }
162 }
163 
164 
#define TOTAL_CPU
#define SYSTEM_CPU
#define USER_CPU
void CPUTimer(double *return_time, int *flag, int *err, char error_string[])
Definition: timer_c.c:90