[MOAB-dev] r2014 - in MOAB/trunk: m4 mhdf/src

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue Jul 15 15:26:12 CDT 2008


Author: kraftche
Date: 2008-07-15 15:26:12 -0500 (Tue, 15 Jul 2008)
New Revision: 2014

Modified:
   MOAB/trunk/m4/compiler.m4
   MOAB/trunk/mhdf/src/util.c
Log:
Make it easier to debug HDF5 writer with valgrind.  Because the HDF5 library
caches data to be written later (often on close) it is difficult to determine
where uninitialized data originated from.  Further, because WriteHDF5 re-uses
the same buffer for most large IO, valgrind does not detect writes of 
uninitialized data because it sees the data as being initialized to whatever
values were previously written.

When building with --enable-debug and the valgrind/memcheck.h header is
present, wrap calls to H5Dwrite with calls to notify valgrind that data
must be initialized before entering HDF5write and that the data should
be treated as uninitialized after leaving the HDF5write call.  Valgrind
calls have no effect if code is not running inside of valgrind.



Modified: MOAB/trunk/m4/compiler.m4
===================================================================
--- MOAB/trunk/m4/compiler.m4	2008-07-15 17:27:56 UTC (rev 2013)
+++ MOAB/trunk/m4/compiler.m4	2008-07-15 20:26:12 UTC (rev 2014)
@@ -148,6 +148,7 @@
   CXXFLAGS="$CXXFLAGS -g"
   CFLAGS="$CFLAGS -g"
   FCFLAGS="$FCFLAGS -g"
+  AC_CHECK_HEADER( [valgrind/memcheck.h], [CXXFLAGS="$CXXFLAGS -DVALGRIND"] )
 fi
 if test "xyes" = "x$enable_cxx_optimize"; then
   CXXFLAGS="$CXXFLAGS -O2 -DNDEBUG"

Modified: MOAB/trunk/mhdf/src/util.c
===================================================================
--- MOAB/trunk/mhdf/src/util.c	2008-07-15 17:27:56 UTC (rev 2013)
+++ MOAB/trunk/mhdf/src/util.c	2008-07-15 20:26:12 UTC (rev 2014)
@@ -22,6 +22,13 @@
 #include "status.h"
 #include "names-and-paths.h"
 
+#ifdef VALGRIND
+#  include <valgrind/memcheck.h>
+#else
+#  define VALGRIND_CHECK_MEM_IS_DEFINED(A,B)
+#  define VALGRIND_MAKE_MEM_UNDEFINED(A,B)
+#endif
+
 void* mhdf_malloc( size_t size, mhdf_Status* status )
 {
   void* result;
@@ -184,7 +191,8 @@
     mhdf_setFail( status, "Failed to create \"%s\" attrib.", name );
     return 0;
   }
-  
+
+  VALGRIND_CHECK_MEM_IS_DEFINED( value, H5Tget_size(type) );
   rval = H5Awrite( attr_id, type, value );
   H5Aclose( attr_id );
   if (rval < 0)
@@ -233,7 +241,7 @@
     H5Tclose( type_id );
   if (rval < 0)
   {
-    mhdf_setFail( status, "Failed to write \"%s\" attrib.", name );
+    mhdf_setFail( status, "Failed to read \"%s\" attrib.", name );
     return 0;
   }
   
@@ -355,8 +363,11 @@
   
   if (read)
     rval = H5Dread( data_id, type, mem_id, slab_id, io_prop, array );
-  else
+  else {
+    VALGRIND_CHECK_MEM_IS_DEFINED( array, counts[0]*counts[1]*H5Tget_size(type) );
     rval = H5Dwrite( data_id, type, mem_id, slab_id, io_prop, array );
+    VALGRIND_MAKE_MEM_UNDEFINED( array, counts[0]*counts[1]*H5Tget_size(type) );
+  }
   H5Sclose( slab_id );
   H5Sclose( mem_id );
   if (rval < 0)
@@ -449,8 +460,11 @@
   
   if (read)
     rval = H5Dread( data_id, type, mem_id, slab_id, io_prop, array );
-  else
+  else {
+    VALGRIND_CHECK_MEM_IS_DEFINED( array, count*H5Tget_size(type) );
     rval = H5Dwrite( data_id, type, mem_id, slab_id, io_prop, array );
+    VALGRIND_MAKE_MEM_UNDEFINED( array, count*H5Tget_size(type) );
+  }
   H5Sclose( slab_id );
   H5Sclose( mem_id );
   if (rval < 0)




More information about the moab-dev mailing list