123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #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 = 2048;
- static const int N_DARKS = 10;
- static const int N_FLATS = 10;
- static const int N_PROJS = 200;
- static void
- write_dataset (hid_t file, const char *name, const guint16 *data, int n_items)
- {
- GTimer *timer;
- hid_t datatype;
- hid_t dataspace;
- hid_t dataset;
- hsize_t dims[3];
- timer = g_timer_new ();
- dims[0] = WIDTH;
- dims[1] = HEIGHT;
- dims[2] = n_items;
- datatype = H5Tcopy (H5T_STD_U16LE);
- dataspace = H5Screate_simple (3, dims, NULL);
- dataset = H5Dcreate (file, name, datatype, dataspace, H5P_DEFAULT);
- H5Dwrite (dataset, H5T_STD_U16LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
- H5Sclose (dataspace);
- H5Dclose (dataset);
- H5Tclose (datatype);
- g_timer_destroy (timer);
- }
- static void
- create_individual_data_sets (hid_t file, const guint16 *data)
- {
- write_dataset (file, "projs", data, N_PROJS);
- write_dataset (file, "darks", data, N_DARKS);
- write_dataset (file, "flats", data, N_FLATS);
- }
- static void
- create_single_dataset (hid_t file, const guint16 *data)
- {
- write_dataset (file, "all", data, N_DARKS + N_FLATS + N_PROJS);
- }
- 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 ();
- g_timer_start (timer);
- file = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- func (file, 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);
- elapsed = g_timer_elapsed (timer, NULL);
- g_timer_destroy (timer);
- return elapsed;
- }
- int
- main (int argc, char const* argv[])
- {
- guint16 *data;
- gsize size;
- size = 2 * WIDTH * HEIGHT * (N_DARKS + N_FLATS + N_PROJS);
- data = g_malloc (size);
- g_print ("Single data set: %f MB/s\n",
- ((gdouble) size) / 1024. / 1024. / run (create_single_dataset, "bar.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;
- }
|