hid_t open_supercontig_dataset(supercontig_t *supercontig, char *trackname) { /* it must already exist; returns a handle for H5Dread or H5Dwrite */ hid_t dataset = -1; /* open dataset if it already exists */ dataset = open_dataset(supercontig->group, DATASET_NAME, H5P_DEFAULT); if (dataset < 0) { fprintf(stderr, "ERROR: Missing supercontig dataset for track: %s\ \nMake sure to open data tracks with genomedata-open-data before trying \ to load data.", trackname); fatal("missing supercontig dataset"); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests reading files created on LE and BE systems. * * Return: Success: exit(0) * Failure: exit(1) * * Programmer: Raymond Lu * Thursday, March 23, 2006 * *------------------------------------------------------------------------- */ int main(void) { char filename[1024]; unsigned nerrors = 0; h5_reset(); puts("Testing reading data created on Linux"); h5_fixname(FILENAME[1], H5P_DEFAULT, filename, sizeof filename); nerrors += open_dataset(filename); puts("Testing reading data created on Solaris"); h5_fixname(FILENAME[2], H5P_DEFAULT, filename, sizeof filename); nerrors += open_dataset(filename); if (nerrors) { printf("***** %u FAILURE%s! *****\n", nerrors, 1==nerrors?"":"S"); HDexit(1); } printf("All data type tests passed.\n"); return 0; }
hid_t set_up_rnw() { // Set up driver to use ram instead of on-disk files. hid_t fapl; fapl = set_core(); create_file(fapl, FILE_NAME_RNW); hid_t file_id; file_id = open_file(fapl, FILE_NAME_RNW); size_t dim0, dim1; for (dim0 = DIM0_START; dim0 <= DIM0_LIM; dim0 *= 2) { for (dim1 = DIM1_START; dim1 <= DIM1_LIM; dim1 *= 2) { // get name of dataset char name[25]; sprintf(name, "dataset_%dx%d", dim0, dim1); // puts string into buffer create_dataset(file_id, dim0, dim1, name); /* Initialise with values */ hid_t dataset_id; dataset_id = open_dataset(file_id, name); double matrix[dim0][dim1]; int i, j; // fill matrix with some elements for (i = 0; i < dim0; i++) { for (j = 0; j < dim1; j++) { matrix[i][j] = i * dim1 + j; } } write_matrix(dataset_id, matrix); close_dataset(dataset_id); } } /* Done initializing values */ close_file(file_id); return fapl; }
main(int argc, char **argv) { char inbuf[BUFLEN], *s; Btree *bt = NULL; FILE *logfile = NULL; for (;;) { fflush(stdout); fputs("Action (? for help): ", stdout); fflush(stdout); fgets(inbuf, BUFLEN, stdin); s = inbuf + strlen(inbuf); while(iscntrl(*s)) *s-- = 0; if (logfile) fprintf(logfile, "%s\n", inbuf); if (!bt && strchr("@adfkKmMsSwW", inbuf[0])) { fputs(" **no open dataset\n", stdout); continue; } switch (inbuf[0]) { case '?': fputs( "@file - load strings in file into tree\n" "a string - add name;addr to tree\n" "d string - delete name;addr from tree\n" "dup [0|1] - disallow/allow duplicates\n" "f string - find name;addr in tree\n" "k/K [file] - display key counts (K = overwrite file)\n" "l file - log actions to file\n" "l - turn off action logging\n" "m/M [file] - display block usage map\n" "n file - make a new dataset\n" "o file - open an existing dataset\n" "s/S [file] - display tree (S = overwrite file)\n" "w/W [file] - walk tree, (W = overwrite file)\n" "q - quit\n" , stdout); fflush(stdout); break; case '@': LoadFile(bt, inbuf + 1); break; case 'a': if (inbuf[1] != ' ' || !inbuf[2] || !strchr(inbuf,';')) fputs(" Not a valid command\n", stdout); else if (DoData(bt, inbuf + 2, 1) == TREE_FAIL) fputs(" ** Insertion failed\n", stdout); break; case 'd': if (inbuf[1] == 'u' && inbuf[2] == 'p') { if (inbuf[3] == ' ' && (inbuf[4] == '0' || inbuf[4] == '1')) bt -> duplicatesOK = inbuf[4] == '0' ? 0 : 1; fputs("duplicates are ", stdout); if (bt -> duplicatesOK == 0) fputs("not ", stdout); fputs("allowed.\n", stdout); break; } if (inbuf[1] != ' ' || inbuf[2] == 0) fputs(" Not a valid command\n", stdout); else { if (DoData(bt, inbuf + 2, 0) == TREE_FAIL) fputs(" ** Delete failed\n", stdout); } break; case 'f': if (inbuf[1] != ' ' || inbuf[2] == 0) fputs(" Not a valid command\n", stdout); else { UR record; inbuf[12] = '\0'; if (bt_find(bt, &record, inbuf+2) == TREE_FAIL) fputs(" ** Find failed\n", stdout); else fprintf(stdout, "found %s;%s\n", record.name, record.addr); } break; case 'k': case 'K': { FILE *out; if (inbuf[1] == ' ' && inbuf[2] != 0) { out = fopen(inbuf+2, inbuf[0] == 'k' ? "w" : "a"); if (!out) printf("Can't open %s\n", inbuf + 2); else { show_btree(bt, out, 0); fclose(out); } } else show_btree(bt, stdout, 0); } break; case 'l': if (inbuf[1] != ' ' || inbuf[2] == 0) { if (logfile) { fclose(logfile); logfile = NULL; } else fputs(" Logfile not open\n", stdout); } else { logfile = fopen(inbuf + 2, "w"); if (logfile == NULL) printf("Can't open %s\n", inbuf + 2); } break; case 'm': case 'M': { FILE *out; if (inbuf[1] == ' ' && inbuf[2] != 0) { out = fopen(inbuf+2, inbuf[0] == 'm' ? "w" : "a"); if (!out) printf("Can't open %s\n", inbuf + 2); else { show_btree_map(bt, out); fclose(out); } } else show_btree_map(bt, stdout); } break; case 'n': if (inbuf[1] != ' ' || inbuf[2] == 0) fputs(" Not a valid command\n", stdout); else make_dataset(inbuf+2); break; case 'o': if (inbuf[1] != ' ' || inbuf[2] == 0) fputs(" Not a valid command\n", stdout); else { if (bt) { if (bt_close(bt)) printf("\nClose failed: %s\n", ErrorText[bt->error_code]); else printf("\nData files closed.\n"); bt = NULL; } bt = open_dataset(inbuf+2); } break; case 'q': if (logfile) fclose(logfile); if (bt) { if (bt_close(bt)) printf("\nClose failed: %s\n", ErrorText[bt->error_code]); else printf("\nData files closed.\n"); } return; case 's': case 'S': { FILE *out; if (inbuf[1] == ' ' && inbuf[2] != 0) { out = fopen(inbuf+2, inbuf[0] == 's' ? "w" : "a"); if (!out) printf("Can't open %s\n", inbuf + 2); else { show_btree(bt, out, 1); fclose(out); } } else show_btree(bt, stdout, 1); } break; case 'w': case 'W': { if (inbuf[1] == ' ' && inbuf[2] != 0) { outfile = fopen(inbuf+2, inbuf[0] == 'w' ? "w" : "a"); if (!outfile) printf("Can't open %s\n", inbuf + 2); else { DataCount = 0; bt_walk(bt, DisplayFunc); fprintf(outfile, "%d items\n", DataCount); fclose(outfile); outfile = NULL; } } else { DataCount = 0; outfile = stdout; bt_walk(bt, DisplayFunc); fprintf(outfile, "%d items\n", DataCount); outfile = NULL; } } break; case ';': break; /* comment */ default: fputs(" Not a valid command\n", stdout); break; } if (bt && bt->error_code) { printf("ERROR: %s\n", ErrorText[bt->error_code]); bt->error_code = 0; } } }
void test_rnw(hid_t fapl) { size_t dim0, dim1; int i, j, k; int x, y; clock_t b, e; double file_open_time, file_close_time; double dataset_open_time, dataset_close_time; double read_time, write_time; file_open_time = 0; file_close_time = 0; dataset_open_time = 0; dataset_close_time = 0; read_time = 0; write_time = 0; for (dim0 = DIM0_START; dim0 <= DIM0_LIM; dim0 *= 2) { for (dim1 = DIM1_START; dim1 <= DIM1_LIM; dim1 *= 2) { for (i = 0; i < LENGTH; i++) { // Open file b = clock(); hid_t file_id; file_id = open_file(fapl, FILE_NAME_RNW); e = clock(); file_open_time += (double) (e - b) / CLOCKS_PER_SEC; // get name of dataset char name[25]; sprintf(name, "dataset_%dx%d", dim0, dim1); // puts string into buffer // Open dataset b = clock(); hid_t dataset_id; dataset_id = open_dataset(file_id, name); e = clock(); dataset_open_time += (double) (e - b) / CLOCKS_PER_SEC; // READS AND WRITES double matrix[dim0][dim1]; for (k = 0; k < READS_AND_WRITES; k++) { b = clock(); read_mat(dataset_id, dim0, dim1, matrix); e = clock(); read_time += (double) (e - b) / CLOCKS_PER_SEC; // Modify the data at least a bit // just to eliminate any shortcuts. /* for (x = 0; x < dim0; x++) { for (y = 0; y < dim1; y++) { matrix[x][y] += 1; } } */ // NOTE: there don't seem to be any shortcuts b = clock(); write_mat(dataset_id, dim0, dim1, matrix); e = clock(); write_time += (double) (e - b) / CLOCKS_PER_SEC; } // Close dataset b = clock(); close_dataset(dataset_id); e = clock(); dataset_close_time += (double) (e - b) / CLOCKS_PER_SEC; // Close file b = clock(); close_file(file_id); e = clock(); file_close_time += (double) (e - b) / CLOCKS_PER_SEC; } } } printf("Executed an average-case read and write test with the following properties:\n"); printf("The experiment uses file: " FILE_NAME_RNW "\n"); printf("The experiment repeats %d times.\n", LENGTH); printf("Dim0 starting from %d and doubling until %d.\n", DIM0_START, DIM0_LIM); printf("Dim1 starting from %d and doubling until %d.\n", DIM1_START, DIM1_LIM); printf("Reading and writing a matrix %d times.\n", READS_AND_WRITES); double total_reads_and_writes; total_reads_and_writes = LENGTH * READS_AND_WRITES * (DIM0_LIM - DIM0_START) * (DIM1_LIM - DIM1_START); printf("This means a total of %.0lf doubles have been read and written.\n", total_reads_and_writes); printf("\n"); printf("Opening the file took a total of %f seconds.\n", file_open_time); printf("Closing the file took a total of %f seconds.\n", file_close_time); printf("Opening the dataset took a total of %f seconds.\n", dataset_open_time); printf("Closing the dataset took a total of %f seconds.\n", dataset_close_time); printf("Reading the data took a total of %f seconds.\n", read_time); printf("Writing the data took a total of %f seconds.\n", write_time); printf("This means that reading produces an average overhead of %f ns per double.\n", read_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); printf("This means that writing produces an average overhead of %f ns per double.\n\n", write_time / total_reads_and_writes * NANOSECONDS_IN_A_SECOND); }
int mpi_mesh_grdecl::mpi_hdf5_read_dataset (const char* dset_title, hid_t file_id, hsize_t dims_memory, hsize_t *stride, hsize_t *block, hsize_t *count, const int datatype, int *data_int, float *data_float, const int nx, const int ny, const int i_start2, const int j_start, const int k_start, const int i_end, const int j_end, const int k_end, int mode) { herr_t status; int rank = 1; // read 1-dimensional array hid_t filespace, memspace; // file and memory dataspace identifiers int k; float *data_float_ptr = data_float; int *data_int_ptr = data_int; hid_t dset_id; hsize_t start[1]; if (datatype != TYPE_FLOAT && datatype != TYPE_INT) { printf("Error: wrong type!\n"); return -1; } dset_id = open_dataset(rank, &dims_memory, file_id, dset_title); if (dset_id < 0) return -1; //cant' open dataset! filespace = H5Dget_space(dset_id); memspace = H5Screate_simple(rank, &dims_memory, NULL); hid_t plist_id = H5Pcreate(H5P_DATASET_XFER); H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT); if (mode) // for 1 pass read { if (mode == 1)// initial_data start[0] = 0; else if (mode == 2)// coord start[0] = (i_start + j_start * (nx + 1)) * 6; H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, stride, count, block); if (datatype == TYPE_FLOAT) status = H5Dread(dset_id, H5T_NATIVE_FLOAT, memspace, filespace, plist_id, data_float); else if (datatype == TYPE_INT) status = H5Dread(dset_id, H5T_NATIVE_INT, memspace, filespace, plist_id, data_int); } else // multi pass read { for (k = 0; k < k_end - k_start + 1; k++) { start[0] = i_start + j_start * nx + (k + k_start) * nx * ny; H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, stride, count, block); if (datatype == TYPE_FLOAT) status = H5Dread(dset_id, H5T_NATIVE_FLOAT, memspace, filespace, plist_id, data_float_ptr); else if (datatype == TYPE_INT) status = H5Dread(dset_id, H5T_NATIVE_INT, memspace, filespace, plist_id, data_int_ptr); if (status < 0) { printf("Error: Dataset read error!\n"); return -1; } data_int_ptr = data_int_ptr + dims_memory; data_float_ptr = data_float_ptr + dims_memory; } } //release resources H5Dclose(dset_id); H5Sclose(filespace); H5Sclose(memspace); H5Pclose(plist_id); return 0; }