[Commits] [svn:einsteintoolkit] SphericalHarmonicDecomp/trunk/ (Rev. 7)
yosef at astro.rit.edu
yosef at astro.rit.edu
Mon Jul 30 13:57:21 CDT 2012
User: zlochower
Date: 2012/07/30 01:57 PM
Modified:
/trunk/
param.ccl
/trunk/src/
ExtractMetric.cc, SphericalHarmonicDecomp.h
Log:
Check status of hdf5 IO operations and optionally kill run
if they fail (not default)
File Changes:
Directory: /trunk/src/
======================
File [modified]: ExtractMetric.cc
Delta lines: +124 -77
===================================================================
--- trunk/src/ExtractMetric.cc 2012-05-28 22:22:18 UTC (rev 6)
+++ trunk/src/ExtractMetric.cc 2012-07-30 18:57:20 UTC (rev 7)
@@ -12,6 +12,22 @@
#include <complex>
#include "sYlm.hh"
+static int hdf5_warn_level = CCTK_WARN_ALERT;
+
+#define HDF5_ERROR(fn_call) \
+ do { \
+ int _error_code = fn_call; \
+ \
+ \
+ if (_error_code < 0) \
+ { \
+ CCTK_VWarn (hdf5_warn_level, __LINE__, __FILE__, CCTK_THORNSTRING, \
+ "HDF5 call '%s' returned error code %d", \
+ #fn_call, _error_code); \
+ error_count++; \
+ } \
+ } while (0)
+
#ifdef USE_LEGENDRE
# include "Legendre.hh"
#endif
@@ -248,10 +264,12 @@
dims[0] = nn;
dims[1] = nlmmodes;
+ int error_count = 0;
static int FirstCall = 1;
static int last_dump[MAX_RADII];
const int dump_it = iter;
+ hid_t dataset_id, attribute_id, dataspace_id, group_id;
if (FirstCall)
{
@@ -262,107 +280,122 @@
}
}
+ bool file_exists = false;
+ H5E_BEGIN_TRY {
+ file_exists = H5Fis_hdf5(filename) > 0;
+ } H5E_END_TRY;
+
+ if(file_exists)
{
- /* OK there must be a better to test if the file exists */
- FILE *file = fopen(filename, "rb");
-
- if (!file)
+ file_id = H5Fopen (filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ if (file_id < 0)
{
- file_id = H5Fcreate (filename, H5F_ACC_TRUNC,
+ CCTK_WARN(hdf5_warn_level, "Failed to open hdf5 file");
+ }
+ }
+ else
+ {
+ file_id = H5Fcreate (filename, H5F_ACC_TRUNC,
H5P_DEFAULT, H5P_DEFAULT);
+ if (file_id < 0)
+ {
+ CCTK_WARN(hdf5_warn_level, "Failed to create hdf5 file");
+ }
- {
- hid_t dataset_id, attribute_id, dataspace_id, group_id;
- char name[]="/metadata";
- group_id = H5Gcreate(file_id, name, 0);
+ char name[]="/metadata";
+ HDF5_ERROR(group_id = H5Gcreate(file_id, name, 0));
- int ds[2] = {nn, nlmmodes};
- hsize_t oD2 = 2;
- hsize_t oD1 = 1;
+ int ds[2] = {nn, nlmmodes};
+ hsize_t oD2 = 2;
+ hsize_t oD1 = 1;
- dataspace_id = H5Screate_simple(1, &oD2, NULL);
- attribute_id = H5Acreate(group_id, "dim", H5T_NATIVE_INT,
- dataspace_id, H5P_DEFAULT);
- status = H5Awrite(attribute_id, H5T_NATIVE_INT, ds);
- status = H5Aclose(attribute_id);
- status = H5Sclose(dataspace_id);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(1, &oD2, NULL));
+ HDF5_ERROR(attribute_id = H5Acreate(group_id, "dim", H5T_NATIVE_INT,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Awrite(attribute_id, H5T_NATIVE_INT, ds));
+ HDF5_ERROR(status = H5Aclose(attribute_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
- dataspace_id = H5Screate_simple(1, &oD1, NULL);
- attribute_id = H5Acreate(group_id, "spin", H5T_NATIVE_INT,
- dataspace_id, H5P_DEFAULT);
- status = H5Awrite(attribute_id, H5T_NATIVE_INT, &s);
- status = H5Aclose(attribute_id);
- status = H5Sclose(dataspace_id);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(1, &oD1, NULL));
+ HDF5_ERROR(attribute_id = H5Acreate(group_id, "spin", H5T_NATIVE_INT,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Awrite(attribute_id, H5T_NATIVE_INT, &s));
+ HDF5_ERROR(status = H5Aclose(attribute_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
- dataspace_id = H5Screate_simple(1, &oD1, NULL);
- attribute_id = H5Acreate(group_id, "Rin", H5T_NATIVE_DOUBLE,
- dataspace_id, H5P_DEFAULT);
- status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &rin);
- status = H5Aclose(attribute_id);
- status = H5Sclose(dataspace_id);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(1, &oD1, NULL));
+ HDF5_ERROR(attribute_id = H5Acreate(group_id, "Rin", H5T_NATIVE_DOUBLE,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &rin));
+ HDF5_ERROR(status = H5Aclose(attribute_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
- dataspace_id = H5Screate_simple(1, &oD1, NULL);
- attribute_id = H5Acreate(group_id, "Rout", H5T_NATIVE_DOUBLE,
- dataspace_id, H5P_DEFAULT);
- status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &rout);
- status = H5Aclose(attribute_id);
- status = H5Sclose(dataspace_id);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(1, &oD1, NULL));
+ HDF5_ERROR(attribute_id = H5Acreate(group_id, "Rout", H5T_NATIVE_DOUBLE,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &rout));
+ HDF5_ERROR(status = H5Aclose(attribute_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
- H5Gclose(group_id);
+ HDF5_ERROR(H5Gclose(group_id));
- }
- }
- else
+ if (error_count > 0)
{
- fclose(file);
- file_id = H5Fopen (filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ CCTK_WARN(hdf5_warn_level, "Failed to initialize hdf5 file");
}
}
+ char buff[BUFFSIZE];
+ if (dump_it > last_dump[obs])
{
- hid_t group_id, dataset_id, attribute_id, dataspace_id;
- char buff[BUFFSIZE];
- if (dump_it > last_dump[obs])
+ hsize_t oneD = 1;
+ snprintf(buff, sizeof buff, "/%d", dump_it);
+ HDF5_ERROR(group_id = H5Gcreate(file_id, buff, 0));
+ HDF5_ERROR(dataspace_id = H5Screate_simple(1, &oneD, NULL));
+ HDF5_ERROR(attribute_id = H5Acreate(group_id, "Time", H5T_NATIVE_DOUBLE,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &time));
+ HDF5_ERROR(status = H5Aclose(attribute_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
+ HDF5_ERROR(H5Gclose(group_id));
+
+ if (error_count > 0)
{
- hsize_t oneD = 1;
- snprintf(buff, sizeof buff, "/%d", dump_it);
- group_id = H5Gcreate(file_id, buff, 0);
- dataspace_id = H5Screate_simple(1, &oneD, NULL);
- attribute_id = H5Acreate(group_id, "Time", H5T_NATIVE_DOUBLE,
- dataspace_id, H5P_DEFAULT);
- status = H5Awrite(attribute_id, H5T_NATIVE_DOUBLE, &time);
- status = H5Aclose(attribute_id);
- status = H5Sclose(dataspace_id);
- H5Gclose(group_id);
+ CCTK_WARN(hdf5_warn_level, "Failed to write to hdf5 file");
}
- last_dump[obs] = dump_it;
+ }
+ last_dump[obs] = dump_it;
- snprintf(buff, sizeof buff, "/%d/%s", dump_it, name);
- group_id = H5Gcreate(file_id, buff, 0);
- H5Gclose(group_id);
+ snprintf(buff, sizeof buff, "/%d/%s", dump_it, name);
+ HDF5_ERROR(group_id = H5Gcreate(file_id, buff, 0));
+ HDF5_ERROR(H5Gclose(group_id));
- snprintf(buff, sizeof buff, "/%d/%s/re", dump_it, name);
- dataspace_id = H5Screate_simple(2, dims, NULL);
- dataset_id = H5Dcreate(file_id, buff, H5T_NATIVE_DOUBLE,
- dataspace_id, H5P_DEFAULT);
- status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL,
- H5S_ALL, H5P_DEFAULT, re);
- status = H5Dclose(dataset_id);
- status = H5Sclose(dataspace_id);
+ snprintf(buff, sizeof buff, "/%d/%s/re", dump_it, name);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(2, dims, NULL));
+ HDF5_ERROR(dataset_id = H5Dcreate(file_id, buff, H5T_NATIVE_DOUBLE,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL,
+ H5S_ALL, H5P_DEFAULT, re));
+ HDF5_ERROR(status = H5Dclose(dataset_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
-
- snprintf(buff, sizeof buff, "/%d/%s/im", dump_it, name);
- dataspace_id = H5Screate_simple(2, dims, NULL);
- dataset_id = H5Dcreate(file_id, buff, H5T_NATIVE_DOUBLE,
- dataspace_id, H5P_DEFAULT);
- status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL,
- H5S_ALL, H5P_DEFAULT, im);
- status = H5Dclose(dataset_id);
- status = H5Sclose(dataspace_id);
+
+ snprintf(buff, sizeof buff, "/%d/%s/im", dump_it, name);
+ HDF5_ERROR(dataspace_id = H5Screate_simple(2, dims, NULL));
+ HDF5_ERROR(dataset_id = H5Dcreate(file_id, buff, H5T_NATIVE_DOUBLE,
+ dataspace_id, H5P_DEFAULT));
+ HDF5_ERROR(status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL,
+ H5S_ALL, H5P_DEFAULT, im));
+ HDF5_ERROR(status = H5Dclose(dataset_id));
+ HDF5_ERROR(status = H5Sclose(dataspace_id));
+ HDF5_ERROR(H5Fclose(file_id));
+
+ if (error_count>0)
+ {
+ CCTK_WARN(hdf5_warn_level, "Failed to write data to hdf5 file");
}
- H5Fclose(file_id);
return 0;
}
@@ -491,18 +524,32 @@
static int last_iter = -10000;
+fprintf(stderr, "Entering Dump metric at %d\n", cctk_iteration);
+
if ((!extract_spacetime_metric_every) ||
(cctk_iteration % extract_spacetime_metric_every))
{
return;
}
const int iter = cctk_iteration / extract_spacetime_metric_every;
+fprintf(stderr, "survived first test\n");
if (iter <= last_iter)
{
return;
}
+
+fprintf(stderr, "survived second test\n");
+ if (CCTK_Equals(action_on_hdf5_error, "abort"))
+ {
+ hdf5_warn_level = CCTK_WARN_ABORT;
+ }
+ else if (CCTK_Equals(action_on_hdf5_error, "alert"))
+ {
+ hdf5_warn_level = CCTK_WARN_ALERT;
+ }
+
Decompose3D(cctkGH, "gxx", CCTK_VarIndex("ADMBase::gxx"), iter);
Decompose3D(cctkGH, "gxy", CCTK_VarIndex("ADMBase::gxy"), iter);
Decompose3D(cctkGH, "gxz", CCTK_VarIndex("ADMBase::gxz"), iter);
File [modified]: SphericalHarmonicDecomp.h
Delta lines: +3 -0
===================================================================
--- trunk/src/SphericalHarmonicDecomp.h 2012-05-28 22:22:18 UTC (rev 6)
+++ trunk/src/SphericalHarmonicDecomp.h 2012-07-30 18:57:20 UTC (rev 7)
@@ -18,4 +18,7 @@
CCTK_REAL **p_im);
}
+#ifdef USE_LEGENDRE
+# ERROR: Don't activate this option
#endif
+#endif
Directory: /trunk/
==================
File [modified]: param.ccl
Delta lines: +6 -0
===================================================================
--- trunk/param.ccl 2012-05-28 22:22:18 UTC (rev 6)
+++ trunk/param.ccl 2012-07-30 18:57:20 UTC (rev 7)
@@ -97,3 +97,9 @@
{
0:* :: "0 or positive. 0 means never"
} 0
+
+CCTK_KEYWORD action_on_hdf5_error "What to do" STEERABLE=ALWAYS
+{
+ "abort" :: "stop the run."
+ "alert" :: "only alert the user"
+} "alert"
More information about the Commits
mailing list