From 3889eeb5c86376fa677d48c8156584435f5cea66 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Mon, 12 Dec 2016 16:41:39 -0600 Subject: Add transaction number printing for write examples, optional transaction number arguments for read examples. Rework and fix bug in h5dsm_dset_wpartial.c. Not tested. --- examples/h5dsm_dset_create.c | 6 ++++-- examples/h5dsm_dset_open.c | 23 ++++++++++++++++++----- examples/h5dsm_dset_read.c | 23 ++++++++++++++++++----- examples/h5dsm_dset_wpartial.c | 19 ++++++------------- examples/h5dsm_dset_write.c | 6 ++++-- examples/h5dsm_file_open.c | 4 ++-- examples/h5dsm_group_create.c | 2 ++ examples/h5dsm_group_open.c | 19 ++++++++++++++++--- 8 files changed, 70 insertions(+), 32 deletions(-) diff --git a/examples/h5dsm_dset_create.c b/examples/h5dsm_dset_create.c index 441a53f..bc19ae8 100644 --- a/examples/h5dsm_dset_create.c +++ b/examples/h5dsm_dset_create.c @@ -39,6 +39,8 @@ int main(int argc, char *argv[]) { if((trans = H5TRcreate(file, trans_num + 1)) < 0) ERROR; + printf("Creating dataset - transaction number = %llu\n", (long long unsigned)(trans_num + 1)); + /* Create dataset */ if((dset = H5Dcreate_ff(file, argv[3], H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, trans)) < 0) ERROR; @@ -52,7 +54,7 @@ int main(int argc, char *argv[]) { ERROR; if(H5TRclose(trans) < 0) ERROR; - if(H5Fclose(file) < 0) + if(H5Fclose_ff(file, -1) < 0) ERROR; if(H5Sclose(space) < 0) ERROR; @@ -69,7 +71,7 @@ error: H5E_BEGIN_TRY { H5Dclose_ff(dset, -1); H5TRclose(trans); - H5Fclose(file); + H5Fclose_ff(file, -1); H5Sclose(space); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_dset_open.c b/examples/h5dsm_dset_open.c index 18cfad8..8725b01 100644 --- a/examples/h5dsm_dset_open.c +++ b/examples/h5dsm_dset_open.c @@ -5,12 +5,13 @@ int main(int argc, char *argv[]) { char *pool_grp = "daos_tier0"; hid_t file = -1, dset = -1, trans = -1, fapl = -1; hsize_t dims[1] = {1}; + uint64_t trans_num; (void)MPI_Init(&argc, &argv); (void)daos_init(); - if(argc != 4) - PRINTF_ERROR("argc != 4\n"); + if(argc < 4 || argc > 5) + PRINTF_ERROR("argc must be 4 or 5\n"); /* Parse UUID */ if(0 != uuid_parse(argv[1], pool_uuid)) @@ -23,9 +24,21 @@ int main(int argc, char *argv[]) { ERROR; /* Open file */ - if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, &trans)) < 0) + if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, argc == 4 ? &trans : NULL)) < 0) ERROR; + /* Create transaction if specified */ + if(argc == 5) { + trans_num = (uint64_t)atoi(argv[4]); + if((trans = H5TRcreate(file, trans_num)) < 0) + ERROR; + } + else + if(H5TRget_trans_num(trans, &trans_num) < 0) + ERROR; + + printf("Opening dataset - transaction number = %llu\n", (long long unsigned)trans_num); + /* Open dataset */ if((dset = H5Dopen_ff(file, argv[3], H5P_DEFAULT, trans)) < 0) ERROR; @@ -35,7 +48,7 @@ int main(int argc, char *argv[]) { ERROR; if(H5TRclose(trans) < 0) ERROR; - if(H5Fclose(file) < 0) + if(H5Fclose_ff(file, -1) < 0) ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -50,7 +63,7 @@ error: H5E_BEGIN_TRY { H5Dclose_ff(dset, -1); H5TRclose(trans); - H5Fclose(file); + H5Fclose_ff(file, -1); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_dset_read.c b/examples/h5dsm_dset_read.c index 39af503..bd98b98 100644 --- a/examples/h5dsm_dset_read.c +++ b/examples/h5dsm_dset_read.c @@ -7,6 +7,7 @@ int main(int argc, char *argv[]) { hid_t file = -1, dset = -1, trans = -1, fapl = -1; int buf[4][6]; int i, j; + uint64_t trans_num; (void)MPI_Init(&argc, &argv); (void)daos_init(); @@ -14,8 +15,8 @@ int main(int argc, char *argv[]) { /* Seed random number generator */ srand(time(NULL)); - if(argc != 4) - PRINTF_ERROR("argc != 4\n"); + if(argc < 4 || argc > 5) + PRINTF_ERROR("argc must be 4 or 5\n"); /* Parse UUID */ if(0 != uuid_parse(argv[1], pool_uuid)) @@ -28,13 +29,25 @@ int main(int argc, char *argv[]) { ERROR; /* Open file */ - if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, &trans)) < 0) + if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, argc == 4 ? &trans : NULL)) < 0) ERROR; /* Open dataset */ if((dset = H5Dopen_ff(file, argv[3], H5P_DEFAULT, trans)) < 0) ERROR; + /* Create transaction if specified */ + if(argc == 5) { + trans_num = (uint64_t)atoi(argv[4]); + if((trans = H5TRcreate(file, trans_num)) < 0) + ERROR; + } + else + if(H5TRget_trans_num(trans, &trans_num) < 0) + ERROR; + + printf("Reading dataset - transaction number = %llu\n", (long long unsigned)trans_num); + /* Initialize buffer */ for(i = 0; i < 4; i++) for(j = 0; j < 6; j++) @@ -57,7 +70,7 @@ int main(int argc, char *argv[]) { ERROR; if(H5TRclose(trans) < 0) ERROR; - if(H5Fclose(file) < 0) + if(H5Fclose_ff(file, -1) < 0) ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -72,7 +85,7 @@ error: H5E_BEGIN_TRY { H5Dclose_ff(dset, -1); H5TRclose(trans); - H5Fclose(file); + H5Fclose_ff(file, -1); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_dset_wpartial.c b/examples/h5dsm_dset_wpartial.c index 7932df9..8d08d60 100644 --- a/examples/h5dsm_dset_wpartial.c +++ b/examples/h5dsm_dset_wpartial.c @@ -75,8 +75,7 @@ int main(int argc, char *argv[]) { printf("\n"); } - if(rank == 0) - MPI_Barrier(MPI_COMM_WORLD); + printf("Transaction number = %llu\n", (long long unsigned)(trans_num + 1)); /* Set up dataspaces */ if((file_space = H5Screate_simple(2, dims, NULL)) < 0) @@ -96,23 +95,17 @@ int main(int argc, char *argv[]) { if(H5Sselect_hyperslab(mem_space, H5S_SELECT_SET, start, NULL, count, NULL) < 0) ERROR; - if(rank == 1) { - MPI_Barrier(MPI_COMM_WORLD); - if(H5TRclose(trans) < 0) - ERROR; - if((trans = H5TRcreate(file, trans_num + 2)) < 0) - ERROR; - } - /* Write data */ if(H5Dwrite_ff(dset, H5T_NATIVE_INT, mem_space, file_space, H5P_DEFAULT, buf, trans) < 0) ERROR; - if(H5TRcommit(trans) < 0) - ERROR; + MPI_Barrier(MPI_COMM_WORLD); if(rank == 0) - MPI_Barrier(MPI_COMM_WORLD); + if(H5TRcommit(trans) < 0) + ERROR; + + MPI_Barrier(MPI_COMM_WORLD); /* Close */ if(H5Dclose_ff(dset, -1) < 0) diff --git a/examples/h5dsm_dset_write.c b/examples/h5dsm_dset_write.c index 9b45892..d52e5a3 100644 --- a/examples/h5dsm_dset_write.c +++ b/examples/h5dsm_dset_write.c @@ -54,6 +54,8 @@ int main(int argc, char *argv[]) { printf("\n"); } + printf("Transaction number = %llu\n", (long long unsigned)(trans_num + 1)); + /* Write data */ if(H5Dwrite_ff(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf, trans) < 0) ERROR; @@ -67,7 +69,7 @@ int main(int argc, char *argv[]) { ERROR; if(H5TRclose(trans) < 0) ERROR; - if(H5Fclose(file) < 0) + if(H5Fclose_ff(file, -1) < 0) ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -82,7 +84,7 @@ error: H5E_BEGIN_TRY { H5Dclose_ff(dset, -1); H5TRclose(trans); - H5Fclose(file); + H5Fclose_ff(file, -1); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_file_open.c b/examples/h5dsm_file_open.c index 379d39f..fa26795 100644 --- a/examples/h5dsm_file_open.c +++ b/examples/h5dsm_file_open.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) { ERROR; /* Close */ - if(H5Fclose(file) < 0) + if(H5Fclose_ff(file, -1) < 0) ERROR; if(H5Pclose(fapl) < 0) ERROR; @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) { error: H5E_BEGIN_TRY { - H5Fclose(file); + H5Fclose_ff(file, -1); H5Pclose(fapl); } H5E_END_TRY; diff --git a/examples/h5dsm_group_create.c b/examples/h5dsm_group_create.c index c172ac2..ad6e3da 100644 --- a/examples/h5dsm_group_create.c +++ b/examples/h5dsm_group_create.c @@ -34,6 +34,8 @@ int main(int argc, char *argv[]) { if((trans = H5TRcreate(file, trans_num + 1)) < 0) ERROR; + printf("Creating dataset - transaction number = %llu\n", (long long unsigned)(trans_num + 1)); + /* Create group */ if((grp = H5Gcreate_ff(file, argv[3], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT, trans)) < 0) ERROR; diff --git a/examples/h5dsm_group_open.c b/examples/h5dsm_group_open.c index 4031ff2..6dc4144 100644 --- a/examples/h5dsm_group_open.c +++ b/examples/h5dsm_group_open.c @@ -5,12 +5,13 @@ int main(int argc, char *argv[]) { char *pool_grp = "daos_tier0"; hid_t file = -1, grp = -1, trans = -1, fapl = -1; hsize_t dims[1] = {1}; + uint64_t trans_num; (void)MPI_Init(&argc, &argv); (void)daos_init(); - if(argc != 4) - PRINTF_ERROR("argc != 4\n"); + if(argc < 4 || argc > 5) + PRINTF_ERROR("argc must be 4 or 5\n"); /* Parse UUID */ if(0 != uuid_parse(argv[1], pool_uuid)) @@ -23,9 +24,21 @@ int main(int argc, char *argv[]) { ERROR; /* Open file */ - if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, &trans)) < 0) + if((file = H5Fopen_ff(argv[2], H5F_ACC_RDONLY, fapl, argc == 4 ? &trans : NULL)) < 0) ERROR; + /* Create transaction if specified */ + if(argc == 5) { + trans_num = (uint64_t)atoi(argv[4]); + if((trans = H5TRcreate(file, trans_num)) < 0) + ERROR; + } + else + if(H5TRget_trans_num(trans, &trans_num) < 0) + ERROR; + + printf("Opening group - transaction number = %llu\n", (long long unsigned)trans_num); + /* Open group */ if((grp = H5Gopen_ff(file, argv[3], H5P_DEFAULT, trans)) < 0) ERROR; -- cgit v0.12