mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 12:23:54 +01:00
return the number of read elements if read_sparse reached EOF
This commit is contained in:
parent
2e99a14b6e
commit
fafb155228
@ -2413,7 +2413,7 @@ def has_$group_dset$(trexio_file) -> bool:
|
||||
|
||||
#+begin_src c :tangle hrw_dset_sparse_front.h :exports none
|
||||
trexio_exit_code trexio_has_$group_dset$(trexio_t* const file);
|
||||
trexio_exit_code trexio_read_$group_dset$(trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, int32_t* const index_sparse, double* const value_sparse);
|
||||
trexio_exit_code trexio_read_$group_dset$(trexio_t* const file, const int64_t offset_file, int64_t* const buffer_size, int32_t* const index_sparse, double* const value_sparse);
|
||||
trexio_exit_code trexio_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max);
|
||||
trexio_exit_code trexio_write_$group_dset$(trexio_t* const file, const int64_t offset_file, const int64_t buffer_size, const int32_t* index_sparse, const double* value_sparse);
|
||||
#+end_src
|
||||
@ -2424,14 +2424,14 @@ trexio_exit_code trexio_write_$group_dset$(trexio_t* const file, const int64_t o
|
||||
trexio_exit_code
|
||||
trexio_read_$group_dset$(trexio_t* const file,
|
||||
const int64_t offset_file,
|
||||
const int64_t buffer_size,
|
||||
int64_t* const buffer_size,
|
||||
int32_t* const index_sparse,
|
||||
double* const value_sparse
|
||||
)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (offset_file < 0L) return TREXIO_INVALID_ARG_2;
|
||||
if (buffer_size <= 0L) return TREXIO_INVALID_ARG_3;
|
||||
if (*buffer_size <= 0L) return TREXIO_INVALID_ARG_3;
|
||||
if (index_sparse == NULL) return TREXIO_INVALID_ARG_4;
|
||||
if (value_sparse == NULL) return TREXIO_INVALID_ARG_5;
|
||||
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
|
||||
@ -2455,12 +2455,12 @@ trexio_read_$group_dset$(trexio_t* const file,
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_read_$group_dset$(file, offset_file, buffer_size, size_max, &eof_read_size, index_sparse, value_sparse);
|
||||
rc = trexio_text_read_$group_dset$(file, offset_file, *buffer_size, size_max, &eof_read_size, index_sparse, value_sparse);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
#ifdef HAVE_HDF5
|
||||
rc = trexio_hdf5_read_$group_dset$(file, offset_file, buffer_size, num, &eof_read_size, index_sparse, value_sparse);
|
||||
rc = trexio_hdf5_read_$group_dset$(file, offset_file, *buffer_size, num, &eof_read_size, index_sparse, value_sparse);
|
||||
break;
|
||||
#else
|
||||
rc = TREXIO_BACK_END_MISSING;
|
||||
@ -2476,10 +2476,12 @@ trexio_read_$group_dset$(trexio_t* const file,
|
||||
|
||||
if (rc != TREXIO_SUCCESS && rc != TREXIO_END) return rc;
|
||||
|
||||
if (rc == TREXIO_END) *buffer_size = eof_read_size;
|
||||
|
||||
// shift indices to be one-based if Fortran API is used
|
||||
if (file->one_based) {
|
||||
// if EOF is reached - shift only indices that have been read, not an entire buffer
|
||||
uint64_t index_size = (rc == TREXIO_END) ? (rank*eof_read_size) : (rank*buffer_size) ;
|
||||
uint64_t index_size = rank*(*buffer_size) ;
|
||||
for (uint64_t i=0; i<index_size; ++i){
|
||||
index_sparse[i] += 1;
|
||||
}
|
||||
@ -2636,8 +2638,8 @@ trexio_has_$group_dset$ (trexio_t* const file)
|
||||
#+begin_src f90 :tangle write_dset_sparse_front_fortran.f90
|
||||
interface
|
||||
integer function trexio_write_$group_dset$ (trex_file, &
|
||||
offset_file, buffer_size, &
|
||||
index_sparse, value_sparse) bind(C)
|
||||
offset_file, buffer_size, &
|
||||
index_sparse, value_sparse) bind(C)
|
||||
use, intrinsic :: iso_c_binding
|
||||
integer(8), intent(in), value :: trex_file
|
||||
integer(8), intent(in), value :: offset_file
|
||||
@ -2651,13 +2653,13 @@ end interface
|
||||
#+begin_src f90 :tangle read_dset_sparse_front_fortran.f90
|
||||
interface
|
||||
integer function trexio_read_$group_dset$ (trex_file, &
|
||||
offset_file, buffer_size, &
|
||||
index_sparse, value_sparse) bind(C)
|
||||
offset_file, buffer_size, &
|
||||
index_sparse, value_sparse) bind(C)
|
||||
use, intrinsic :: iso_c_binding
|
||||
integer(8), intent(in), value :: trex_file
|
||||
integer(8), intent(in), value :: offset_file
|
||||
integer(8), intent(in), value :: buffer_size
|
||||
integer(4), intent(in) :: index_sparse(*)
|
||||
integer(8), intent(out) :: buffer_size
|
||||
integer(4), intent(out) :: index_sparse(*)
|
||||
double precision, intent(out) :: value_sparse(*)
|
||||
end function trexio_read_$group_dset$
|
||||
end interface
|
||||
@ -2666,7 +2668,7 @@ end interface
|
||||
#+begin_src f90 :tangle read_dset_sparse_size_front_fortran.f90
|
||||
interface
|
||||
integer function trexio_read_$group_dset$_size (trex_file, &
|
||||
size_max) bind(C)
|
||||
size_max) bind(C)
|
||||
use, intrinsic :: iso_c_binding
|
||||
integer(8), intent(in), value :: trex_file
|
||||
integer(8), intent(out) :: size_max
|
||||
|
@ -134,26 +134,36 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
|
||||
int64_t chunk_read = 10L;
|
||||
int64_t offset_file_read = 40L;
|
||||
int offset_data_read = 5;
|
||||
int64_t read_size_check;
|
||||
read_size_check = chunk_read;
|
||||
|
||||
if (offset != 0L) offset_file_read += offset;
|
||||
|
||||
// read one chunk using the aforementioned parameters
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(chunk_read == read_size_check);
|
||||
assert(index_read[0] == 0);
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
|
||||
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
||||
offset_file_read = 97L;
|
||||
offset_file_read = 97;
|
||||
offset_data_read = 1;
|
||||
int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100
|
||||
|
||||
if (offset != 0L) offset_file_read += offset;
|
||||
|
||||
// read one chunk that will reach EOF and return TREXIO_END code
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
assert(rc == TREXIO_END);
|
||||
assert(chunk_read == eof_read_size_check);
|
||||
assert(index_read[4*size_r-1] == 0);
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
/*
|
||||
for(int i=0; i<size_r; ++i){
|
||||
printf("%d %lf\n", index_read[4*i], value_read[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
// close current session
|
||||
rc = trexio_close(file);
|
||||
|
@ -134,24 +134,29 @@ static int test_read_dset_sparse (const char* file_name, const back_end_t backen
|
||||
int64_t chunk_read = 10L;
|
||||
int64_t offset_file_read = 40L;
|
||||
int offset_data_read = 5;
|
||||
int64_t read_size_check;
|
||||
read_size_check = chunk_read;
|
||||
|
||||
if (offset != 0L) offset_file_read += offset;
|
||||
|
||||
// read one chunk using the aforementioned parameters
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
assert(rc == TREXIO_SUCCESS);
|
||||
assert(chunk_read == read_size_check);
|
||||
assert(index_read[0] == 0);
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
|
||||
// now attempt to read so that one encounters end of file during reading (i.e. offset_file_read + chunk_read > size_max)
|
||||
offset_file_read = 97L;
|
||||
offset_data_read = 1;
|
||||
int64_t eof_read_size_check = SIZE - offset_file_read; // if offset_file_read=97 => only 3 integrals will be read out of total of 100
|
||||
|
||||
if (offset != 0L) offset_file_read += offset;
|
||||
|
||||
// read one chunk that will reach EOF and return TREXIO_END code
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
rc = trexio_read_mo_2e_int_eri(file, offset_file_read, &chunk_read, &index_read[4*offset_data_read], &value_read[offset_data_read]);
|
||||
assert(rc == TREXIO_END);
|
||||
assert(chunk_read == eof_read_size_check);
|
||||
assert(index_read[4*size_r-1] == 0);
|
||||
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));
|
||||
|
||||
|
@ -200,6 +200,7 @@ subroutine test_read(file_name, back_end)
|
||||
integer(4) :: index_sparse_mo_2e_int_eri(4,20)
|
||||
double precision :: value_sparse_mo_2e_int_eri(20)
|
||||
integer(8) :: read_buf_size = 10
|
||||
integer(8) :: read_buf_size_save = 10
|
||||
integer(8) :: offset_read = 40
|
||||
integer(8) :: offset_data_read = 5
|
||||
integer(8) :: offset_eof = 97
|
||||
@ -282,6 +283,9 @@ subroutine test_read(file_name, back_end)
|
||||
rc = trexio_read_mo_2e_int_eri(trex_file, offset_read, read_buf_size, &
|
||||
index_sparse_mo_2e_int_eri(1, offset_data_read + 1), &
|
||||
value_sparse_mo_2e_int_eri(offset_data_read + 1))
|
||||
!do i = 1,20
|
||||
! write(*,*) index_sparse_mo_2e_int_eri(1,i)
|
||||
!enddo
|
||||
call trexio_assert(rc, TREXIO_SUCCESS)
|
||||
if (index_sparse_mo_2e_int_eri(1, 1) == 0 .and. &
|
||||
index_sparse_mo_2e_int_eri(1, offset_data_read + 1) == offset_read*4 + 1) then
|
||||
@ -297,14 +301,16 @@ subroutine test_read(file_name, back_end)
|
||||
rc = trexio_read_mo_2e_int_eri(trex_file, offset_eof, read_buf_size, &
|
||||
index_sparse_mo_2e_int_eri(1, offset_data_eof + 1), &
|
||||
value_sparse_mo_2e_int_eri(offset_data_eof + 1))
|
||||
call trexio_assert(rc, TREXIO_END)
|
||||
!do i = 1,20
|
||||
! write(*,*) index_sparse_mo_2e_int_eri(1,i)
|
||||
!enddo
|
||||
if (index_sparse_mo_2e_int_eri(1, 1) == 0 .and. &
|
||||
call trexio_assert(rc, TREXIO_END)
|
||||
if (read_buf_size == 3 .and. &
|
||||
index_sparse_mo_2e_int_eri(1, 1) == 0 .and. &
|
||||
index_sparse_mo_2e_int_eri(1, offset_data_read + 1) == offset_read*4 + 1 .and. &
|
||||
index_sparse_mo_2e_int_eri(1, offset_data_eof + 1) == offset_eof*4 + 1) then
|
||||
write(*,*) 'SUCCESS READ SPARSE DATA EOF'
|
||||
read_buf_size = read_buf_size_save
|
||||
else
|
||||
print *, 'FAILURE SPARSE DATA EOF CHECK'
|
||||
call exit(-1)
|
||||
|
Loading…
Reference in New Issue
Block a user