2017-01-27 03:34:12 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
#include "h5test.h"
|
|
|
|
#include "vds_swmr.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int file_number = -1; /* Source file number */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t fid = -1; /* HDF5 file ID */
|
|
|
|
hid_t faplid = -1; /* file access property list ID */
|
|
|
|
hid_t did = -1; /* dataset ID */
|
|
|
|
hid_t msid = -1; /* memory dataspace ID */
|
|
|
|
hid_t fsid = -1; /* file dataspace ID */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t extent[RANK]; /* dataset extents */
|
|
|
|
hsize_t start[RANK]; /* hyperslab start point */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int *buffer = NULL; /* data buffer */
|
|
|
|
int value = -1; /* value written to datasets */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t n_elements = 0; /* number of elements in a plane */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t i; /* iterator */
|
|
|
|
hsize_t j; /* iterator */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/******************************
|
|
|
|
* Fill a source dataset file *
|
|
|
|
******************************/
|
|
|
|
|
|
|
|
/* The file number is passed on the command line.
|
2020-04-21 07:12:00 +08:00
|
|
|
* This is an integer index into the FILE_NAMES array.
|
2017-01-27 03:34:12 +08:00
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
if (argc != 2) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "ERROR: Must pass the source file number on the command line.\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_number = HDatoi(argv[1]);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (file_number < 0 || file_number >= N_SOURCES)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Open the source file and dataset */
|
|
|
|
/* All SWMR files need to use the latest file format */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((faplid = h5_fileaccess()) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pset_libver_bounds(faplid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fopen(FILE_NAMES[file_number], H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, faplid)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((did = H5Dopen2(fid, SOURCE_DSET_PATH, H5P_DEFAULT)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create a data buffer that represents a plane */
|
|
|
|
n_elements = PLANES[file_number][1] * PLANES[file_number][2];
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (buffer = (int *)HDmalloc(n_elements * sizeof(int))))
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create the memory dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((msid = H5Screate_simple(RANK, PLANES[file_number], NULL)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Write planes to the dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < N_PLANES_TO_WRITE; i++) {
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
time_t delay; /* Time interval between plane writes */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Cork the dataset's metadata in the cache */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Odisable_mdc_flushes(did) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Set the dataset's extent. This is inefficient but that's ok here. */
|
|
|
|
extent[0] = i + 1;
|
|
|
|
extent[1] = PLANES[file_number][1];
|
|
|
|
extent[2] = PLANES[file_number][2];
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dset_extent(did, extent) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Get the file dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fsid = H5Dget_space(did)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Each plane is filled with the plane number as a data value. */
|
|
|
|
value = (((int)i + 1) * 10) + (int)i;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (j = 0; j < n_elements; j++)
|
|
|
|
buffer[j] = value;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Set up the hyperslab for writing. */
|
|
|
|
start[0] = i;
|
|
|
|
start[1] = 0;
|
|
|
|
start[2] = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sselect_hyperslab(fsid, H5S_SELECT_SET, start, NULL, PLANES[file_number], NULL) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Write the plane to the dataset. */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dwrite(did, H5T_NATIVE_INT, msid, fsid, H5P_DEFAULT, buffer) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Uncork the dataset's metadata from the cache */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Oenable_mdc_flushes(did) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Wait one second between writing planes */
|
2017-02-10 00:44:38 +08:00
|
|
|
delay = HDtime(0) + (time_t)1;
|
2020-09-30 22:27:10 +08:00
|
|
|
while (HDtime(0) < delay)
|
2017-01-27 03:34:12 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/* Flush */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
} /* end for */
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(faplid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(msid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(fsid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dclose(did) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(fid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfree(buffer);
|
|
|
|
|
|
|
|
HDfprintf(stderr, "SWMR writer exited successfully\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
if (fid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Fclose(fid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (faplid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Pclose(faplid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (did >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Dclose(did);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (msid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Sclose(msid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (fsid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Sclose(fsid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (buffer != NULL)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfree(buffer);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
H5E_END_TRY
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
HDfprintf(stderr, "ERROR: SWMR writer exited with errors\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
} /* end main */
|