summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2006-10-28 21:11:04 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2006-10-28 21:11:04 (GMT)
commitc6c63ab6c64f4a29b3f379673e5236b2d614b422 (patch)
treedde44ec55b13d9dddad49d7d43611ef336930eb3
parent143db84d88b335730d4d785dc50380f49b007a52 (diff)
downloadhdf5-c6c63ab6c64f4a29b3f379673e5236b2d614b422.zip
hdf5-c6c63ab6c64f4a29b3f379673e5236b2d614b422.tar.gz
hdf5-c6c63ab6c64f4a29b3f379673e5236b2d614b422.tar.bz2
[svn-r12822] H5Pset_alignment seems working. Added it in test/vfd.c and made the test more complete by writing
two data sets. One is aligned, and the other isn't.
-rw-r--r--src/H5FDdirect.c7
-rw-r--r--test/h5test.c2
-rw-r--r--test/vfd.c123
3 files changed, 124 insertions, 8 deletions
diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c
index bf826aa..0daf6d9 100644
--- a/src/H5FDdirect.c
+++ b/src/H5FDdirect.c
@@ -514,7 +514,7 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd
if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL;
/* Flag for Direct I/O */
- o_flags |= O_DIRECT;
+ /*o_flags |= O_DIRECT;*/ /*change it back!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* Open the file */
if ((fd=HDopen(name, o_flags, 0666))<0)
@@ -1097,8 +1097,7 @@ H5FD_direct_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, h
alloc_size = (size / _fbsize + 1) * _fbsize + _fbsize;
else
alloc_size = _cbsize;
-/*printf("alloc_size=%ld, size=%ld, _fbsize=%ld, _cbsize=%ld\n", alloc_size, size, _fbsize,
-_cbsize);*/
+
if (posix_memalign(&copy_buf, _boundary, alloc_size) != 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "posix_memalign failed")
@@ -1147,8 +1146,6 @@ _cbsize);*/
if(size < _cbsize)
memcpy(p1, p3, size);
else if(size >= _cbsize && copy_size <= (alloc_size-(size_t)(copy_addr%_fbsize))) {
-/*printf("copy_size=%d, alloc_size=%d, size=%d, copy_addr%_fbsize=%ld\n", copy_size, alloc_size,
-size, copy_addr%_fbsize);*/
memcpy(p1, p3, copy_size);
}else if(size >= _cbsize && copy_size > (alloc_size-(size_t)(copy_addr%_fbsize))) {
memcpy(p1, p3, (alloc_size - (size_t)(copy_addr % _fbsize)));
diff --git a/test/h5test.c b/test/h5test.c
index 93f992e..840e126 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -581,7 +581,7 @@ h5_fileaccess(void)
#ifdef H5_HAVE_DIRECT
/* Linux direct read() and write() system calls. Set memory boundary, file block size,
* and copy buffer size to the default values. */
- if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0) return -1;
+ if (H5Pset_fapl_direct(fapl, 1024, 4096, 7*4096)<0) return -1;
#endif
} else {
/* Unknown driver */
diff --git a/test/vfd.c b/test/vfd.c
index 8c1fb23..fdd710d 100644
--- a/test/vfd.c
+++ b/test/vfd.c
@@ -27,9 +27,17 @@
#define FAMILY_SIZE2 (5*KB)
#define MULTI_SIZE 128
#define CORE_INCREMENT (4*KB)
+
+/*Macros for Direct VFD*/
#define MBOUNDARY 512
-#define FBSIZE 4096
-#define CBSIZE 4096
+#define FBSIZE (4*KB)
+#define CBSIZE (8*KB)
+#define THRESHOLD 1
+#define DSET1_NAME "dset1"
+#define DSET1_DIM1 1024
+#define DSET1_DIM2 32
+#define DSET2_NAME "dset2"
+#define DSET2_DIM 4
const char *FILENAME[] = {
"sec2_file",
@@ -142,12 +150,18 @@ test_direct(void)
{
#ifdef H5_HAVE_DIRECT
hid_t file=(-1), fapl, access_fapl = -1;
+ hid_t dset1=-1, dset2=-1, space1=-1, space2=-1;
char filename[1024];
int *fhandle=NULL;
hsize_t file_size;
+ hsize_t dims1[2], dims2[1];
size_t mbound;
size_t fbsize;
size_t cbsize;
+ int *points, *check, *p1, *p2;
+ int wdata2[DSET2_DIM] = {11,12,13,14};
+ int rdata2[DSET2_DIM];
+ int i, j, n;
#endif /*H5_HAVE_DIRECT*/
TESTING("Direct I/O file driver");
@@ -170,6 +184,9 @@ test_direct(void)
if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE)
TEST_ERROR;
+ if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE)<0)
+ TEST_ERROR;
+
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
TEST_ERROR;
@@ -197,8 +214,106 @@ test_direct(void)
if(file_size<1*KB || file_size>4*KB)
TEST_ERROR;
+ /* Allocate aligned memory for data set 1. For data set 1, everything is aligned including
+ * memory address, size of data, and file address. */
+ if(posix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
+ TEST_ERROR;
+
+ if(posix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
+ TEST_ERROR;
+
+ /* Initialize the dset1 */
+ p1 = points;
+ for (i = n = 0; i < DSET1_DIM1; i++)
+ for (j = 0; j < DSET1_DIM2; j++)
+ *p1++ = n++;
+
+ /* Create the data space1 */
+ dims1[0] = DSET1_DIM1;
+ dims1[1] = DSET1_DIM2;
+ if ((space1 = H5Screate_simple(2, dims1, NULL))<0)
+ TEST_ERROR;
+
+ /* Create the dset1 */
+ if ((dset1 = H5Dcreate(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT))<0)
+ TEST_ERROR;
+
+ /* Write the data to the dset1 */
+ if (H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ TEST_ERROR;
+
+ if(H5Dclose(dset1)<0)
+ TEST_ERROR;
+
+ if((dset1=H5Dopen(file, DSET1_NAME))<0)
+ TEST_ERROR;
+
+ /* Read the data back from dset1 */
+ if (H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
+ TEST_ERROR;
+
+ /* Check that the values read are the same as the values written */
+ p1 = points;
+ p2 = check;
+ for (i = 0; i < DSET1_DIM1; i++) {
+ for (j = 0; j < DSET1_DIM2; j++) {
+ if (*p1++ != *p2++) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 1.\n");
+ printf(" At index %d,%d\n", i, j);
+ TEST_ERROR;
+ }
+ }
+ }
+
+ /* Create the data space2. For data set 2, memory address and data size are not aligned. */
+ dims2[0] = DSET2_DIM;
+ if ((space2 = H5Screate_simple(1, dims2, NULL))<0)
+ TEST_ERROR;
+
+ /* Create the dset2 */
+ if ((dset2 = H5Dcreate(file, DSET2_NAME, H5T_NATIVE_INT, space2, H5P_DEFAULT))<0)
+ TEST_ERROR;
+
+ /* Write the data to the dset1 */
+ if (H5Dwrite(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata2)<0)
+ TEST_ERROR;
+
+ if(H5Dclose(dset2)<0)
+ TEST_ERROR;
+
+ if((dset2=H5Dopen(file, DSET2_NAME))<0)
+ TEST_ERROR;
+
+ /* Read the data back from dset1 */
+ if (H5Dread(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata2)<0)
+ TEST_ERROR;
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < DSET2_DIM; i++) {
+ if (wdata2[i] != rdata2[i]) {
+ H5_FAILED();
+ printf(" Read different values than written in data set 2.\n");
+ printf(" At index %d\n", i);
+ TEST_ERROR;
+ }
+ }
+
+ if(H5Sclose(space1)<0)
+ TEST_ERROR;
+ if(H5Dclose(dset1)<0)
+ TEST_ERROR;
+ if(H5Sclose(space2)<0)
+ TEST_ERROR;
+ if(H5Dclose(dset2)<0)
+ TEST_ERROR;
if(H5Fclose(file)<0)
TEST_ERROR;
+ if(points)
+ free(points);
+ if(check)
+ free(check);
+
h5_cleanup(FILENAME, fapl);
PASSED();
return 0;
@@ -206,6 +321,10 @@ test_direct(void)
error:
H5E_BEGIN_TRY {
H5Pclose (fapl);
+ H5Sclose(space1);
+ H5Dclose(dset1);
+ H5Sclose(space2);
+ H5Dclose(dset2);
H5Fclose(file);
} H5E_END_TRY;
return -1;