/*writes properties of the current run related to implementation and command line choices*/ herr_t /*hdf5 error*/ append_meta_properties(hdf5block_t *h5block,/*hdf5 file ids*/ double *seed,/*random number seed*/ size_t *BurnInSampleSize, /*tuning iterations*/ char *h5file, /*name of hdf5 file containing the experimental data and prior set-up*/ char *lib_base)/*basename of the library file @code .so@ file*/{ herr_t status; int omp_n,omp_np,i; status&=H5LTset_attribute_double(h5block->file_id, "LogParameters", "seed", seed, 1); status&=H5LTset_attribute_ulong(h5block->file_id, "LogParameters", "BurnIn", BurnInSampleSize, 1); status&=H5LTset_attribute_string(h5block->file_id, "LogParameters", "DataFrom", h5file); status&=H5LTmake_dataset_string(h5block->file_id,"Model",lib_base); // here we make a short test to see what the automatic choice of the // number of threads turns out to be. #pragma omp parallel private(omp_n,omp_np) reduction(+:i) { i=1; omp_n=omp_get_num_threads(); omp_np=omp_get_num_procs(); } if (i!=omp_n){ fprintf(stderr,"[append_meta_properties] warning: finding out number of threads possibly failed reduction of (n×1: %i) != get_num_threads():%i.\n",i,omp_n); } else { h5block->size[0]=1; h5block->size[1]=1; status&=H5LTmake_dataset_int(h5block->file_id,"OMP_NUM_THREADS",1,h5block->size,&omp_n); status&=H5LTmake_dataset_int(h5block->file_id,"OMP_NUM_PROCS",1,h5block->size,&omp_np); } return status; }
void hdf5_save_int(hid_t loc_id, const string& dataset_name, int i) { hsize_t one = 1; herr_t status = \ H5LTmake_dataset_int(loc_id, dataset_name.c_str(), 1, &one, &i); CHECK_GE(status, 0) << "Failed to save int dataset with name " << dataset_name; }
/** write initial guesses; * return 1 on success, 0 on failure */ int fclib_write_guesses (int number_of_guesses, struct fclib_solution *guesses, const char *path) { hid_t file_id, main_id, id; int nv, nr, nl, i; hsize_t dim = 1; char num [128]; FILE *f; if ((f = fopen (path, "r"))) /* HDF5 outputs lots of warnings when file does not exist */ { fclose (f); if ((file_id = H5Fopen (path, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { fprintf (stderr, "ERROR: opening file failed\n"); return 0; } if (H5Lexists (file_id, "/guesses", H5P_DEFAULT)) /* cannot overwrite existing datasets */ { fprintf (stderr, "ERROR: some guesses have already been written to this file\n"); return 0; } } else { fprintf (stderr, "ERROR: opening file failed\n"); return 0; } if (! read_nvnunrnl (file_id, &nv, &nr, &nl)) return 0; IO (main_id = H5Gmake (file_id, "/guesses")); IO (H5LTmake_dataset_int (file_id, "/guesses/number_of_guesses", 1, &dim, &number_of_guesses)); for (i = 0; i < number_of_guesses; i ++) { snprintf (num, 128, "%d", i+1); IO (id = H5Gmake (main_id, num)); write_solution (id, &guesses [i], nv, nr, nl); IO (H5Gclose (id)); } IO (H5Gclose (main_id)); IO (H5Fclose (file_id)); return 1; }
static int test_dsets( void ) { int rank = 2; hsize_t dims[2] = {2,3}; hid_t file_id; hid_t dataset_id; char data_char_in[DIM] = {1,2,3,4,5,6}; char data_char_out[DIM]; short data_short_in[DIM] = {1,2,3,4,5,6}; short data_short_out[DIM]; int data_int_in[DIM] = {1,2,3,4,5,6}; int data_int_out[DIM]; long data_long_in[DIM] = {1,2,3,4,5,6}; long data_long_out[DIM]; float data_float_in[DIM] = {1,2,3,4,5,6}; float data_float_out[DIM]; double data_double_in[DIM] = {1,2,3,4,5,6}; double data_double_out[DIM]; const char *data_string_in = "This is a string"; char data_string_out[20]; int i; /* Create a new file using default properties. */ file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); /*------------------------------------------------------------------------- * H5LTmake_dataset test *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset"); /* Make dataset */ if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 ) goto out; /* Read dataset using the basic HDF5 API */ if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 ) goto out; if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 ) goto out; if ( H5Dclose( dataset_id ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * read using the LT function H5LTread_dataset *------------------------------------------------------------------------- */ TESTING("H5LTread_dataset"); if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * test the H5LTmake_dataset_ functions *------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- * H5LTmake_dataset_char *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_char"); /* Make dataset char */ if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_char_in[i] != data_char_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_char_in[i] != data_char_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_short *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_short"); /* Make dataset short */ if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_short_in[i] != data_short_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_short_in[i] != data_short_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_int *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_int"); /* Make dataset int */ if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_int_in[i] != data_int_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_long *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_long"); /* Make dataset long */ if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_long_in[i] != data_long_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_long_in[i] != data_long_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_float *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_float"); /* Make dataset float */ if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_float_in[i] != data_float_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_float_in[i] != data_float_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_double *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_double"); /* Make dataset double */ if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_double_in[i] != data_double_out[i] ) { goto out; } } /* Read dataset */ if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 ) goto out; for (i = 0; i < DIM; i++) { if ( data_double_in[i] != data_double_out[i] ) { goto out; } } PASSED(); /*------------------------------------------------------------------------- * H5LTmake_dataset_string *------------------------------------------------------------------------- */ TESTING("H5LTmake_dataset_string"); /* Make dataset string */ if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 ) goto out; /* Read dataset */ if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 ) goto out; if ( strcmp(data_string_in,data_string_out) != 0 ) goto out; /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- */ /* Close the file. */ H5Fclose( file_id ); PASSED(); return 0; out: /* Close the file. */ H5_FAILED(); return -1; }
int main(void) { hid_t fid; /* file ID */ hid_t did; /* dataset ID */ hid_t dsid; /* DS dataset ID */ int rank = RANK; /* rank of data dataset */ int rankds = 1; /* rank of DS dataset */ hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; /* size of data dataset */ int buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; /* data of data dataset */ hsize_t s1_dim[1] = {DIM1_SIZE}; /* size of DS 1 dataset */ hsize_t s2_dim[1] = {DIM2_SIZE}; /* size of DS 2 dataset */ float s1_wbuf[DIM1_SIZE] = {10,20,30}; /* data of DS 1 dataset */ int s2_wbuf[DIM2_SIZE] = {10,20,50,100}; /* data of DS 2 dataset */ /* create a file using default properties */ if ((fid=H5Fcreate("ex_ds1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) goto out; /* make a dataset */ if (H5LTmake_dataset_int(fid,DSET_NAME,rank,dims,buf)<0) goto out; /* make a DS dataset for the first dimension */ if (H5LTmake_dataset_float(fid,DS_1_NAME,rankds,s1_dim,s1_wbuf)<0) goto out; /* make a DS dataset for the second dimension */ if (H5LTmake_dataset_int(fid,DS_2_NAME,rankds,s2_dim,s2_wbuf)<0) goto out; /*------------------------------------------------------------------------- * attach the DS_1_NAME dimension scale to DSET_NAME at dimension 0 *------------------------------------------------------------------------- */ /* get the dataset id for DSET_NAME */ if ((did = H5Dopen2(fid,DSET_NAME, H5P_DEFAULT))<0) goto out; /* get the DS dataset id */ if ((dsid = H5Dopen2(fid,DS_1_NAME, H5P_DEFAULT))<0) goto out; /* attach the DS_1_NAME dimension scale to DSET_NAME at dimension index 0 */ if (H5DSattach_scale(did,dsid,DIM0)<0) goto out; /* close DS id */ if (H5Dclose(dsid)<0) goto out; /*------------------------------------------------------------------------- * attach the DS_2_NAME dimension scale to DSET_NAME *------------------------------------------------------------------------- */ /* get the DS dataset id */ if ((dsid = H5Dopen2(fid,DS_2_NAME, H5P_DEFAULT))<0) goto out; /* attach the DS_2_NAME dimension scale to DSET_NAME as the 2nd dimension (index 1) */ if (H5DSattach_scale(did,dsid,DIM1)<0) goto out; /* close DS id */ if (H5Dclose(dsid)<0) goto out; /* close file */ H5Fclose(fid); return 0; out: printf("Error on return function...Exiting\n"); return 1; }
/*main mcmc loop, records sampled values, performs no tuning of the step size.*/ int /*always returns success*/ mcmc_foreach(int rank, /*MPI rank*/ int R, /*MPI Comm size*/ size_t SampleSize, /*number of iterations of MCMC*/ ode_model_parameters *omp, /*ODE problem cpecification and pre-allocated space*/ mcmc_kernel *kernel, /* MCMC kernel sturct, holds MCMC-algorithm's parameters*/ hdf5block_t *h5block, /*defines the hdf5 file to write into, holds ids and sizes*/ void *buffer, /* for MPI communication, similar to kernel*/ main_options *option)/*options from defaults, files and command line*/{ clock_t ct=clock(); gsl_matrix *log_para_chunk; gsl_vector *log_post_chunk; int D=get_number_of_MCMC_variables(omp); log_para_chunk=gsl_matrix_alloc(CHUNK,D); log_post_chunk=gsl_vector_alloc(CHUNK); gsl_vector_view current; gsl_vector_view x_state; int swaps = 0; // swap success counter int acc=no; // acceptance flag int acc_c=0; // acceptance counter double acc_rate=0.0; size_t it; int master=no; int DEST; double beta=mcmc_get_beta(kernel); herr_t status; int resume_EC; int last_chunk=no, not_written_yet=yes; for (it = 0; it < SampleSize; it++) { mcmc_sample(kernel, &acc); last_chunk=SampleSize-it<CHUNK; if (acc && last_chunk && not_written_yet){ resume_EC=write_resume_state(option->resume_file, rank, R, kernel); if (resume_EC==EXIT_SUCCESS){ not_written_yet=no; } } acc_c += acc; master=(it%2==rank%2); if (master){ DEST=(rank+1)%R; // this process is the master process for swap decisions } else { DEST=(R+rank-1)%R; // this process has to accept swap decisions from DEST } //their_beta=BETA(DEST,R); // the other proc's if (R>1){ mcmc_exchange_information(kernel,DEST,buffer); swaps+=mcmc_swap_chains(kernel,master,rank,DEST,buffer); } /* save sampled point for writing */ current=gsl_matrix_row(log_para_chunk,it%CHUNK); x_state=gsl_vector_view_array(kernel->x,D); gsl_vector_memcpy(&(current.vector),&(x_state.vector)); gsl_vector_set(log_post_chunk,it%CHUNK,kernel->fx[0]); /* print sample log and statistics every 100 samples */ if ( ((it + 1) % CHUNK) == 0 ) { acc_rate = ((double) acc_c) / ((double) CHUNK); fprintf(stdout, "# [rank % 2i/% 2i; β=%5f; %3li%% done] (it %5li)\tacc. rate: %3.2f;\t%3i %% swap success\t",rank,R,beta,(100*it)/SampleSize,it,acc_rate,swaps); mcmc_print_stats(kernel, stdout); acc_c = 0; // print chunk to hdf5 file status=h5write_current_chunk(h5block,log_para_chunk,log_post_chunk); h5block->offset[0]=it+1; swaps=0; } } assert(status==0); // write remaining data to the output hdf5 file int Rest=SampleSize % CHUNK; printf("[main] last iteration done %i points remain to write.\n",Rest); if (Rest > 0){ h5block->chunk_size[0]=Rest; h5block->chunk_size[1]=D; h5block->para_chunk_id=H5Screate_simple(2, h5block->chunk_size, NULL); h5block->chunk_size[0]=Rest; h5block->chunk_size[1]=1; h5block->post_chunk_id=H5Screate_simple(2, h5block->chunk_size, NULL); printf("[main] writing the remaining %i sampled parametrisations to file.\n",Rest); h5block->block[0]=Rest; h5block->block[1]=D; display_chunk_properties(h5block); status = H5Sselect_hyperslab(h5block->para_dataspace_id, H5S_SELECT_SET, h5block->offset, h5block->stride, h5block->count, h5block->block); H5Dwrite(h5block->parameter_set_id, H5T_NATIVE_DOUBLE, h5block->para_chunk_id, h5block->para_dataspace_id, H5P_DEFAULT, log_para_chunk->data); h5block->block[1]=1; printf("[main] writing their %i log-posterior values to file.\n",Rest); display_chunk_properties(h5block); status &= H5Sselect_hyperslab(h5block->post_dataspace_id, H5S_SELECT_SET, h5block->offset, h5block->stride, h5block->count, h5block->block); H5Dwrite(h5block->posterior_set_id, H5T_NATIVE_DOUBLE, h5block->post_chunk_id, h5block->post_dataspace_id, H5P_DEFAULT, log_post_chunk->data); assert(status>=0); } // annotate written sample with all necessary information //printf("[main] writing some annotation about the sampled points as hdf5 attributes.\n"); status&=H5LTset_attribute_int(h5block->file_id, "LogParameters", "MPI_RANK", &rank, 1); status&=H5LTset_attribute_ulong(h5block->file_id, "LogParameters", "SampleSize", &SampleSize, 1); status&=H5LTset_attribute_double(h5block->file_id, "LogParameters", "InverseTemperature_Beta", &beta, 1); ct=clock()-ct; double sampling_time=((double) ct)/((double) CLOCKS_PER_SEC); int ts=round(sampling_time); int hms[3]; // hours, minutes, seconds hms[0]=ts/3600; hms[1]=(ts%3600)/60; hms[2]=(ts%60); printf("# computation time spend sampling: %i:%i:%i\n",hms[0],hms[1],hms[2]); h5block->size[0]=1; status&=H5LTmake_dataset_double (h5block->file_id, "SamplingTime_s", 1, h5block->size, &sampling_time); h5block->size[0]=3; status&=H5LTmake_dataset_int(h5block->file_id, "SamplingTime_hms", 1, h5block->size, hms); if(status){ printf("[rank %i] statistics written to file.\n",rank); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { // test_dstegr(); if (argc != 4 + 1) { printf("Usage: %s N W K output.h5\n", argv[0]); return -1; } lapack_int N = atoi(argv[1]); double W = atof(argv[2]); lapack_int K = atoi(argv[3]); char *outname = argv[4]; // printf("N = %d\nW = %g\nK = %d\noutname = %s\n", N, W, K, outname); if (!(0 < K && K <= N && 0 < W && W < 0.5)) { printf("The arguments must satisfy 0 < K <= N and 0 < W < 0.5\n"); return -1; } double *d = calloc(N, sizeof(double)); double *e = calloc(N, sizeof(double)); double *w = calloc(N, sizeof(double)); double *z = calloc(K * N, sizeof(double)); lapack_int m = 0; lapack_int ldz = N; lapack_int *isuppz = calloc(2 * K, sizeof(lapack_int)); assert(d && e && w && z && isuppz); double cos_two_pi_W = cos(2 * 3.14159265358979323846 * W); double x; for (int i = 0; i < N; i++) { x = (0.5 * (N - 1) - i); d[i] = x * x * cos_two_pi_W; } for (int i = 0; i < N - 1; i++) e[i] = 0.5 * (i + 1) * (N - i - 1); /* lapack_int LAPACKE_dstegr( int matrix_order, char jobz, char range, */ /* lapack_int n, double* d, double* e, double vl, */ /* double vu, lapack_int il, lapack_int iu, */ /* double abstol, lapack_int* m, double* w, double* z, */ /* lapack_int ldz, lapack_int* isuppz ); */ printf("Before DSTEGR\n"); lapack_int info = LAPACKE_dstegr(LAPACK_COL_MAJOR, 'V', 'I', N, d, e, 0, 0, N - K + 1, N, 0, &m, w, z, ldz, isuppz); printf("After DSTEGR\n"); printf("K = %d\nm = %d\n", K, m); if (info) { printf("Some error occurred in DSTEGR, info = %d\n", info); return -1; } hid_t file_id; hsize_t dims_w[1] = {K}; hsize_t dims_z[2] = {K, N}; hsize_t dims_scalar[1] = {1}; herr_t status; file_id = H5Fcreate(outname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); assert(file_id >= 0); status = H5LTmake_dataset_double(file_id, "/eigenvalues", 1, dims_w, w); assert(status >= 0); status = H5LTmake_dataset_double(file_id, "/eigenvectors", 2, dims_z, z); assert(status >= 0); status = H5LTmake_dataset_double(file_id, "/W", 1, dims_scalar, &W); assert(status >= 0); status = H5LTmake_dataset_int(file_id, "/K", 1, dims_scalar, &K); assert(status >= 0); status = H5LTmake_dataset_int(file_id, "/N", 1, dims_scalar, &N); assert(status >= 0); status = H5Fclose (file_id); assert(status >= 0); /* free(d); */ /* free(e); */ /* free(w); */ /* free(z); */ /* free(isuppz); */ return 0; }
/** write local problem; * return 1 on success, 0 on failure */ int fclib_write_local (struct fclib_local *problem, const char *path) { hid_t file_id, main_id, id; hsize_t dim = 1; FILE *f; if ((f = fopen (path, "r"))) /* HDF5 outputs lots of warnings when file does not exist */ { fclose (f); if ((file_id = H5Fopen (path, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { fprintf (stderr, "ERROR: opening file failed\n"); return 0; } if (H5Lexists (file_id, "/fclib_local", H5P_DEFAULT)) /* cannot overwrite existing datasets */ { fprintf (stderr, "ERROR: a local problem has already been written to this file\n"); return 0; } } else if ((file_id = H5Fcreate (path, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) /* cerate */ { fprintf (stderr, "ERROR: creating file failed\n"); return 0; } IO (main_id = H5Gmake (file_id, "/fclib_local")); ASSERT (problem->spacedim == 2 || problem->spacedim == 3, "ERROR: space dimension must be 2 or 3"); IO (H5LTmake_dataset_int (file_id, "/fclib_local/spacedim", 1, &dim, &problem->spacedim)); ASSERT (problem->W, "ERROR: W must be given"); IO (id = H5Gmake (file_id, "/fclib_local/W")); write_matrix (id, problem->W); IO (H5Gclose (id)); if (problem->V && problem->R) { IO (id = H5Gmake (file_id, "/fclib_local/V")); write_matrix (id, problem->V); IO (H5Gclose (id)); IO (id = H5Gmake (file_id, "/fclib_local/R")); write_matrix (id, problem->R); IO (H5Gclose (id)); } else ASSERT (!problem->V && !problem->R, "ERROR: V and R must be defined at the same time"); IO (id = H5Gmake (file_id, "/fclib_local/vectors")); write_local_vectors (id, problem); IO (H5Gclose (id)); if (problem->info) { IO (id = H5Gmake (file_id, "/fclib_local/info")); write_problem_info (id, problem->info); IO (H5Gclose (id)); } IO (H5Gclose (main_id)); IO (H5Fclose (file_id)); return 1; }
/** write matrix */ static void write_matrix (hid_t id, struct fclib_matrix *mat) { hsize_t dim = 1; IO (H5LTmake_dataset_int (id, "nzmax", 1, &dim, &mat->nzmax)); IO (H5LTmake_dataset_int (id, "m", 1, &dim, &mat->m)); IO (H5LTmake_dataset_int (id, "n", 1, &dim, &mat->n)); IO (H5LTmake_dataset_int (id, "nz", 1, &dim, &mat->nz)); if (mat->nz >= 0) /* triplet */ { dim = mat->nz; IO (H5LTmake_dataset_int (id, "p", 1, &dim, mat->p)); IO (H5LTmake_dataset_int (id, "i", 1, &dim, mat->i)); } else if (mat->nz == -1) /* csc */ { dim = mat->n+1; IO (H5LTmake_dataset_int (id, "p", 1, &dim, mat->p)); dim = mat->nzmax; IO (H5LTmake_dataset_int (id, "i", 1, &dim, mat->i)); } else if (mat->nz == -2) /* csr */ { dim = mat->m+1; IO (H5LTmake_dataset_int (id, "p", 1, &dim, mat->p)); dim = mat->nzmax; IO (H5LTmake_dataset_int (id, "i", 1, &dim, mat->i)); } else ASSERT (0, "ERROR: unkown sparse matrix type => fclib_matrix->nz = %d\n", mat->nz); dim = mat->nzmax; IO (H5LTmake_dataset_double (id, "x", 1, &dim, mat->x)); if (mat->info) { dim = 1; if (mat->info->comment) IO (H5LTmake_dataset_string (id, "comment", mat->info->comment)); IO (H5LTmake_dataset_double (id, "conditioning", 1, &dim, &mat->info->conditioning)); IO (H5LTmake_dataset_double (id, "determinant", 1, &dim, &mat->info->determinant)); IO (H5LTmake_dataset_int (id, "rank", 1, &dim, &mat->info->rank)); } }