cbec90699f
- creato il progetto in Visual Studio per compilare come libreria statica - modifiche al codice originale per integrarlo nelle nostre librerie.
207 lines
7.0 KiB
C++
207 lines
7.0 KiB
C++
/*****************************************************************************/
|
|
/* */
|
|
/* F I S T : Fast, Industrial-Strength Triangulation */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* (C) Martin Held */
|
|
/* (C) Universitaet Salzburg, Salzburg, Austria */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in api_functions.cpp. */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "fpkernel.h"
|
|
#include "martin.h"
|
|
#include "defs.h"
|
|
|
|
/* */
|
|
/* Note: CPUTIME_IN_MILLISECONDS can be defined in the Imakefile by using */
|
|
/* flag "-DCPUTIME_IN_MILLISECONDS". */
|
|
/* */
|
|
|
|
/* */
|
|
/* Note2:CPUTIME_IN_MILLISECONDS should be turned off for parallel clipping! */
|
|
/* */
|
|
|
|
#ifdef NO_CPUTIME
|
|
machine_double elapsed(global_struct *all) {
|
|
return -1 ;
|
|
}
|
|
#else
|
|
|
|
|
|
|
|
|
|
#ifdef PARTITION_FIST
|
|
#undef CPUTIME_IN_MILLISECONDS
|
|
#undef CPUTIME_VIA_CLOCK
|
|
#endif
|
|
|
|
|
|
#ifdef CPUTIME_IN_MILLISECONDS
|
|
#include <sys/resource.h>
|
|
#ifndef RUSAGE_CHILDREN
|
|
#undef CPUTIME_IN_MILLISECONDS
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef CPUTIME_IN_MILLISECONDS
|
|
|
|
/* */
|
|
/* This procedure computes the CPU time used by the calling process since */
|
|
/* the last call. (The sum of both system and user time is reported.) */
|
|
/* Call it before and after the execution of some instructions of your */
|
|
/* program, whose CPU consumption you would like to know. The first value */
|
|
/* returned can be ignored, and the second value gives the actual CPU */
|
|
/* consumption in the form milliseconds.microseconds. (I.e., 12345 microsecs */
|
|
/* are returned as 12.345 millisecs.) */
|
|
/* */
|
|
machine_double elapsed(global_struct *all)
|
|
{
|
|
machine_double cpu_time;
|
|
unsigned long new_secs, secs, new_usecs, usecs, new_add_secs;
|
|
int getrusage(int who, struct rusage *rusage);
|
|
struct rusage rusage_self, rusage_children;
|
|
|
|
getrusage(RUSAGE_SELF, &rusage_self);
|
|
getrusage(RUSAGE_CHILDREN, &rusage_children);
|
|
|
|
new_secs = rusage_self.ru_utime.tv_sec +
|
|
rusage_self.ru_stime.tv_sec +
|
|
rusage_children.ru_utime.tv_sec +
|
|
rusage_children.ru_stime.tv_sec;
|
|
new_usecs = rusage_self.ru_utime.tv_usec +
|
|
rusage_self.ru_stime.tv_usec +
|
|
rusage_children.ru_utime.tv_usec +
|
|
rusage_children.ru_stime.tv_usec;
|
|
|
|
if (new_usecs >= 1000000) {
|
|
new_add_secs = new_usecs / 1000000;
|
|
new_usecs -= new_add_secs * 1000000;
|
|
new_secs += new_add_secs;
|
|
}
|
|
|
|
if (all->total_usecs > new_usecs) {
|
|
secs = new_secs - all->total_secs - 1;
|
|
usecs = new_usecs -all-> total_usecs + 1000000;
|
|
}
|
|
else {
|
|
secs = new_secs - all->total_secs;
|
|
usecs = new_usecs - all->total_usecs;
|
|
}
|
|
|
|
all->total_secs = new_secs;
|
|
all->total_usecs = new_usecs;
|
|
|
|
cpu_time = 1.0e3 * (machine_double) secs + 1.0e-3 * (machine_double) usecs;
|
|
|
|
return cpu_time;
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* ifndef CPUTIME_IN_MILLISECONDS */
|
|
|
|
#ifdef CPUTIME_VIA_CLOCK
|
|
|
|
#include <time.h>
|
|
#include "fpkernel.h"
|
|
#include "martin.h"
|
|
#include "defs.h"
|
|
|
|
#define CLOCK_UNITS 1000.0 /* this could be figured out automatically */
|
|
|
|
/* */
|
|
/* This procedure computes the CPU time used by the calling process since */
|
|
/* the last call. (The sum of both system and user time is reported.) */
|
|
/* Call it before and after the execution of some instructions of your */
|
|
/* program, whose CPU consumption you would like to know. The first value */
|
|
/* returned can be ignored, and the second value gives the actual CPU */
|
|
/* consumption in the form milliseconds.microseconds. (I.e., 12345 microsecs */
|
|
/* are returned as 12.345 millisecs.) */
|
|
/* */
|
|
machine_double elapsed(global_struct *all)
|
|
{
|
|
machine_double cpu_time;
|
|
clock_t finish;
|
|
|
|
#ifndef CLOCKS_PER_SEC
|
|
#define CLOCKS_PER_SEC sysconf(_SC_CLK_TCK)
|
|
#endif
|
|
|
|
if (! all->cpu_time_initialized) {
|
|
all->total_cpu_time = clock();
|
|
all->cpu_time_initialized = true;
|
|
}
|
|
finish = clock();
|
|
|
|
cpu_time = ((machine_double) (finish - all->total_cpu_time)) *
|
|
(CLOCK_UNITS / CLOCKS_PER_SEC);
|
|
all->total_cpu_time = finish;
|
|
|
|
return cpu_time;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else /* ifndef CPUTIME_IN_MILLISECONDS || CPUTIME_VIA_CLOCK */
|
|
|
|
|
|
|
|
//#include <sys/types.h>
|
|
//#include <sys/times.h>
|
|
///*#include <time.h> */
|
|
//#include <unistd.h>
|
|
|
|
#include "martin.h"
|
|
#include "defs.h"
|
|
|
|
/* */
|
|
/* This procedure computes the CPU time used by the calling process since */
|
|
/* the last call. (The sum of both system and user time is reported.) */
|
|
/* Call it before and after the execution of some instructions of your */
|
|
/* program, whose CPU consumption you would like to know. The first value */
|
|
/* returned can be ignored, and the second value gives the actual CPU */
|
|
/* consumption (in milliseconds). */
|
|
/* */
|
|
|
|
/* gettimeofday() is a wall-clock and better suited to this task than times()*/
|
|
#include <sys/time.h>
|
|
|
|
machine_double elapsed(global_struct *all)
|
|
{
|
|
// long dummy;
|
|
// machine_double cpu_time;
|
|
// struct tms buffer;
|
|
// int HZ = sysconf(_SC_CLK_TCK);
|
|
//
|
|
// times(&buffer);
|
|
// dummy = buffer.tms_utime + buffer.tms_stime +
|
|
// buffer.tms_cutime + buffer.tms_cstime;
|
|
// cpu_time = (machine_double) ((dummy - all->total_cpu_time) * 1000.0) / HZ;
|
|
// all->total_cpu_time = dummy;
|
|
//
|
|
// return cpu_time;
|
|
|
|
if(all->cpu_time == 0.0) gettimeofday(&all->start, NULL);
|
|
else gettimeofday(&all->end, NULL);
|
|
|
|
double elapsedTime = (all->end.tv_sec - all->start.tv_sec) * 1000.0;
|
|
elapsedTime += (all->end.tv_usec - all->start.tv_usec) / 1000.0;
|
|
|
|
return elapsedTime;
|
|
}
|
|
|
|
|
|
#endif
|
|
#endif
|
|
#endif
|