[cig-commits] r4244 - mc/3D/CitcomS/trunk/lib
luis at geodynamics.org
luis at geodynamics.org
Mon Aug 7 14:24:29 PDT 2006
Author: luis
Date: 2006-08-07 14:24:28 -0700 (Mon, 07 Aug 2006)
New Revision: 4244
Modified:
mc/3D/CitcomS/trunk/lib/Output_h5.c
mc/3D/CitcomS/trunk/lib/hdf5_related.h
Log:
Added time dataset
Modified: mc/3D/CitcomS/trunk/lib/Output_h5.c
===================================================================
--- mc/3D/CitcomS/trunk/lib/Output_h5.c 2006-08-07 06:47:06 UTC (rev 4243)
+++ mc/3D/CitcomS/trunk/lib/Output_h5.c 2006-08-07 21:24:28 UTC (rev 4244)
@@ -58,6 +58,7 @@
void h5output_surf_botm(struct All_variables *, int);
void h5output_surf_botm_pseudo_surf(struct All_variables *, int);
void h5output_ave_r(struct All_variables *, int);
+void h5output_time(struct All_variables *, int);
#ifdef USE_HDF5
static hid_t h5create_file(const char *filename,
@@ -123,6 +124,7 @@
hid_t type_id,
int nodex, int nodey);
+static void h5create_time(hid_t loc_id);
#endif
extern void parallel_process_termination();
@@ -179,6 +181,12 @@
/* disable horizontal average h5output by Tan2 */
/* h5output_ave_r(E, cycles); */
+ /* TODO: call h5output_time() from outside h5output()
+ * it should be called for each cycle (instead of skipping
+ * cycles with monitoringFrequency).
+ */
+ h5output_time(E, cycles);
+
/* Count how many times we have called this function.
* This statement should always be the last one.
*/
@@ -301,6 +309,9 @@
type_id = E->hdf5.type_id;
+ /* Create dataset for timekeeping */
+ h5create_time(file_id);
+
/* Create necessary groups and arrays */
for(cap = 0; cap < caps; cap++)
{
@@ -369,7 +380,8 @@
void h5output_close(struct All_variables *E)
{
#ifdef USE_HDF5
- herr_t status = H5Fclose(E->hdf5.file_id);
+ herr_t status;
+ status = H5Fclose(E->hdf5.file_id);
free(E->hdf5.vector3d);
free(E->hdf5.scalar3d);
free(E->hdf5.vector2d);
@@ -952,8 +964,75 @@
h5create_field(loc_id, "topography", type_id, 1, nodex, nodey, 0, 0);
}
+static void h5create_time(hid_t loc_id)
+{
+ hid_t dcpl_id; /* dataset creation property list identifier */
+ hid_t datatype;
+ hid_t dataspace;
+ hid_t dataset;
+ herr_t status;
+ hsize_t dim = 0;
+ hsize_t maxdim = H5S_UNLIMITED;
+ hsize_t chunkdim = 1;
+ int i;
+ long n;
+ double x;
+
+ /* Modify dataset creation properties (enable chunking) */
+ dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
+ status = H5Pset_chunk(dcpl_id, 1, &chunkdim);
+
+ /* Create the dataspace */
+ dataspace = H5Screate_simple(1, &dim, &maxdim);
+
+ /* Create the memory data type */
+ datatype = H5Tcreate(H5T_COMPOUND, sizeof(struct HDF5_TIME));
+ status = H5Tinsert(datatype, "time", HOFFSET(struct HDF5_TIME, time), H5T_NATIVE_FLOAT);
+ status = H5Tinsert(datatype, "time_step", HOFFSET(struct HDF5_TIME, time_step), H5T_NATIVE_FLOAT);
+ status = H5Tinsert(datatype, "cpu", HOFFSET(struct HDF5_TIME, cpu), H5T_NATIVE_FLOAT);
+ status = H5Tinsert(datatype, "cpu_step", HOFFSET(struct HDF5_TIME, cpu_step), H5T_NATIVE_FLOAT);
+
+ /* Create the dataset */
+ dataset = H5Dcreate(loc_id, "time", datatype, dataspace, dcpl_id);
+
+ /*
+ * Write necessary attributes for PyTables compatibility
+ */
+
+ set_attribute(dataset, "TITLE", "Timing table");
+ set_attribute(dataset, "CLASS", "TABLE");
+ set_attribute(dataset, "FLAVOR", "numpy");
+ set_attribute(dataset, "VERSION", "2.6");
+
+ n = 0;
+ set_attribute_numerical(dataset, "NROWS", H5T_NATIVE_LONG, &n);
+
+ set_attribute(dataset, "FIELD_0_NAME", "time");
+ set_attribute(dataset, "FIELD_1_NAME", "time_step");
+ set_attribute(dataset, "FIELD_2_NAME", "cpu");
+ set_attribute(dataset, "FIELD_3_NAME", "cpu_step");
+
+ x = 0;
+ set_attribute_numerical(dataset, "FIELD_0_FILL", H5T_NATIVE_DOUBLE, &x);
+ set_attribute_numerical(dataset, "FIELD_1_FILL", H5T_NATIVE_DOUBLE, &x);
+ set_attribute_numerical(dataset, "FIELD_2_FILL", H5T_NATIVE_DOUBLE, &x);
+ set_attribute_numerical(dataset, "FIELD_3_FILL", H5T_NATIVE_DOUBLE, &x);
+
+ i = 1;
+ set_attribute_numerical(dataset, "AUTOMATIC_INDEX", H5T_NATIVE_INT, &i);
+ set_attribute_numerical(dataset, "REINDEX", H5T_NATIVE_INT, &i);
+ set_attribute(dataset, "FILTERS_INDEX", FILTERS_P);
+
+ /* Release resources */
+ status = H5Pclose(dcpl_id);
+ status = H5Tclose(datatype);
+ status = H5Sclose(dataspace);
+ status = H5Dclose(dataset);
+}
+
+
#endif
@@ -1555,3 +1634,72 @@
#endif
}
+void h5output_time(struct All_variables *E, int cycles)
+{
+#ifdef USE_HDF5
+ double CPU_time0();
+
+ hid_t dxpl_id; /* data transfer property list identifier */
+ hid_t datatype;
+ hid_t filespace;
+ hid_t dataspace;
+ hid_t dataset;
+
+ herr_t status;
+
+ hsize_t dim;
+ hsize_t offset;
+ hsize_t count;
+
+ struct HDF5_TIME row;
+
+ double current_time = CPU_time0();
+
+ if(E->parallel.me == 0)
+ {
+ /* Prepare data */
+ row.time = E->monitor.elapsed_time;
+ row.time_step = E->advection.timestep;
+ row.cpu = current_time - E->monitor.cpu_time_at_start;
+ row.cpu_step = current_time - E->monitor.cpu_time_at_last_cycle;
+
+ /* Get dataset */
+ dataset = H5Dopen(E->hdf5.file_id, "time");
+
+ /* Create property list for independent dataset write */
+ dxpl_id = H5Pcreate(H5P_DATASET_XFER);
+ status = H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_INDEPENDENT);
+
+ /* Extend dataset */
+ dim = cycles + 1;
+ status = H5Dextend(dataset, &dim);
+
+ /* Get file dataspace */
+ filespace = H5Dget_space(dataset);
+
+ /* Define memory dataspace */
+ dim = 1;
+ dataspace = H5Screate_simple(1, &dim, NULL);
+
+ /* Get datatype */
+ datatype = H5Dget_type(dataset);
+
+ /* Select hyperslab */
+ count = 1;
+ offset = cycles;
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET,
+ &offset, NULL, &count, NULL);
+
+ /* Write to hyperslab selection */
+ status = H5Dwrite(dataset, datatype, dataspace, filespace,
+ dxpl_id, &row);
+
+ /* Release resources */
+ status = H5Pclose(dxpl_id);
+ status = H5Tclose(datatype);
+ status = H5Sclose(dataspace);
+ status = H5Sclose(filespace);
+ status = H5Dclose(dataset);
+ }
+#endif
+}
Modified: mc/3D/CitcomS/trunk/lib/hdf5_related.h
===================================================================
--- mc/3D/CitcomS/trunk/lib/hdf5_related.h 2006-08-07 06:47:06 UTC (rev 4243)
+++ mc/3D/CitcomS/trunk/lib/hdf5_related.h 2006-08-07 21:24:28 UTC (rev 4244)
@@ -26,11 +26,26 @@
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
-/* In this file we define the contents of the HDF5_INFO data structure
- * that is used for collective output of citcom data. The contents
- * of this structure are initialized by the function h5output_open().
+/* In this file we define the following data structures:
+ *
+ * HDF5_INFO
+ * Used for collective output of citcom data.
+ *
+ * HDF5_TIME
+ * Used to define table with timing information.
+ *
+ * Any required initialization steps are performed in h5output_open().
+ *
*/
+struct HDF5_TIME
+{
+ float time;
+ float time_step;
+ float cpu;
+ float cpu_step;
+};
+
struct HDF5_INFO
{
char filename[100];
@@ -75,5 +90,5 @@
double *vector2d; /* shape (nx,ny,2) */
double *scalar2d; /* shape (nx,ny) */
double *scalar1d; /* shape (nz,) */
-
+
};
More information about the cig-commits
mailing list