1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 12:56:53 +01:00

Merge branch 'add-sparse-datasets' of github.com:TREX-CoE/trexio into add-sparse-datasets

This commit is contained in:
Anthony Scemama 2021-12-17 11:03:29 +01:00
commit 5605be77bb
4 changed files with 43 additions and 20 deletions

View File

@ -2413,7 +2413,7 @@ def has_$group_dset$(trexio_file) -> bool:
#+begin_src c :tangle hrw_dset_sparse_front.h :exports none #+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_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_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); 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 #+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_exit_code
trexio_read_$group_dset$(trexio_t* const file, trexio_read_$group_dset$(trexio_t* const file,
const int64_t offset_file, const int64_t offset_file,
const int64_t buffer_size, int64_t* const buffer_size,
int32_t* const index_sparse, int32_t* const index_sparse,
double* const value_sparse double* const value_sparse
) )
{ {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (offset_file < 0L) return TREXIO_INVALID_ARG_2; 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 (index_sparse == NULL) return TREXIO_INVALID_ARG_4;
if (value_sparse == NULL) return TREXIO_INVALID_ARG_5; if (value_sparse == NULL) return TREXIO_INVALID_ARG_5;
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; 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) { switch (file->back_end) {
case TREXIO_TEXT: 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; break;
case TREXIO_HDF5: case TREXIO_HDF5:
#ifdef HAVE_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; break;
#else #else
rc = TREXIO_BACK_END_MISSING; 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_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 // shift indices to be one-based if Fortran API is used
if (file->one_based) { if (file->one_based) {
// if EOF is reached - shift only indices that have been read, not an entire buffer // 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){ for (uint64_t i=0; i<index_size; ++i){
index_sparse[i] += 1; 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 #+begin_src f90 :tangle write_dset_sparse_front_fortran.f90
interface interface
integer function trexio_write_$group_dset$ (trex_file, & integer function trexio_write_$group_dset$ (trex_file, &
offset_file, buffer_size, & offset_file, buffer_size, &
index_sparse, value_sparse) bind(C) index_sparse, value_sparse) bind(C)
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file integer(8), intent(in), value :: trex_file
integer(8), intent(in), value :: offset_file integer(8), intent(in), value :: offset_file
@ -2651,13 +2653,13 @@ end interface
#+begin_src f90 :tangle read_dset_sparse_front_fortran.f90 #+begin_src f90 :tangle read_dset_sparse_front_fortran.f90
interface interface
integer function trexio_read_$group_dset$ (trex_file, & integer function trexio_read_$group_dset$ (trex_file, &
offset_file, buffer_size, & offset_file, buffer_size, &
index_sparse, value_sparse) bind(C) index_sparse, value_sparse) bind(C)
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file integer(8), intent(in), value :: trex_file
integer(8), intent(in), value :: offset_file integer(8), intent(in), value :: offset_file
integer(8), intent(in), value :: buffer_size integer(8), intent(out) :: buffer_size
integer(4), intent(in) :: index_sparse(*) integer(4), intent(out) :: index_sparse(*)
double precision, intent(out) :: value_sparse(*) double precision, intent(out) :: value_sparse(*)
end function trexio_read_$group_dset$ end function trexio_read_$group_dset$
end interface end interface
@ -2666,7 +2668,7 @@ end interface
#+begin_src f90 :tangle read_dset_sparse_size_front_fortran.f90 #+begin_src f90 :tangle read_dset_sparse_size_front_fortran.f90
interface interface
integer function trexio_read_$group_dset$_size (trex_file, & integer function trexio_read_$group_dset$_size (trex_file, &
size_max) bind(C) size_max) bind(C)
use, intrinsic :: iso_c_binding use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file integer(8), intent(in), value :: trex_file
integer(8), intent(out) :: size_max integer(8), intent(out) :: size_max

View File

@ -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 chunk_read = 10L;
int64_t offset_file_read = 40L; int64_t offset_file_read = 40L;
int offset_data_read = 5; int offset_data_read = 5;
int64_t read_size_check;
read_size_check = chunk_read;
if (offset != 0L) offset_file_read += offset; if (offset != 0L) offset_file_read += offset;
// read one chunk using the aforementioned parameters // 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(rc == TREXIO_SUCCESS);
assert(chunk_read == read_size_check);
assert(index_read[0] == 0); assert(index_read[0] == 0);
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); 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) // 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; 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; if (offset != 0L) offset_file_read += offset;
// read one chunk that will reach EOF and return TREXIO_END code // 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(rc == TREXIO_END);
assert(chunk_read == eof_read_size_check);
assert(index_read[4*size_r-1] == 0); assert(index_read[4*size_r-1] == 0);
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); 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 // close current session
rc = trexio_close(file); rc = trexio_close(file);

View 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 chunk_read = 10L;
int64_t offset_file_read = 40L; int64_t offset_file_read = 40L;
int offset_data_read = 5; int offset_data_read = 5;
int64_t read_size_check;
read_size_check = chunk_read;
if (offset != 0L) offset_file_read += offset; if (offset != 0L) offset_file_read += offset;
// read one chunk using the aforementioned parameters // 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(rc == TREXIO_SUCCESS);
assert(chunk_read == read_size_check);
assert(index_read[0] == 0); assert(index_read[0] == 0);
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); 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) // 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 = 97L;
offset_data_read = 1; 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; if (offset != 0L) offset_file_read += offset;
// read one chunk that will reach EOF and return TREXIO_END code // 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(rc == TREXIO_END);
assert(chunk_read == eof_read_size_check);
assert(index_read[4*size_r-1] == 0); assert(index_read[4*size_r-1] == 0);
assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset)); assert(index_read[4*offset_data_read] == 4 * (int32_t) (offset_file_read-offset));

View File

@ -200,6 +200,7 @@ subroutine test_read(file_name, back_end)
integer(4) :: index_sparse_mo_2e_int_eri(4,20) integer(4) :: index_sparse_mo_2e_int_eri(4,20)
double precision :: value_sparse_mo_2e_int_eri(20) double precision :: value_sparse_mo_2e_int_eri(20)
integer(8) :: read_buf_size = 10 integer(8) :: read_buf_size = 10
integer(8) :: read_buf_size_save = 10
integer(8) :: offset_read = 40 integer(8) :: offset_read = 40
integer(8) :: offset_data_read = 5 integer(8) :: offset_data_read = 5
integer(8) :: offset_eof = 97 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, & 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), & index_sparse_mo_2e_int_eri(1, offset_data_read + 1), &
value_sparse_mo_2e_int_eri(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) call trexio_assert(rc, TREXIO_SUCCESS)
if (index_sparse_mo_2e_int_eri(1, 1) == 0 .and. & 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 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, & 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), & index_sparse_mo_2e_int_eri(1, offset_data_eof + 1), &
value_sparse_mo_2e_int_eri(offset_data_eof + 1)) value_sparse_mo_2e_int_eri(offset_data_eof + 1))
call trexio_assert(rc, TREXIO_END)
!do i = 1,20 !do i = 1,20
! write(*,*) index_sparse_mo_2e_int_eri(1,i) ! write(*,*) index_sparse_mo_2e_int_eri(1,i)
!enddo !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_read + 1) == offset_read*4 + 1 .and. &
index_sparse_mo_2e_int_eri(1, offset_data_eof + 1) == offset_eof*4 + 1) then index_sparse_mo_2e_int_eri(1, offset_data_eof + 1) == offset_eof*4 + 1) then
write(*,*) 'SUCCESS READ SPARSE DATA EOF' write(*,*) 'SUCCESS READ SPARSE DATA EOF'
read_buf_size = read_buf_size_save
else else
print *, 'FAILURE SPARSE DATA EOF CHECK' print *, 'FAILURE SPARSE DATA EOF CHECK'
call exit(-1) call exit(-1)