We are integrating the HDF5 library in our .NET application.
As the HDF5 library is not thread safe we encapsulated it with the use of lock(). One thread of our program work on a single and exclusive .h5 file.
Some computations are done in parallel. For the parallel part we use :
- threads
- Parallel.foreach()
from :
- System.Threading
- System.Threading.Tasks.
Everything is working file execpt when we are executing some unit tests with NUnit v3.2.1 with thread, parallel.foreach, with a single instance of each on one single .h5 file, The final values (as they are read and written multiple times) inside our .h5 file are not correct (they are correct otherwise).
We are suspecting the HDF5 library to have an issue with the combination of all four (HDF5,NUnit,Threads,Parallel.foreach). We don't have a clear clue of what's happening.
Tools : Visual Studio 2015 Pro, NUNit v3.2.1 and NUnit3TestAdapter v3.5.1.
Any suggestions?
Thanks in advance.
Here is a sample of how we write some data inside our file :
public void SetGroupAttribute(H5LocId hdf5Handle, string location, string attribute, int value)
{
lock (AccessLock)
{
// Retrieve the attribute to read
var attributeId = GetAttribute(hdf5Handle, location, attribute);
H5GroupId rootId = null;
if (attributeId != null)
{
// Remove the old attribute
rootId = H5G.open(hdf5Handle, location);
H5A.Delete(rootId, attribute);
H5G.close(rootId);
}
// Create and set the new attribute value
H5DataSpaceId spaceId = H5S.create(H5S.H5SClass.SCALAR);
var attributeType = H5T.copy(H5T.H5Type.NATIVE_INT);
rootId = H5G.open(hdf5Handle, location);
attributeId = H5A.create(rootId, attribute, attributeType, spaceId);
H5G.close(rootId);
// Set the attribute value
int[] dims = new int[1];
dims[0] = value;
H5A.write<int>(attributeId, attributeType, new H5Array<int>(dims));
H5A.close(attributeId);
}
}