[SCM] Gerris Flow Solver branch, upstream, updated. b3aa46814a06c9cb2912790b23916ffb44f1f203

Stephane Popinet s.popinet at niwa.co.nz
Fri May 15 02:52:25 UTC 2009


The following commit has been merged in the upstream branch:
commit 4b1307818dedbe3b0bce58cd20cf74308d46de27
Author: Stephane Popinet <s.popinet at niwa.co.nz>
Date:   Tue Aug 9 09:51:00 2005 +1000

    New GfsClock object replaces GTimer
    
    Times are now given as user CPU time rather than wall-clock time.
    
    darcs-hash:20050808235100-fbd8f-2c1ba9f3576c37d32a2d42db9aa5ddcdf899ae64.gz

diff --git a/src/domain.c b/src/domain.c
index 0b7444a..ff0a08f 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -229,7 +229,7 @@ static void domain_destroy (GtsObject * o)
   GfsDomain * domain = GFS_DOMAIN (o);
   GSList * i;
 
-  g_timer_destroy (domain->timer);
+  gfs_clock_destroy (domain->timer);
 
   i = domain->variables;
   while (i) {
@@ -275,7 +275,7 @@ static void domain_init (GfsDomain * domain)
   domain->pid = -1;
 #endif /* not HAVE_MPI */
 
-  domain->timer = g_timer_new ();
+  domain->timer = gfs_clock_new ();
   domain->timers = g_hash_table_new (g_str_hash, g_str_equal);
 
   gts_range_init (&domain->size);
@@ -2756,7 +2756,7 @@ void gfs_domain_timer_start (GfsDomain * domain, const gchar * name)
   }
   else
     g_return_if_fail (t->start < 0.);
-  t->start = g_timer_elapsed (domain->timer, NULL);
+  t->start = gfs_clock_elapsed (domain->timer);
 }
 
 /**
@@ -2773,7 +2773,7 @@ void gfs_domain_timer_stop (GfsDomain * domain, const gchar * name)
   gdouble end;
 
   g_return_if_fail (domain != NULL);
-  end = g_timer_elapsed (domain->timer, NULL);
+  end = gfs_clock_elapsed (domain->timer);
   g_return_if_fail (name != NULL);
 
   t = g_hash_table_lookup (domain->timers, name);
diff --git a/src/domain.h b/src/domain.h
index e8ffec1..e9607f5 100644
--- a/src/domain.h
+++ b/src/domain.h
@@ -39,7 +39,7 @@ struct _GfsDomain {
   GtsWGraph parent;
 
   int pid;
-  GTimer * timer;
+  GfsClock * timer;
   GHashTable * timers;
 
   GtsRange timestep;
diff --git a/src/ocean.c b/src/ocean.c
index 05408b1..06e147d 100644
--- a/src/ocean.c
+++ b/src/ocean.c
@@ -368,7 +368,7 @@ static void ocean_run (GfsSimulation * sim)
 			      (FttCellTraverseFunc) gfs_cell_coarse_init, domain);
     gts_container_foreach (GTS_CONTAINER (sim->events), (GtsFunc) gfs_event_do, sim);
 
-    tstart = g_timer_elapsed (domain->timer, NULL);
+    tstart = gfs_clock_elapsed (domain->timer);
 
     gfs_simulation_set_timestep (sim);
 
@@ -441,7 +441,7 @@ static void ocean_run (GfsSimulation * sim)
 
     gfs_simulation_adapt (sim, NULL);
 
-    gts_range_add_value (&domain->timestep, g_timer_elapsed (domain->timer, NULL) - tstart);
+    gts_range_add_value (&domain->timestep, gfs_clock_elapsed (domain->timer) - tstart);
     gts_range_update (&domain->timestep);
     gts_range_add_value (&domain->size, gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
     gts_range_update (&domain->size);
@@ -992,7 +992,7 @@ static void ocean1_run (GfsSimulation * sim)
 			      (FttCellTraverseFunc) gfs_cell_coarse_init, domain);
     gts_container_foreach (GTS_CONTAINER (sim->events), (GtsFunc) gfs_event_do, sim);
 
-    tstart = g_timer_elapsed (domain->timer, NULL);
+    tstart = gfs_clock_elapsed (domain->timer);
 
     gfs_simulation_set_timestep (sim);
     gfs_free_surface_divergence (domain, div);
@@ -1035,7 +1035,7 @@ static void ocean1_run (GfsSimulation * sim)
 
     gfs_simulation_adapt (sim, NULL);
 
-    gts_range_add_value (&domain->timestep, g_timer_elapsed (domain->timer, NULL) - tstart);
+    gts_range_add_value (&domain->timestep, gfs_clock_elapsed (domain->timer) - tstart);
     gts_range_update (&domain->timestep);
     gts_range_add_value (&domain->size, gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
     gts_range_update (&domain->size);
diff --git a/src/output.c b/src/output.c
index 06e9c8c..cc6dafc 100644
--- a/src/output.c
+++ b/src/output.c
@@ -484,13 +484,23 @@ void gfs_output_file_close (GfsOutputFile * file)
 
 /* GfsOutputTime: Object */
 
+static void time_destroy (GtsObject * o)
+{
+  gfs_clock_destroy (GFS_OUTPUT_TIME (o)->clock);
+
+  (* GTS_OBJECT_CLASS (gfs_output_time_class ())->parent_class->destroy) (o);  
+}
+
 static gboolean time_event (GfsEvent * event, GfsSimulation * sim)
 {
   if ((* GFS_EVENT_CLASS (gfs_output_class())->event) (event, sim)) {
+    if (!GFS_OUTPUT_TIME (event)->clock->started)
+      gfs_clock_start (GFS_OUTPUT_TIME (event)->clock);
     fprintf (GFS_OUTPUT (event)->file->fp,
-	     "step: %7u t: %15.8f dt: %13.6e\n",
+	     "step: %7u t: %15.8f dt: %13.6e cpu: %15.8f\n",
 	     sim->time.i, sim->time.t, 
-	     sim->advection_params.dt);
+	     sim->advection_params.dt,
+	     gfs_clock_elapsed (GFS_OUTPUT_TIME (event)->clock));
     return TRUE;
   }
   return FALSE;
@@ -498,9 +508,15 @@ static gboolean time_event (GfsEvent * event, GfsSimulation * sim)
 
 static void gfs_output_time_class_init (GfsEventClass * klass)
 {
+  GTS_OBJECT_CLASS (klass)->destroy = time_destroy;
   klass->event = time_event;
 }
 
+static void gfs_output_time_init (GfsOutputTime * time)
+{
+  time->clock = gfs_clock_new ();
+}
+
 GfsOutputClass * gfs_output_time_class (void)
 {
   static GfsOutputClass * klass = NULL;
@@ -508,10 +524,10 @@ GfsOutputClass * gfs_output_time_class (void)
   if (klass == NULL) {
     GtsObjectClassInfo gfs_output_time_info = {
       "GfsOutputTime",
-      sizeof (GfsOutput),
+      sizeof (GfsOutputTime),
       sizeof (GfsOutputClass),
       (GtsObjectClassInitFunc) gfs_output_time_class_init,
-      (GtsObjectInitFunc) NULL,
+      (GtsObjectInitFunc) gfs_output_time_init,
       (GtsArgSetFunc) NULL,
       (GtsArgGetFunc) NULL
     };
diff --git a/src/output.h b/src/output.h
index bc8deb7..1fdbd9b 100644
--- a/src/output.h
+++ b/src/output.h
@@ -69,6 +69,22 @@ void            gfs_output_file_close   (GfsOutputFile * file);
 
 /* GfsOutputTime: Header */
 
+typedef struct _GfsOutputTime         GfsOutputTime;
+
+struct _GfsOutputTime {
+  /*< private >*/
+  GfsOutput parent;
+
+  /*< public >*/
+  GfsClock * clock;
+};
+
+#define GFS_OUTPUT_TIME(obj)            GTS_OBJECT_CAST (obj,\
+					         GfsOutputTime,\
+					         gfs_output_time_class ())
+#define GFS_IS_OUTPUT_TIME(obj)         (gts_object_is_from_class (obj,\
+						 gfs_output_time_class ()))
+
 GfsOutputClass * gfs_output_time_class  (void);
 
 /* GfsOutputProgress: Header */
diff --git a/src/simulation.c b/src/simulation.c
index e2686dc..25a8254 100644
--- a/src/simulation.c
+++ b/src/simulation.c
@@ -540,7 +540,7 @@ static void simulation_run (GfsSimulation * sim)
 			      (FttCellTraverseFunc) gfs_cell_coarse_init, domain);
     gts_container_foreach (GTS_CONTAINER (sim->events), (GtsFunc) gfs_event_do, sim);
 
-    tstart = g_timer_elapsed (domain->timer, NULL);
+    tstart = gfs_clock_elapsed (domain->timer);
 
     gfs_simulation_set_timestep (sim);
 
@@ -586,7 +586,7 @@ static void simulation_run (GfsSimulation * sim)
     sim->time.t = sim->tnext;
     sim->time.i++;
 
-    gts_range_add_value (&domain->timestep, g_timer_elapsed (domain->timer, NULL) - tstart);
+    gts_range_add_value (&domain->timestep, gfs_clock_elapsed (domain->timer) - tstart);
     gts_range_update (&domain->timestep);
     gts_range_add_value (&domain->size, gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
     gts_range_update (&domain->size);
@@ -1155,10 +1155,10 @@ void gfs_simulation_run (GfsSimulation * sim)
 {
   g_return_if_fail (sim != NULL);
 
-  g_timer_start (GFS_DOMAIN (sim)->timer);
+  gfs_clock_start (GFS_DOMAIN (sim)->timer);
   gts_range_init (&GFS_DOMAIN (sim)->mpi_wait);
   (* GFS_SIMULATION_CLASS (GTS_OBJECT (sim)->klass)->run) (sim);
-  g_timer_stop (GFS_DOMAIN (sim)->timer);
+  gfs_clock_stop (GFS_DOMAIN (sim)->timer);
 }
 
 /* GfsAdvection: Object */
@@ -1197,7 +1197,7 @@ static void advection_run (GfsSimulation * sim)
 			      (FttCellTraverseFunc) gfs_cell_coarse_init, domain);
     gts_container_foreach (GTS_CONTAINER (sim->events), (GtsFunc) gfs_event_do, sim);
 
-    tstart = g_timer_elapsed (domain->timer, NULL);
+    tstart = gfs_clock_elapsed (domain->timer);
 
     gfs_simulation_set_timestep (sim);
 
@@ -1237,7 +1237,7 @@ static void advection_run (GfsSimulation * sim)
     sim->time.t = sim->tnext;
     sim->time.i++;
 
-    gts_range_add_value (&domain->timestep, g_timer_elapsed (domain->timer, NULL) - tstart);
+    gts_range_add_value (&domain->timestep, gfs_clock_elapsed (domain->timer) - tstart);
     gts_range_update (&domain->timestep);
     gts_range_add_value (&domain->size, gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
     gts_range_update (&domain->size);
@@ -1376,7 +1376,7 @@ static void poisson_run (GfsSimulation * sim)
 			      (FttCellTraverseFunc) gfs_cell_coarse_init, domain);
     gts_container_foreach (GTS_CONTAINER (sim->events), (GtsFunc) gfs_event_do, sim);
 
-    tstart = g_timer_elapsed (domain->timer, NULL);
+    tstart = gfs_clock_elapsed (domain->timer);
 
     gfs_poisson_cycle (domain, par->dimension, minlevel, maxlevel, par->nrelax, p, div, dia, res1);
     par->residual = gfs_domain_norm_residual (domain, FTT_TRAVERSE_LEAFS, -1, 1., res1);
@@ -1387,7 +1387,7 @@ static void poisson_run (GfsSimulation * sim)
     sim->time.t = sim->tnext;
     sim->time.i++;
 
-    gts_range_add_value (&domain->timestep, g_timer_elapsed (domain->timer, NULL) - tstart);
+    gts_range_add_value (&domain->timestep, gfs_clock_elapsed (domain->timer) - tstart);
     gts_range_update (&domain->timestep);
     gts_range_add_value (&domain->size, gfs_domain_size (domain, FTT_TRAVERSE_LEAFS, -1));
     gts_range_update (&domain->size);
diff --git a/src/utils.c b/src/utils.c
index e711f58..beda962 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <math.h>
+#include <sys/times.h>
 #include "config.h"
 #include "solid.h"
 #include "simulation.h"
@@ -1005,3 +1006,89 @@ void gfs_matrix_free (gpointer m)
   g_free (((gpointer *) m)[0]);
   g_free (m);
 }
+
+/**
+ * gfs_clock_new:
+ *
+ * Returns: a new #GfsClock.
+ */
+GfsClock * gfs_clock_new (void)
+{
+  GfsClock * t = g_malloc (sizeof (GfsClock));
+
+  t->start = -1;
+  t->started = FALSE;
+  return t;
+}
+
+/**
+ * gfs_clock_start:
+ * @t: a #GfsClock.
+ *
+ * Starts clock @t.
+ */
+void gfs_clock_start (GfsClock * t)
+{
+  struct tms tm;
+
+  g_return_if_fail (t != NULL);
+  g_return_if_fail (!t->started);
+
+  if (times (&tm) < 0)
+    g_warning ("cannot read clock");
+  t->start = tm.tms_utime;
+  t->started = TRUE;
+}
+
+/**
+ * gfs_clock_stop:
+ * @t: a #GfsClock.
+ *
+ * Stops clock @t.
+ */
+void gfs_clock_stop (GfsClock * t)
+{
+  struct tms tm;
+
+  g_return_if_fail (t != NULL);
+  g_return_if_fail (t->started);
+
+  if (times (&tm) < 0)
+    g_warning ("cannot read clock");
+  t->stop = tm.tms_utime;
+  t->started = FALSE;
+}
+
+/**
+ * gfs_clock_elapsed:
+ * @t: a #GfsClock.
+ *
+ * Returns: the time elapsed in seconds since @t was started.
+ */
+gdouble gfs_clock_elapsed (GfsClock * t)
+{
+  g_return_val_if_fail (t != NULL, 0.);
+  g_return_val_if_fail (t->start >= 0, 0.);
+
+  if (t->started == FALSE)
+    return (t->stop - t->start)/(gdouble) sysconf (_SC_CLK_TCK);
+  else {
+    struct tms tm;
+    if (times (&tm) < 0)
+      g_warning ("cannot read clock");
+    return (tm.tms_utime - t->start)/(gdouble) sysconf (_SC_CLK_TCK);
+  }
+}
+
+/**
+ * gfs_clock_destroy:
+ * @t: a #GfsClock.
+ *
+ * Destroys the clock, freeing the memory allocated for it.
+ */
+void gfs_clock_destroy (GfsClock * t)
+{
+  g_return_if_fail (t != NULL);
+
+  g_free (t);
+}
diff --git a/src/utils.h b/src/utils.h
index 90e4d9a..3eca0fc 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -92,6 +92,17 @@ gpointer           gfs_matrix_new           (guint n,
 					     guint size);
 void               gfs_matrix_free          (gpointer m);
 
+typedef struct {
+  gboolean started;
+  glong start, stop;
+} GfsClock;
+
+GfsClock *         gfs_clock_new            (void);
+void               gfs_clock_start          (GfsClock * t);
+void               gfs_clock_stop           (GfsClock * t);
+gdouble            gfs_clock_elapsed        (GfsClock * t);
+void               gfs_clock_destroy        (GfsClock * t);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

-- 
Gerris Flow Solver



More information about the debian-science-commits mailing list