mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-25 06:31:43 +02:00
Working text back end [to test]
This commit is contained in:
parent
a2fee3164b
commit
aa47ae4c2e
@ -1313,7 +1313,7 @@ trexio_text_delete_$group$ (trexio_t* const file)
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** Source code for the determinant part
|
||||
** Source code for the determinant part
|
||||
|
||||
Each array is stored in a separate =.txt= file due to the fact that determinant I/O has to be decoupled
|
||||
from conventional write/read/flush behaviour of the TEXT back end. Chunks are used to read/write the data
|
||||
@ -1334,7 +1334,7 @@ trexio_exit_code trexio_text_read_determinant_list(
|
||||
const uint32_t rank,
|
||||
const uint64_t* dims,
|
||||
int64_t* const eof_read_size,
|
||||
int64_t* const list)
|
||||
int64_t* const list)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (eof_read_size == NULL) return TREXIO_INVALID_ARG_5;
|
||||
@ -1353,9 +1353,9 @@ trexio_exit_code trexio_text_read_determinant_list(
|
||||
FILE* f = fopen(file_full_path, "r");
|
||||
if(f == NULL) return TREXIO_FILE_ERROR;
|
||||
|
||||
/* Specify the line length in order to offset properly.
|
||||
Each 64-bit integer takes at most 10 slots and requires one space,
|
||||
we have int_num integers per up-spin determinant,
|
||||
/* Specify the line length in order to offset properly.
|
||||
Each 64-bit integer takes at most 10 slots and requires one space,
|
||||
we have int_num integers per up-spin determinant,
|
||||
then this number is doubled because we have the same number for down-spin electrons,
|
||||
and then one newline char.
|
||||
,*/
|
||||
@ -1366,49 +1366,43 @@ trexio_exit_code trexio_text_read_determinant_list(
|
||||
|
||||
/* Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF */
|
||||
int rc;
|
||||
|
||||
//char buffer[16];
|
||||
char* buffer = CALLOC(line_length+1, char);
|
||||
|
||||
uint64_t count = 0UL;
|
||||
int shift = 0;
|
||||
/* Declare fixed buffer which will be used to read the determinant string <a1 a2 ... a/\ b1 b2 ... b\/> */
|
||||
char buffer[1024];
|
||||
uint32_t buf_size = sizeof(buffer);
|
||||
/* Parameters to post-process the buffer and to get bit fields integers */
|
||||
uint64_t accum = 0UL;
|
||||
for (uint64_t i=0UL; i < (uint64_t) dims[0]; ++i) {
|
||||
uint32_t shift_int64 = 10U;
|
||||
/* Counter for number of elements beind processed */
|
||||
uint64_t count = 0UL;
|
||||
for (uint64_t i=0UL; i < dims[0]; ++i) {
|
||||
|
||||
accum = 0UL;
|
||||
memset(buffer, 0, line_length+1); // sizeof(buffer)); //1024);
|
||||
accum = 0UL;
|
||||
memset(buffer, 0, buf_size);
|
||||
|
||||
if(fgets(buffer, line_length, f) == NULL){
|
||||
if(fgets(buffer, buf_size-1, f) == NULL){
|
||||
|
||||
fclose(f);
|
||||
FREE(buffer);
|
||||
*eof_read_size = count;
|
||||
return TREXIO_END;
|
||||
fclose(f);
|
||||
,*eof_read_size = count;
|
||||
return TREXIO_END;
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
/* The format string is not anymore static but rather dynamic (the number of ints depend on the mo_num)
|
||||
Thus, we parse the buffer string int_num*2 times to get the bit field determinants.
|
||||
*/
|
||||
|
||||
for (int32_t j=0; j<dims[1]; ++j) {
|
||||
rc = sscanf(buffer, "%10" SCNd64 "%n", list + i + j, &shift);
|
||||
if(rc <= 0) {
|
||||
fclose(f);
|
||||
FREE(buffer);
|
||||
return TREXIO_FAILURE;
|
||||
}
|
||||
buffer += shift;
|
||||
accum += shift;
|
||||
/* The format string is not anymore static but rather dynamic (the number of ints depend on the mo_num)
|
||||
Thus, we parse the buffer string int_num*2 times to get the bit field determinants.
|
||||
,*/
|
||||
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
|
||||
rc = sscanf(buffer+accum, "%10" SCNd64, list + i + j);
|
||||
if(rc <= 0) {
|
||||
fclose(f);
|
||||
return TREXIO_FAILURE;
|
||||
}
|
||||
|
||||
accum += shift_int64 + 1;
|
||||
count += 1UL;
|
||||
buffer -= accum;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
FREE(buffer);
|
||||
|
||||
/* Close the TXT file */
|
||||
rc = fclose(f);
|
||||
if(rc != 0) return TREXIO_FILE_ERROR;
|
||||
@ -1422,7 +1416,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
|
||||
const int64_t offset_file,
|
||||
const uint32_t rank,
|
||||
const uint64_t* dims,
|
||||
const int64_t* list)
|
||||
const int64_t* list)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
|
||||
@ -1443,7 +1437,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
|
||||
/* Write the data in the file and check the return code of fprintf to verify that > 0 bytes have been written */
|
||||
int rc;
|
||||
for (uint64_t i=0UL; i < dims[0]; ++i) {
|
||||
|
||||
|
||||
/* The loop below is needed to write a line with int bit fields for alpha and beta electrons */
|
||||
for (uint32_t j=0; j < (uint32_t) dims[1]; ++j) {
|
||||
rc = fprintf(f, "%10" PRId64 " ", *(list + i + j));
|
||||
@ -1453,7 +1447,7 @@ trexio_exit_code trexio_text_write_determinant_list(trexio_t* const file,
|
||||
}
|
||||
}
|
||||
fprintf(f, "%s", "\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Close the TXT file */
|
||||
|
Loading…
Reference in New Issue
Block a user