Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
chrono.c
Go to the documentation of this file.
1/* =============================================================================
2** This file is part of the mmg software package for the tetrahedral
3** mesh modification.
4** Copyright (c) Bx INP/CNRS/Inria/UBordeaux/UPMC, 2004-
5**
6** mmg is free software: you can redistribute it and/or modify it
7** under the terms of the GNU Lesser General Public License as published
8** by the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** mmg is distributed in the hope that it will be useful, but WITHOUT
12** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14** License for more details.
15**
16** You should have received a copy of the GNU Lesser General Public
17** License and of the GNU General Public License along with mmg (in
18** files COPYING.LESSER and COPYING). If not, see
19** <http://www.gnu.org/licenses/>. Please read their terms carefully and
20** use this copy of the mmg distribution only if you accept them.
21** =============================================================================
22*/
23
37#include <assert.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include "chrono_private.h"
41
49void chrono(int cmode,mytime *ptt) {
50
51 if ( cmode == RESET ) {
52 ptt->call = 0;
53 ptt->gini = ptt->gend = ptt->gdif = 0.0;
54 ptt->sini = ptt->send = ptt->sdif = 0.0;
55 ptt->uini = ptt->uend = ptt->udif = 0.0;
56 }
57 else {
58#ifdef MMG_POSIX
59 gettimeofday(&(ptt->rutim), NULL);
60#else
61 QueryPerformanceCounter(&ptt->rutim);
62
63 GetProcessTimes(ptt->thisProcess, &ptt->ftIni, &ptt->ftEnd, &ptt->ftSys, &ptt->ftUser);
64 FileTimeToSystemTime(&ptt->ftSys , &ptt->stSys );
65 FileTimeToSystemTime(&ptt->ftUser, &ptt->stUser);
66#endif
67 if ( cmode == ON ) {
68#ifdef MMG_POSIX
69 ptt->gini = (double)((ptt->rutim.tv_sec ) + (ptt->rutim.tv_usec) * BIG1);
70
71 getrusage(RUSAGE_SELF,&(ptt->ru));
72 ptt->rutim = ptt->ru.ru_utime;
73 ptt->uini = (double)((ptt->rutim.tv_sec) * BIG + (ptt->rutim.tv_usec));
74 ptt->rutim = ptt->ru.ru_stime;
75 ptt->sini = (double)((ptt->rutim.tv_sec )* BIG + (ptt->rutim.tv_usec));
76#else
77 ptt->gini = (double)(ptt->rutim.QuadPart / ptt->frequency.QuadPart);
78
79 ptt->uini = ((double)ptt->stUser.wHour * 3600 + (double)ptt->stUser.wMinute * 60
80 + (double)ptt->stUser.wSecond) * BIG + (double)ptt->stUser.wMilliseconds * 1000;
81 ptt->sini = ((double)ptt->stSys.wHour * 3600 + (double)ptt->stSys.wMinute * 60
82 + (double)ptt->stSys.wSecond) * BIG + (double)ptt->stSys.wMilliseconds * 1000;
83#endif
84 }
85 else if ( cmode == OFF ) {
86#ifdef MMG_POSIX
87 ptt->gend = (double)((ptt->rutim.tv_sec ) + (ptt->rutim.tv_usec) * BIG1);
88
89 getrusage(RUSAGE_SELF,&(ptt->ru));
90 ptt->rutim = ptt->ru.ru_utime;
91 ptt->uend = (double)((ptt->rutim.tv_sec ) * BIG + (ptt->rutim.tv_usec));
92 ptt->rutim = ptt->ru.ru_stime;
93 ptt->send = (double)((ptt->rutim.tv_sec ) * BIG + (ptt->rutim.tv_usec));
94#else
95 ptt->gend = (double)(ptt->rutim.QuadPart / ptt->frequency.QuadPart);
96
97 ptt->uend = ((double)ptt->stUser.wHour * 3600 + (double)ptt->stUser.wMinute * 60
98 + (double)ptt->stUser.wSecond) * BIG + (double)ptt->stUser.wMilliseconds * 1000;
99 ptt->send = ((double)ptt->stSys.wHour * 3600 + (double)ptt->stSys.wMinute * 60
100 + (double)ptt->stSys.wSecond) * BIG + (double)ptt->stSys.wMilliseconds * 1000;
101#endif
102
103 ptt->gdif += ptt->gend - ptt->gini;
104
105 ptt->udif += (ptt->uend - ptt->uini) * BIG1;
106 ptt->sdif += (ptt->send - ptt->sini) * BIG1;
107
108 ptt->call++;
109 }
110 }
111}
112
113
120void tminit(mytime *t,int maxtim) {
121 mytime *ptt;
122 int k;
123
124#ifndef MMG_POSIX
125 QueryPerformanceFrequency(&t[0].frequency);
126
127 t[0].thisProcess = GetCurrentProcess();
128 for (k = 1; k < maxtim; k++) {
129 t[k].frequency = t[0].frequency;
130 t[k].thisProcess = t[0].thisProcess;
131 }
132#endif
133 for (k=0; k<maxtim; k++) {
134 ptt = &t[k];
135 ptt->call = 0;
136 ptt->gini = ptt->gend = ptt->gdif = 0.0;
137 ptt->sini = ptt->send = ptt->sdif = 0.0;
138 ptt->uini = ptt->uend = ptt->udif = 0.0;
139 }
140}
141
142#ifdef MMG_COMPARABLE_OUTPUT
149void printim(double elps,char *stim) {
150 sprintf(stim,"");
151}
152
153#else
160void printim(double elps,char *stim) {
161 int hh,mm,ss;
162
163 if ( elps < 60.0 )
164 sprintf(stim,"%5.3lfs",elps);
165 else if ( elps < 3600.0 ) {
166 mm = (int)(elps / 60.0);
167 ss = (int)elps - mm * 60;
168 sprintf(stim,"%dm%ds (%7.3lfs)",mm,ss,elps);
169 }
170 else {
171 hh = (int)(elps / 3600);
172 mm = (int)((elps - hh*3600) / 60);
173 ss = (int)(elps - mm*60 - hh*3600);
174 sprintf(stim,"%dh%dm%ds",hh,mm,ss);
175 }
176}
177#endif
void tminit(mytime *t, int maxtim)
Initialize mytime object.
Definition: chrono.c:120
void printim(double elps, char *stim)
Print real time.
Definition: chrono.c:160
void chrono(int cmode, mytime *ptt)
Function to measure time.
Definition: chrono.c:49
#define BIG
#define BIG1
Chrono object.
FILETIME ftEnd
double gdif
double sdif
LARGE_INTEGER rutim
FILETIME ftIni
double gini
SYSTEMTIME stSys
FILETIME ftSys
SYSTEMTIME stUser
FILETIME ftUser
LARGE_INTEGER frequency
double gend
double sini
HANDLE thisProcess
double uini
double send
double uend
double udif