summaryrefslogtreecommitdiffstats
path: root/testpar/t_chunk_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'testpar/t_chunk_alloc.c')
-rw-r--r--testpar/t_chunk_alloc.c243
1 files changed, 115 insertions, 128 deletions
diff --git a/testpar/t_chunk_alloc.c b/testpar/t_chunk_alloc.c
index e716f41..8b9eb36 100644
--- a/testpar/t_chunk_alloc.c
+++ b/testpar/t_chunk_alloc.c
@@ -22,21 +22,20 @@
#include "testphdf5.h"
static int mpi_size, mpi_rank;
-#define DSET_NAME "ExtendibleArray"
-#define CHUNK_SIZE 1000 /* #elements per chunk */
-#define CHUNK_FACTOR 200 /* default dataset size in terms of chunks */
-#define CLOSE 1
-#define NO_CLOSE 0
+#define DSET_NAME "ExtendibleArray"
+#define CHUNK_SIZE 1000 /* #elements per chunk */
+#define CHUNK_FACTOR 200 /* default dataset size in terms of chunks */
+#define CLOSE 1
+#define NO_CLOSE 0
static MPI_Offset
get_filesize(const char *filename)
{
int mpierr;
- MPI_File fd;
- MPI_Offset filesize;
+ MPI_File fd;
+ MPI_Offset filesize;
- mpierr = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_RDONLY,
- MPI_INFO_NULL, &fd);
+ mpierr = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &fd);
VRFY((mpierr == MPI_SUCCESS), "");
mpierr = MPI_File_get_size(fd, &filesize);
@@ -45,21 +44,12 @@ get_filesize(const char *filename)
mpierr = MPI_File_close(&fd);
VRFY((mpierr == MPI_SUCCESS), "");
- return(filesize);
+ return (filesize);
}
-typedef enum write_pattern {
- none,
- sec_last,
- all
-} write_type;
-
-typedef enum access_ {
- write_all,
- open_only,
- extend_only
-} access_type;
+typedef enum write_pattern { none, sec_last, all } write_type;
+typedef enum access_ { write_all, open_only, extend_only } access_type;
/*
* This creates a dataset serially with chunks, each of CHUNK_SIZE
@@ -69,35 +59,35 @@ typedef enum access_ {
static void
create_chunked_dataset(const char *filename, int chunk_factor, write_type write_pattern)
{
- hid_t file_id, dataset; /* handles */
- hid_t dataspace,memspace;
- hid_t cparms;
- hsize_t dims[1];
- hsize_t maxdims[1] = {H5S_UNLIMITED};
-
- hsize_t chunk_dims[1] ={CHUNK_SIZE};
- hsize_t count[1];
- hsize_t stride[1];
- hsize_t block[1];
- hsize_t offset[1]; /* Selection offset within dataspace */
+ hid_t file_id, dataset; /* handles */
+ hid_t dataspace, memspace;
+ hid_t cparms;
+ hsize_t dims[1];
+ hsize_t maxdims[1] = {H5S_UNLIMITED};
+
+ hsize_t chunk_dims[1] = {CHUNK_SIZE};
+ hsize_t count[1];
+ hsize_t stride[1];
+ hsize_t block[1];
+ hsize_t offset[1]; /* Selection offset within dataspace */
/* Variables used in reading data back */
- char buffer[CHUNK_SIZE];
- long nchunks;
- herr_t hrc;
+ char buffer[CHUNK_SIZE];
+ long nchunks;
+ herr_t hrc;
- MPI_Offset filesize, /* actual file size */
- est_filesize; /* estimated file size */
+ MPI_Offset filesize, /* actual file size */
+ est_filesize; /* estimated file size */
/* set up MPI parameters */
- MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
/* Only MAINPROCESS should create the file. Others just wait. */
- if (MAINPROCESS){
- nchunks=chunk_factor*mpi_size;
- dims[0]=(hsize_t)(nchunks*CHUNK_SIZE);
+ if (MAINPROCESS) {
+ nchunks = chunk_factor * mpi_size;
+ dims[0] = (hsize_t)(nchunks * CHUNK_SIZE);
/* Create the data space with unlimited dimensions. */
- dataspace = H5Screate_simple (1, dims, maxdims);
+ dataspace = H5Screate_simple(1, dims, maxdims);
VRFY((dataspace >= 0), "");
memspace = H5Screate_simple(1, chunk_dims, NULL);
@@ -118,19 +108,20 @@ create_chunked_dataset(const char *filename, int chunk_factor, write_type write_
VRFY((hrc >= 0), "");
/* Create a new dataset within the file using cparms creation properties. */
- dataset = H5Dcreate2(file_id, DSET_NAME, H5T_NATIVE_UCHAR, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
+ dataset =
+ H5Dcreate2(file_id, DSET_NAME, H5T_NATIVE_UCHAR, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
VRFY((dataset >= 0), "");
- if(write_pattern == sec_last) {
+ if (write_pattern == sec_last) {
HDmemset(buffer, 100, CHUNK_SIZE);
- count[0] = 1;
+ count[0] = 1;
stride[0] = 1;
- block[0] = chunk_dims[0];
- offset[0] = (hsize_t)(nchunks-2)*chunk_dims[0];
+ block[0] = chunk_dims[0];
+ offset[0] = (hsize_t)(nchunks - 2) * chunk_dims[0];
hrc = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, stride, count, block);
- VRFY((hrc >= 0), "");
+ VRFY((hrc >= 0), "");
/* Write sec_last chunk */
hrc = H5Dwrite(dataset, H5T_NATIVE_UCHAR, memspace, dataspace, H5P_DEFAULT, buffer);
@@ -138,28 +129,27 @@ create_chunked_dataset(const char *filename, int chunk_factor, write_type write_
} /* end if */
/* Close resources */
- hrc = H5Dclose (dataset);
+ hrc = H5Dclose(dataset);
VRFY((hrc >= 0), "");
dataset = -1;
- hrc = H5Sclose (dataspace);
+ hrc = H5Sclose(dataspace);
VRFY((hrc >= 0), "");
- hrc = H5Sclose (memspace);
+ hrc = H5Sclose(memspace);
VRFY((hrc >= 0), "");
- hrc = H5Pclose (cparms);
+ hrc = H5Pclose(cparms);
VRFY((hrc >= 0), "");
- hrc = H5Fclose (file_id);
+ hrc = H5Fclose(file_id);
VRFY((hrc >= 0), "");
file_id = -1;
/* verify file size */
- filesize = get_filesize(filename);
+ filesize = get_filesize(filename);
est_filesize = (MPI_Offset)nchunks * (MPI_Offset)CHUNK_SIZE * (MPI_Offset)sizeof(unsigned char);
VRFY((filesize >= est_filesize), "file size check");
-
}
/* Make sure all processes are done before exiting this routine. Otherwise,
@@ -170,7 +160,6 @@ create_chunked_dataset(const char *filename, int chunk_factor, write_type write_
MPI_Barrier(MPI_COMM_WORLD);
}
-
/*
* This program performs three different types of parallel access. It writes on
* the entire dataset, it extends the dataset to nchunks*CHUNK_SIZE, and it only
@@ -178,51 +167,52 @@ create_chunked_dataset(const char *filename, int chunk_factor, write_type write_
* consistent with argument 'chunk_factor'.
*/
static void
-parallel_access_dataset(const char *filename, int chunk_factor, access_type action, hid_t *file_id, hid_t *dataset)
+parallel_access_dataset(const char *filename, int chunk_factor, access_type action, hid_t *file_id,
+ hid_t *dataset)
{
/* HDF5 gubbins */
- hid_t memspace, dataspace; /* HDF5 file identifier */
- hid_t access_plist; /* HDF5 ID for file access property list */
- herr_t hrc; /* HDF5 return code */
- hsize_t size[1];
-
- hsize_t chunk_dims[1] ={CHUNK_SIZE};
- hsize_t count[1];
- hsize_t stride[1];
- hsize_t block[1];
- hsize_t offset[1]; /* Selection offset within dataspace */
- hsize_t dims[1];
- hsize_t maxdims[1];
+ hid_t memspace, dataspace; /* HDF5 file identifier */
+ hid_t access_plist; /* HDF5 ID for file access property list */
+ herr_t hrc; /* HDF5 return code */
+ hsize_t size[1];
+
+ hsize_t chunk_dims[1] = {CHUNK_SIZE};
+ hsize_t count[1];
+ hsize_t stride[1];
+ hsize_t block[1];
+ hsize_t offset[1]; /* Selection offset within dataspace */
+ hsize_t dims[1];
+ hsize_t maxdims[1];
/* Variables used in reading data back */
- char buffer[CHUNK_SIZE];
- int i;
- long nchunks;
+ char buffer[CHUNK_SIZE];
+ int i;
+ long nchunks;
/* MPI Gubbins */
- MPI_Offset filesize, /* actual file size */
- est_filesize; /* estimated file size */
+ MPI_Offset filesize, /* actual file size */
+ est_filesize; /* estimated file size */
/* Initialize MPI */
- MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
- nchunks=chunk_factor*mpi_size;
+ nchunks = chunk_factor * mpi_size;
/* Set up MPIO file access property lists */
- access_plist = H5Pcreate(H5P_FILE_ACCESS);
+ access_plist = H5Pcreate(H5P_FILE_ACCESS);
VRFY((access_plist >= 0), "");
hrc = H5Pset_fapl_mpio(access_plist, MPI_COMM_WORLD, MPI_INFO_NULL);
VRFY((hrc >= 0), "");
/* Open the file */
- if (*file_id<0){
+ if (*file_id < 0) {
*file_id = H5Fopen(filename, H5F_ACC_RDWR, access_plist);
VRFY((*file_id >= 0), "");
}
/* Open dataset*/
- if (*dataset<0){
+ if (*dataset < 0) {
*dataset = H5Dopen2(*file_id, DSET_NAME, H5P_DEFAULT);
VRFY((*dataset >= 0), "");
}
@@ -233,19 +223,19 @@ parallel_access_dataset(const char *filename, int chunk_factor, access_type acti
dataspace = H5Dget_space(*dataset);
VRFY((dataspace >= 0), "");
- size[0] = (hsize_t)nchunks*CHUNK_SIZE;
+ size[0] = (hsize_t)nchunks * CHUNK_SIZE;
switch (action) {
/* all chunks are written by all the processes in an interleaved way*/
case write_all:
- HDmemset(buffer, mpi_rank+1, CHUNK_SIZE);
- count[0] = 1;
+ HDmemset(buffer, mpi_rank + 1, CHUNK_SIZE);
+ count[0] = 1;
stride[0] = 1;
- block[0] = chunk_dims[0];
- for (i=0; i<nchunks/mpi_size; i++) {
- offset[0] = (hsize_t)(i*mpi_size+mpi_rank)*chunk_dims[0];
+ block[0] = chunk_dims[0];
+ for (i = 0; i < nchunks / mpi_size; i++) {
+ offset[0] = (hsize_t)(i * mpi_size + mpi_rank) * chunk_dims[0];
hrc = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, stride, count, block);
VRFY((hrc >= 0), "");
@@ -282,10 +272,10 @@ parallel_access_dataset(const char *filename, int chunk_factor, access_type acti
VRFY((hrc >= 0), "");
*dataset = -1;
- hrc = H5Sclose (dataspace);
+ hrc = H5Sclose(dataspace);
VRFY((hrc >= 0), "");
- hrc = H5Sclose (memspace);
+ hrc = H5Sclose(memspace);
VRFY((hrc >= 0), "");
hrc = H5Fclose(*file_id);
@@ -293,8 +283,8 @@ parallel_access_dataset(const char *filename, int chunk_factor, access_type acti
*file_id = -1;
/* verify file size */
- filesize = get_filesize(filename);
- est_filesize = (MPI_Offset)nchunks*(MPI_Offset)CHUNK_SIZE*(MPI_Offset)sizeof(unsigned char);
+ filesize = get_filesize(filename);
+ est_filesize = (MPI_Offset)nchunks * (MPI_Offset)CHUNK_SIZE * (MPI_Offset)sizeof(unsigned char);
VRFY((filesize >= est_filesize), "file size check");
/* Can close some plists */
@@ -317,45 +307,45 @@ parallel_access_dataset(const char *filename, int chunk_factor, access_type acti
* interleaved pattern.
*/
static void
-verify_data(const char *filename, int chunk_factor, write_type write_pattern, int vclose,
- hid_t *file_id, hid_t *dataset)
+verify_data(const char *filename, int chunk_factor, write_type write_pattern, int vclose, hid_t *file_id,
+ hid_t *dataset)
{
/* HDF5 gubbins */
- hid_t dataspace, memspace; /* HDF5 file identifier */
- hid_t access_plist; /* HDF5 ID for file access property list */
- herr_t hrc; /* HDF5 return code */
-
- hsize_t chunk_dims[1] ={CHUNK_SIZE};
- hsize_t count[1];
- hsize_t stride[1];
- hsize_t block[1];
- hsize_t offset[1]; /* Selection offset within dataspace */
+ hid_t dataspace, memspace; /* HDF5 file identifier */
+ hid_t access_plist; /* HDF5 ID for file access property list */
+ herr_t hrc; /* HDF5 return code */
+
+ hsize_t chunk_dims[1] = {CHUNK_SIZE};
+ hsize_t count[1];
+ hsize_t stride[1];
+ hsize_t block[1];
+ hsize_t offset[1]; /* Selection offset within dataspace */
/* Variables used in reading data back */
- char buffer[CHUNK_SIZE];
- int value, i;
- int index_l;
- long nchunks;
+ char buffer[CHUNK_SIZE];
+ int value, i;
+ int index_l;
+ long nchunks;
/* Initialize MPI */
- MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
- nchunks=chunk_factor*mpi_size;
+ nchunks = chunk_factor * mpi_size;
/* Set up MPIO file access property lists */
- access_plist = H5Pcreate(H5P_FILE_ACCESS);
+ access_plist = H5Pcreate(H5P_FILE_ACCESS);
VRFY((access_plist >= 0), "");
hrc = H5Pset_fapl_mpio(access_plist, MPI_COMM_WORLD, MPI_INFO_NULL);
VRFY((hrc >= 0), "");
/* Open the file */
- if (*file_id<0){
+ if (*file_id < 0) {
*file_id = H5Fopen(filename, H5F_ACC_RDWR, access_plist);
VRFY((*file_id >= 0), "");
}
/* Open dataset*/
- if (*dataset<0){
+ if (*dataset < 0) {
*dataset = H5Dopen2(*file_id, DSET_NAME, H5P_DEFAULT);
VRFY((*dataset >= 0), "");
}
@@ -367,14 +357,14 @@ verify_data(const char *filename, int chunk_factor, write_type write_pattern, in
VRFY((dataspace >= 0), "");
/* all processes check all chunks. */
- count[0] = 1;
+ count[0] = 1;
stride[0] = 1;
- block[0] = chunk_dims[0];
- for (i=0; i<nchunks; i++){
+ block[0] = chunk_dims[0];
+ for (i = 0; i < nchunks; i++) {
/* reset buffer values */
HDmemset(buffer, -1, CHUNK_SIZE);
- offset[0] = (hsize_t)i*chunk_dims[0];
+ offset[0] = (hsize_t)i * chunk_dims[0];
hrc = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, stride, count, block);
VRFY((hrc >= 0), "");
@@ -386,13 +376,13 @@ verify_data(const char *filename, int chunk_factor, write_type write_pattern, in
/* set expected value according the write pattern */
switch (write_pattern) {
case all:
- value = i%mpi_size + 1;
+ value = i % mpi_size + 1;
break;
case none:
value = 0;
break;
case sec_last:
- if (i==nchunks-2)
+ if (i == nchunks - 2)
value = 100;
else
value = 0;
@@ -406,10 +396,10 @@ verify_data(const char *filename, int chunk_factor, write_type write_pattern, in
VRFY((buffer[index_l] == value), "data verification");
}
- hrc = H5Sclose (dataspace);
+ hrc = H5Sclose(dataspace);
VRFY((hrc >= 0), "");
- hrc = H5Sclose (memspace);
+ hrc = H5Sclose(memspace);
VRFY((hrc >= 0), "");
/* Can close some plists */
@@ -417,7 +407,7 @@ verify_data(const char *filename, int chunk_factor, write_type write_pattern, in
VRFY((hrc >= 0), "");
/* Close up */
- if (vclose){
+ if (vclose) {
hrc = H5Dclose(*dataset);
VRFY((hrc >= 0), "");
*dataset = -1;
@@ -434,8 +424,6 @@ verify_data(const char *filename, int chunk_factor, write_type write_pattern, in
MPI_Barrier(MPI_COMM_WORLD);
}
-
-
/*
* Test following possible scenarios,
* Case 1:
@@ -458,15 +446,15 @@ void
test_chunk_alloc(void)
{
const char *filename;
- hid_t file_id, dataset;
+ hid_t file_id, dataset;
file_id = dataset = -1;
/* Initialize MPI */
- MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
- filename = (const char*)GetTestParameters();
+ filename = (const char *)GetTestParameters();
if (VERBOSE_MED)
HDprintf("Extend Chunked allocation test on file %s\n", filename);
@@ -495,5 +483,4 @@ test_chunk_alloc(void)
parallel_access_dataset(filename, CHUNK_FACTOR, write_all, &file_id, &dataset);
/* reopen dataset in parallel, read and verify the data */
verify_data(filename, CHUNK_FACTOR, all, CLOSE, &file_id, &dataset);
-
}