Sfoglia il codice sorgente

hdf5: write 16 bit and flush correctly

Matthias Vogelgesang 9 anni fa
parent
commit
c1e8d0d19b
1 ha cambiato i file con 29 aggiunte e 27 eliminazioni
  1. 29 27
      hdf5perf/hdf5perf.c

+ 29 - 27
hdf5perf/hdf5perf.c

@@ -1,16 +1,19 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include <glib.h>
 #include <hdf5.h>
 
 
 static const int WIDTH = 2048;
-static const int HEIGHT = 1024;
+static const int HEIGHT = 2048;
 static const int N_DARKS = 10;
 static const int N_FLATS = 10;
-static const int N_PROJS = 100;
+static const int N_PROJS = 200;
 
 
 static void
-write_dataset (hid_t file, const char *name, const float *data, int n_items)
+write_dataset (hid_t file, const char *name, const guint16 *data, int n_items)
 {
     GTimer *timer;
     hid_t datatype;
@@ -24,22 +27,11 @@ write_dataset (hid_t file, const char *name, const float *data, int n_items)
     dims[1] = HEIGHT;
     dims[2] = n_items;
 
-    datatype = H5Tcopy (H5T_NATIVE_FLOAT);
+    datatype = H5Tcopy (H5T_STD_U16LE);
 
-    g_timer_start (timer);
     dataspace = H5Screate_simple (3, dims, NULL);
-    g_timer_stop (timer);
-    g_print (" H5Screate_simple: %3.5fs\n", g_timer_elapsed(timer, NULL));
-
-    g_timer_start (timer);
     dataset = H5Dcreate (file, name, datatype, dataspace, H5P_DEFAULT);
-    g_timer_stop (timer);
-    g_print (" H5Dcreate: %3.5fs\n", g_timer_elapsed(timer, NULL));
-
-    g_timer_start (timer);
-    H5Dwrite (dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
-    g_timer_stop (timer);
-    g_print (" H5Dwrite: %3.5fs\n", g_timer_elapsed(timer, NULL));
+    H5Dwrite (dataset, H5T_STD_U16LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
 
     H5Sclose (dataspace);
     H5Dclose (dataset);
@@ -48,7 +40,7 @@ write_dataset (hid_t file, const char *name, const float *data, int n_items)
 }
 
 static void
-create_individual_data_sets (hid_t file, const float *data)
+create_individual_data_sets (hid_t file, const guint16 *data)
 {
     write_dataset (file, "projs", data, N_PROJS);
     write_dataset (file, "darks", data, N_DARKS);
@@ -56,16 +48,18 @@ create_individual_data_sets (hid_t file, const float *data)
 }
 
 static void
-create_single_dataset (hid_t file, const float *data)
+create_single_dataset (hid_t file, const guint16 *data)
 {
     write_dataset (file, "all", data, N_DARKS + N_FLATS + N_PROJS);
 }
 
-static void
-run (void (*func)(hid_t, const float *), const char *fname, const float *data)
+static gdouble
+run (void (*func)(hid_t, const guint16 *), const char *fname, const guint16 *data)
 {
     hid_t file;
+    int fid;
     GTimer *timer;
+    gdouble elapsed;
 
     timer = g_timer_new ();
 
@@ -77,23 +71,31 @@ run (void (*func)(hid_t, const float *), const char *fname, const float *data)
     H5Fflush (file, H5F_SCOPE_GLOBAL);
     H5Fclose (file);
 
+    /* H5Fflush is extremely unreliable. So let's take out the hammer ... */
+    fid = open (fname, O_RDWR | O_SYNC);
+    fsync (fid);
+    close (fid);
+
     g_timer_stop (timer);
-    g_print (" Total: %3.5fs\n", g_timer_elapsed (timer, NULL));
+    elapsed = g_timer_elapsed (timer, NULL);
     g_timer_destroy (timer);
+    return elapsed;
 }
 
 int
 main (int argc, char const* argv[])
 {
-    float *data;
+    guint16 *data;
+    gsize size;
 
-    data = g_malloc (sizeof(float) * WIDTH * HEIGHT * (N_DARKS + N_FLATS + N_PROJS));
+    size = 2 * WIDTH * HEIGHT * (N_DARKS + N_FLATS + N_PROJS);
+    data = g_malloc (size);
 
-    g_print ("Single data set\n");
-    run (create_single_dataset, "bar.h5", data);
+    g_print ("Single data set: %f MB/s\n",
+             ((gdouble) size) / 1024. / 1024. / run (create_single_dataset, "bar.h5", data));
 
-    g_print ("\nIndividual data sets\n");
-    run (create_individual_data_sets, "foo.h5", data);
+    g_print ("Multi data set: %f MB/s\n",
+             ((gdouble) size) / 1024. / 1024. / run (create_individual_data_sets, "foo.h5", data));
 
     g_free (data);
     return 0;