summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2018-10-19 18:48:02 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2018-10-19 18:48:02 (GMT)
commit934ef8bec040f05a2e1700bda40159deb9c4cb5e (patch)
tree93bdaacb6f565a577587f78ff4debcd7f9bc928a /examples
parent4e575a086553a23fc79d3e92f48eb9508711e6ca (diff)
downloadhdf5-934ef8bec040f05a2e1700bda40159deb9c4cb5e.zip
hdf5-934ef8bec040f05a2e1700bda40159deb9c4cb5e.tar.gz
hdf5-934ef8bec040f05a2e1700bda40159deb9c4cb5e.tar.bz2
Added RADOS files (not wired up yet)
Diffstat (limited to 'examples')
-rw-r--r--examples/h5rados_dset_create.c84
-rw-r--r--examples/h5rados_dset_open.c126
-rw-r--r--examples/h5rados_dset_read.c86
-rw-r--r--examples/h5rados_dset_rpartial.c142
-rw-r--r--examples/h5rados_dset_rss.c134
-rw-r--r--examples/h5rados_dset_wpartial.c129
-rw-r--r--examples/h5rados_dset_write.c81
-rw-r--r--examples/h5rados_dset_wss.c135
-rw-r--r--examples/h5rados_example.h14
-rw-r--r--examples/h5rados_file_create.c54
-rw-r--r--examples/h5rados_file_open.c54
-rw-r--r--examples/h5rados_group_create.c63
-rw-r--r--examples/h5rados_group_open.c63
13 files changed, 1165 insertions, 0 deletions
diff --git a/examples/h5rados_dset_create.c b/examples/h5rados_dset_create.c
new file mode 100644
index 0000000..0e14a7f
--- /dev/null
+++ b/examples/h5rados_dset_create.c
@@ -0,0 +1,84 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, space = -1, fapl = -1, dcpl = H5P_DEFAULT;
+ hsize_t dims[2] = {4, 6};
+ hsize_t cdims[2];
+
+ (void)MPI_Init(&argc, &argv);
+
+ if((argc != 3) && (argc != 5))
+ PRINTF_ERROR("argc is not 3 or 5\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Set up DCPL */
+ if(argc == 5) {
+ cdims[0] = (hsize_t)atoi(argv[3]);
+ cdims[1] = (hsize_t)atoi(argv[4]);
+ if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ ERROR;
+ if(H5Pset_chunk(dcpl, 2, cdims) < 0)
+ ERROR;
+ } /* end if */
+
+ /* Set up dataspace */
+ if((space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ printf("Creating dataset\n");
+
+ /* Create dataset */
+ if((dset = H5Dcreate2(file, argv[2], H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Sclose(space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+ if((dcpl != H5P_DEFAULT) && (H5Pclose(dcpl) < 0))
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Sclose(space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_open.c b/examples/h5rados_dset_open.c
new file mode 100644
index 0000000..19e29ed
--- /dev/null
+++ b/examples/h5rados_dset_open.c
@@ -0,0 +1,126 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, fapl = -1, space = -1, type = -1, dcpl = -1, dapl = -1, def_dcpl = -1, def_dapl = -1;
+ int ndims;
+ hsize_t dims[2];
+ htri_t tri_ret;
+
+ (void)MPI_Init(&argc, &argv);
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0)
+ ERROR;
+
+ printf("Opening dataset\n");
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Check dataset dataspace */
+ if((space = H5Dget_space(dset)) < 0)
+ ERROR;
+ if((ndims = H5Sget_simple_extent_ndims(space)) < 0)
+ ERROR;
+ if(ndims != 2)
+ PRINTF_ERROR("ndims == %d, expected 2\n", ndims);
+ if(H5Sget_simple_extent_dims(space, dims, NULL) < 0)
+ ERROR;
+ if(dims[0] != 4)
+ PRINTF_ERROR("dims[0] == %d, expected 4\n", (int)dims[0]);
+ if(dims[1] != 6)
+ PRINTF_ERROR("dims[1] == %d, expected 6\n", (int)dims[1]);
+
+ /* Check dataset datatype */
+ if((type = H5Dget_type(dset)) < 0)
+ ERROR;
+ if((tri_ret = H5Tequal(type, H5T_NATIVE_INT)) < 0)
+ ERROR;
+ if(!tri_ret)
+ PRINTF_ERROR("datatype does not equal H5T_NATIVE_INT\n");
+
+ /* Check DCPL */
+ if((dcpl = H5Dget_create_plist(dset)) < 0)
+ ERROR;
+ if((def_dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ ERROR;
+ if((tri_ret = H5Pequal(dcpl, def_dcpl)) < 0)
+ ERROR;
+ if(!tri_ret)
+ PRINTF_ERROR("DCPL does not equal default\n");
+
+ /* Check DAPL */
+ if((dapl = H5Dget_access_plist(dset)) < 0)
+ ERROR;
+ if((def_dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
+ ERROR;
+ if((tri_ret = H5Pequal(dapl, def_dapl)) < 0)
+ ERROR;
+ if(!tri_ret)
+ PRINTF_ERROR("DAPL does not equal default\n");
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+ if(H5Sclose(space) < 0)
+ ERROR;
+ if(H5Tclose(type) < 0)
+ ERROR;
+ if(H5Pclose(dcpl) < 0)
+ ERROR;
+ if(H5Pclose(dapl) < 0)
+ ERROR;
+ if(H5Pclose(def_dcpl) < 0)
+ ERROR;
+ if(H5Pclose(def_dapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Pclose(fapl);
+ H5Sclose(space);
+ H5Tclose(type);
+ H5Pclose(dcpl);
+ H5Pclose(dapl);
+ H5Pclose(def_dcpl);
+ H5Pclose(def_dapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_read.c b/examples/h5rados_dset_read.c
new file mode 100644
index 0000000..fc7292c
--- /dev/null
+++ b/examples/h5rados_dset_read.c
@@ -0,0 +1,86 @@
+#include "h5rados_example.h"
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, fapl = -1;
+ int buf[4][6];
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ printf("Reading dataset\n");
+
+ /* Initialize buffer */
+ for(i = 0; i < 4; i++)
+ for(j = 0; j < 6; j++)
+ buf[i][j] = -1;
+
+ /* Read data */
+ if(H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ /* Print buffer */
+ printf("Successfully read data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++)
+ printf("%d ", buf[i][j]);
+ printf("\n");
+ }
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_rpartial.c b/examples/h5rados_dset_rpartial.c
new file mode 100644
index 0000000..622b961
--- /dev/null
+++ b/examples/h5rados_dset_rpartial.c
@@ -0,0 +1,142 @@
+#include "h5rados_example.h"
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, file_space = -1, mem_space = -1, fapl = -1;
+ hsize_t dims[2] = {4, 6};
+ hsize_t start[2], count[2];
+ int buf[4][6];
+ int rank, mpi_size;
+ char *file_sel_str[2] = {"XXX...", "...XXX"};
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+ MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+
+ if(mpi_size > 2)
+ PRINTF_ERROR("mpi_size > 2\n");
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ if(rank == 1)
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ printf("---------------Rank %d---------------\n", rank);
+ printf("Selecting elements denoted with X\n");
+ printf("Memory File\n");
+ printf("...... %s\n", file_sel_str[rank]);
+ for(i = 1; i < 4; i++)
+ printf(".XXXX. %s\n", file_sel_str[rank]);
+
+ if(rank == 0)
+ MPI_Barrier(MPI_COMM_WORLD);
+ else
+ printf("Reading dataset\n");
+
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ /* Set up dataspaces */
+ if((file_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if((mem_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ start[0] = 0;
+ start[1] = 3 * rank;
+ count[0] = 4;
+ count[1] = 3;
+ if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
+ ERROR;
+ start[0] = 1;
+ start[1] = 1;
+ count[0] = 3;
+ count[1] = 4;
+ if(H5Sselect_hyperslab(mem_space, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
+ ERROR;
+
+ /* Initialize buffer */
+ for(i = 0; i < 4; i++)
+ for(j = 0; j < 6; j++)
+ buf[i][j] = -1;
+
+ /* Read data */
+ if(H5Dread(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ if(rank == 1)
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ /* Fill and print buffer */
+ printf("---------------Rank %d---------------\n", rank);
+ printf("Successfully read data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++)
+ printf("%d ", buf[i][j]);
+ printf("\n");
+ }
+
+ if(rank == 0)
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Sclose(file_space) < 0)
+ ERROR;
+ if(H5Sclose(mem_space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Sclose(file_space);
+ H5Sclose(mem_space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_rss.c b/examples/h5rados_dset_rss.c
new file mode 100644
index 0000000..456da0c
--- /dev/null
+++ b/examples/h5rados_dset_rss.c
@@ -0,0 +1,134 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, file_space = -1, mem_space = -1, fapl = -1;
+ hsize_t dims[2] = {4, 6};
+ hsize_t fstart[2], count[2], mstart[2];
+ int buf[4][6];
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+
+ if(argc != 9)
+ PRINTF_ERROR("argc != 9\n");
+
+ fstart[0] = (hsize_t)atoi(argv[3]);
+ fstart[1] = (hsize_t)atoi(argv[4]);
+ count[0] = (hsize_t)atoi(argv[5]);
+ count[1] = (hsize_t)atoi(argv[6]);
+ mstart[0] = (hsize_t)atoi(argv[7]);
+ mstart[1] = (hsize_t)atoi(argv[8]);
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ printf("Selecting elements denoted with X\n");
+ printf("File:\n");
+ for(i = 0; i < 4; i++) {
+ if((i >= fstart[0]) && (i < fstart[0] + count[0])) {
+ for(j = 0; j < 6; j++)
+ if((j >= fstart[1]) && (j < fstart[1] + count[1]))
+ printf("X");
+ else
+ printf(".");
+ printf("\n");
+ }
+ else
+ printf("......\n");
+ }
+ printf("\nMemory:\n");
+ for(i = 0; i < 4; i++) {
+ if((i >= mstart[0]) && (i < mstart[0] + count[0])) {
+ for(j = 0; j < 6; j++)
+ if((j >= mstart[1]) && (j < mstart[1] + count[1]))
+ printf("X");
+ else
+ printf(".");
+ printf("\n");
+ }
+ else
+ printf("......\n");
+ }
+
+ /* Set up dataspaces */
+ if((file_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if((mem_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, fstart, NULL, count, NULL) < 0)
+ ERROR;
+ if(H5Sselect_hyperslab(mem_space, H5S_SELECT_SET, mstart, NULL, count, NULL) < 0)
+ ERROR;
+
+ /* Initialize buffer */
+ for(i = 0; i < 4; i++)
+ for(j = 0; j < 6; j++)
+ buf[i][j] = -1;
+
+ /* Read data */
+ if(H5Dread(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ /* Fill and print buffer */
+ printf("Successfully read data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++)
+ printf("%d ", buf[i][j]);
+ printf("\n");
+ }
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Sclose(file_space) < 0)
+ ERROR;
+ if(H5Sclose(mem_space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Sclose(file_space);
+ H5Sclose(mem_space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_wpartial.c b/examples/h5rados_dset_wpartial.c
new file mode 100644
index 0000000..bb53982
--- /dev/null
+++ b/examples/h5rados_dset_wpartial.c
@@ -0,0 +1,129 @@
+#include "h5rados_example.h"
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, file_space = -1, mem_space = -1, fapl = -1;
+ hsize_t dims[2] = {4, 6};
+ hsize_t start[2], count[2];
+ int buf[4][6];
+ int rank, mpi_size;
+ char *file_sel_str[2] = {"XXX...", "...XXX"};
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+ MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+
+ if(mpi_size != 2)
+ PRINTF_ERROR("mpi_size != 2\n");
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ if(rank == 1)
+ MPI_Barrier(MPI_COMM_WORLD);
+
+ printf("---------------Rank %d---------------\n", rank);
+ printf("Selecting elements denoted with X\n");
+ printf("Memory File\n");
+ printf("...... %s\n", file_sel_str[rank]);
+ for(i = 1; i < 4; i++)
+ printf(".XXXX. %s\n", file_sel_str[rank]);
+
+ /* Fill and print buffer */
+ printf("Writing data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++) {
+ buf[i][j] = rand() % 10;
+ printf("%d ", buf[i][j]);
+ }
+ printf("\n");
+ }
+
+ if(rank == 0)
+ MPI_Barrier(MPI_COMM_WORLD);
+
+
+ /* Set up dataspaces */
+ if((file_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if((mem_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ start[0] = 0;
+ start[1] = 3 * rank;
+ count[0] = 4;
+ count[1] = 3;
+ if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
+ ERROR;
+ start[0] = 1;
+ start[1] = 1;
+ count[0] = 3;
+ count[1] = 4;
+ if(H5Sselect_hyperslab(mem_space, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
+ ERROR;
+
+ /* Write data */
+ if(H5Dwrite(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Sclose(file_space) < 0)
+ ERROR;
+ if(H5Sclose(mem_space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Sclose(file_space);
+ H5Sclose(mem_space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_write.c b/examples/h5rados_dset_write.c
new file mode 100644
index 0000000..dad96fa
--- /dev/null
+++ b/examples/h5rados_dset_write.c
@@ -0,0 +1,81 @@
+#include "h5rados_example.h"
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, fapl = -1;
+ int buf[4][6];
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Fill and print buffer */
+ printf("Writing data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++) {
+ buf[i][j] = rand() % 10;
+ printf("%d ", buf[i][j]);
+ }
+ printf("\n");
+ }
+
+ /* Write data */
+ if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_dset_wss.c b/examples/h5rados_dset_wss.c
new file mode 100644
index 0000000..cefc1ed
--- /dev/null
+++ b/examples/h5rados_dset_wss.c
@@ -0,0 +1,135 @@
+#include "h5rados_example.h"
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, dset = -1, file_space = -1, mem_space = -1, fapl = -1;
+ hsize_t dims[2] = {4, 6};
+ hsize_t mstart[2], count[2], fstart[2];
+ int buf[4][6];
+ int i, j;
+
+ (void)MPI_Init(&argc, &argv);
+
+ /* Seed random number generator */
+ srand(time(NULL));
+
+ if(argc != 9)
+ PRINTF_ERROR("argc != 9\n");
+
+ mstart[0] = (hsize_t)atoi(argv[3]);
+ mstart[1] = (hsize_t)atoi(argv[4]);
+ count[0] = (hsize_t)atoi(argv[5]);
+ count[1] = (hsize_t)atoi(argv[6]);
+ fstart[0] = (hsize_t)atoi(argv[7]);
+ fstart[1] = (hsize_t)atoi(argv[8]);
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ /* Open dataset */
+ if((dset = H5Dopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ printf("Selecting elements denoted with X\n");
+ printf("Memory:\n");
+ for(i = 0; i < 4; i++) {
+ if((i >= mstart[0]) && (i < mstart[0] + count[0])) {
+ for(j = 0; j < 6; j++)
+ if((j >= mstart[1]) && (j < mstart[1] + count[1]))
+ printf("X");
+ else
+ printf(".");
+ printf("\n");
+ }
+ else
+ printf("......\n");
+ }
+ printf("\nFile:\n");
+ for(i = 0; i < 4; i++) {
+ if((i >= fstart[0]) && (i < fstart[0] + count[0])) {
+ for(j = 0; j < 6; j++)
+ if((j >= fstart[1]) && (j < fstart[1] + count[1]))
+ printf("X");
+ else
+ printf(".");
+ printf("\n");
+ }
+ else
+ printf("......\n");
+ }
+
+ /* Fill and print buffer */
+ printf("Writing data. Buffer is:\n");
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 6; j++) {
+ buf[i][j] = rand() % 10;
+ printf("%d ", buf[i][j]);
+ }
+ printf("\n");
+ }
+
+
+ /* Set up dataspaces */
+ if((file_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if((mem_space = H5Screate_simple(2, dims, NULL)) < 0)
+ ERROR;
+ if(H5Sselect_hyperslab(file_space, H5S_SELECT_SET, fstart, NULL, count, NULL) < 0)
+ ERROR;
+ if(H5Sselect_hyperslab(mem_space, H5S_SELECT_SET, mstart, NULL, count, NULL) < 0)
+ ERROR;
+
+ /* Write data */
+ if(H5Dwrite(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Dclose(dset) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Sclose(file_space) < 0)
+ ERROR;
+ if(H5Sclose(mem_space) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Dclose(dset);
+ H5Fclose(file);
+ H5Sclose(file_space);
+ H5Sclose(mem_space);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_example.h b/examples/h5rados_example.h
new file mode 100644
index 0000000..4516b15
--- /dev/null
+++ b/examples/h5rados_example.h
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <mpi.h>
+#include <hdf5.h>
+#include <rados/librados.h>
+#include <H5VLrados_public.h>
+
+/* Macros for printing standard messages and issuing errors */
+#define AT() printf (" at %s:%d in %s()...\n", __FILE__, __LINE__, __FUNCTION__)
+#define FAILED() do {puts("*FAILED*");fflush(stdout);} while(0)
+#define ERROR do {FAILED(); AT(); goto error;} while(0)
+#define PRINTF_ERROR(...) do {FAILED(); AT(); printf(" " __VA_ARGS__); printf("\n"); goto error;} while(0)
+
diff --git a/examples/h5rados_file_create.c b/examples/h5rados_file_create.c
new file mode 100644
index 0000000..493be18
--- /dev/null
+++ b/examples/h5rados_file_create.c
@@ -0,0 +1,54 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, fapl = -1;
+
+ (void)MPI_Init(&argc, &argv);
+
+ if(argc != 2)
+ PRINTF_ERROR("argc != 2\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Create file */
+ if((file = H5Fcreate(argv[1], H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_file_open.c b/examples/h5rados_file_open.c
new file mode 100644
index 0000000..176d26e
--- /dev/null
+++ b/examples/h5rados_file_open.c
@@ -0,0 +1,54 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, fapl = -1;
+
+ (void)MPI_Init(&argc, &argv);
+
+ if(argc != 2)
+ PRINTF_ERROR("argc != 2\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Create file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_group_create.c b/examples/h5rados_group_create.c
new file mode 100644
index 0000000..fcfbbc0
--- /dev/null
+++ b/examples/h5rados_group_create.c
@@ -0,0 +1,63 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, fapl = -1, grp = -1;
+
+ (void)MPI_Init(&argc, &argv);
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* OPEN file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDWR, fapl)) < 0)
+ ERROR;
+
+ printf("Creating group\n");
+
+ /* Create group */
+ if((grp = H5Gcreate2(file, argv[2], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Gclose(grp) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Gclose(grp);
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+
diff --git a/examples/h5rados_group_open.c b/examples/h5rados_group_open.c
new file mode 100644
index 0000000..3339480
--- /dev/null
+++ b/examples/h5rados_group_open.c
@@ -0,0 +1,63 @@
+#include "h5rados_example.h"
+
+int main(int argc, char *argv[]) {
+ rados_t cluster;
+ char *pool = "mypool";
+ hid_t file = -1, fapl = -1, grp = -1;
+
+ (void)MPI_Init(&argc, &argv);
+
+ if(argc != 3)
+ PRINTF_ERROR("argc != 3\n");
+
+ if(rados_create(&cluster, NULL) < 0)
+ ERROR;
+ if(rados_conf_read_file(cluster, "ceph.conf") < 0)
+ ERROR;
+
+ /* Initialize VOL */
+ if(H5VLrados_init(cluster, pool) < 0)
+ ERROR;
+
+ /* Set up FAPL */
+ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ ERROR;
+ if(H5Pset_fapl_rados(fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ ERROR;
+ if(H5Pset_all_coll_metadata_ops(fapl, true) < 0)
+ ERROR;
+
+ /* Open file */
+ if((file = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0)
+ ERROR;
+
+ printf("Opening group\n");
+
+ /* Open group */
+ if((grp = H5Gopen2(file, argv[2], H5P_DEFAULT)) < 0)
+ ERROR;
+
+ /* Close */
+ if(H5Gclose(grp) < 0)
+ ERROR;
+ if(H5Fclose(file) < 0)
+ ERROR;
+ if(H5Pclose(fapl) < 0)
+ ERROR;
+
+ printf("Success\n");
+
+ (void)MPI_Finalize();
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Gclose(grp);
+ H5Fclose(file);
+ H5Pclose(fapl);
+ } H5E_END_TRY;
+
+ (void)MPI_Finalize();
+ return 1;
+}
+