1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00
This commit is contained in:
Anthony Scemama 2021-03-13 00:56:16 +01:00
parent e6a211127c
commit 455168efc6
3 changed files with 39 additions and 176 deletions

View File

@ -1,4 +1,3 @@
/* [[file:trexio_text.org::*File prefixes][File prefixes:4]] */
/* This file was generated from the trexio.org org-mode file.
To generate it, open trexio.org in Emacs and execute
M-x org-babel-tangle
@ -7,9 +6,7 @@
#include "trexio_text.h"
/* File prefixes:4 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:2]] */
trexio_exit_code trexio_text_init(trexio_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -52,9 +49,7 @@ trexio_exit_code trexio_text_init(trexio_t* file) {
return TREXIO_SUCCESS;
}
/* Init/deinit functions:2 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:4]] */
trexio_exit_code trexio_text_lock(trexio_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -73,9 +68,7 @@ trexio_exit_code trexio_text_lock(trexio_t* file) {
return TREXIO_SUCCESS;
}
/* Init/deinit functions:4 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:6]] */
trexio_exit_code trexio_text_finalize(trexio_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -88,9 +81,7 @@ trexio_exit_code trexio_text_finalize(trexio_t* file) {
return TREXIO_SUCCESS;
}
/* Init/deinit functions:6 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:8]] */
trexio_exit_code trexio_text_unlock(trexio_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -109,9 +100,7 @@ trexio_exit_code trexio_text_unlock(trexio_t* file) {
close(f->lock_file);
return TREXIO_SUCCESS;
}
/* Init/deinit functions:8 ends here */
/* [[file:trexio_text.org::*Read the struct][Read the struct:2]] */
#define DEBUG printf("%s : line %d\n", __FILE__, __LINE__);
nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) {
@ -182,9 +171,9 @@ DEBUG
}
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
uint j=-1;
unsigned int j=-1;
rc = fscanf(f, "%s %u", buffer, &j);
if ((rc != 2) || (strcmp(buffer, "dims_charge") != 0) || (j!=i)) {
FREE(buffer);
@ -227,9 +216,9 @@ DEBUG
}
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
uint j=-1;
unsigned int j=-1;
rc = fscanf(f, "%s %u", buffer, &j);
if ((rc != 2) || (strcmp(buffer, "dims_coord") != 0) || (j!=i)) {
FREE(buffer);
@ -367,9 +356,7 @@ DEBUG
file->nucleus = nucleus;
return nucleus;
}
/* Read the struct:2 ends here */
/* [[file:trexio_text.org::*Flush the struct][Flush the struct:2]] */
trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -389,7 +376,7 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
fprintf(f, "rank_charge %d\n", nucleus->rank_charge);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
fprintf(f, "dims_charge %d %ld\n", i, nucleus->dims_charge[i]);
size_charge *= nucleus->dims_charge[i];
}
@ -397,7 +384,7 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
fprintf(f, "rank_coord %d\n", nucleus->rank_coord);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
fprintf(f, "dims_coord %d %ld\n", i, nucleus->dims_coord[i]);
size_coord *= nucleus->dims_coord[i];
}
@ -417,9 +404,7 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
file->nucleus->to_flush = 0;
return TREXIO_SUCCESS;
}
/* Flush the struct:2 ends here */
/* [[file:trexio_text.org::*Free memory][Free memory:2]] */
trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -449,9 +434,7 @@ trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) {
FREE (nucleus);
return TREXIO_SUCCESS;
}
/* Free memory:2 ends here */
/* [[file:trexio_text.org::*Read/Write the num attribute][Read/Write the num attribute:2]] */
trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -480,9 +463,7 @@ trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint6
return TREXIO_SUCCESS;
}
/* Read/Write the num attribute:2 ends here */
/* [[file:trexio_text.org::*Read/Write the coord attribute][Read/Write the coord attribute:2]] */
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -494,7 +475,7 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
if (rank != nucleus->rank_coord) return TREXIO_INVALID_ARG_3;
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
for (unsigned int i=0; i<rank; i++){
if (dims[i] != nucleus->dims_coord[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
@ -523,7 +504,7 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
nucleus->rank_coord = rank;
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
nucleus->dims_coord[i] = dims[i];
dim_size *= dims[i];
}
@ -537,9 +518,7 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
nucleus->to_flush = 1;
return TREXIO_SUCCESS;
}
/* Read/Write the coord attribute:2 ends here */
/* [[file:trexio_text.org::*Read/Write the charge attribute][Read/Write the charge attribute:2]] */
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -551,7 +530,7 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
if (rank != nucleus->rank_charge) return TREXIO_INVALID_ARG_3;
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
for (unsigned int i=0; i<rank; i++){
if (dims[i] != nucleus->dims_charge[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
@ -580,7 +559,7 @@ trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const do
nucleus->rank_charge = rank;
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
nucleus->dims_charge[i] = dims[i];
dim_size *= dims[i];
}
@ -594,9 +573,7 @@ trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const do
nucleus->to_flush = 1;
return TREXIO_SUCCESS;
}
/* Read/Write the charge attribute:2 ends here */
/* [[file:trexio_text.org::*Read the complete struct][Read the complete struct:2]] */
rdm_t* trexio_text_read_rdm(trexio_text_t* file) {
if (file == NULL) return NULL;
@ -676,9 +653,7 @@ rdm_t* trexio_text_read_rdm(trexio_text_t* file) {
file->rdm = rdm ;
return rdm;
}
/* Read the complete struct:2 ends here */
/* [[file:trexio_text.org::*Flush the complete struct][Flush the complete struct:2]] */
trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -709,9 +684,7 @@ trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file) {
file->rdm->to_flush = 0;
return TREXIO_SUCCESS;
}
/* Flush the complete struct:2 ends here */
/* [[file:trexio_text.org::*Free memory][Free memory:2]] */
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -741,9 +714,7 @@ trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) {
file->rdm = NULL;
return TREXIO_SUCCESS;
}
/* Free memory:2 ends here */
/* [[file:trexio_text.org::*Read/Write the one_e attribute][Read/Write the one_e attribute:2]] */
trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e, const uint64_t dim_one_e) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -778,9 +749,7 @@ trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double*
rdm->to_flush = 1;
return TREXIO_SUCCESS;
}
/* Read/Write the one_e attribute:2 ends here */
/* [[file:trexio_text.org::*Read/Write the two_e attribute][Read/Write the two_e attribute:2]] */
trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, int64_t* index, double* value) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -845,4 +814,3 @@ trexio_exit_code trexio_text_buffered_write_rdm_two_e(const trexio_t* file, cons
return TREXIO_SUCCESS;
}
/* Read/Write the two_e attribute:2 ends here */

View File

@ -1,4 +1,3 @@
/* [[file:trexio_text.org::*File prefixes][File prefixes:3]] */
/* This file was generated from the trexio.org org-mode file.
To generate it, open trexio.org in Emacs and execute
M-x org-babel-tangle
@ -21,11 +20,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
/* File prefixes:3 ends here */
/* Structs for blocks */
/* [[file:trexio_text.org::*Structs for blocks][Structs for blocks:1]] */
typedef struct nucleus_s {
FILE* file;
double* coord;
@ -52,12 +47,7 @@ typedef struct rdm_s {
char* two_e_file_name;
int to_flush;
} rdm_t;
/* Structs for blocks:1 ends here */
/* Structs for the text back end */
/* [[file:trexio_text.org::*Structs for the text back end][Structs for the text back end:1]] */
typedef struct trexio_text_s {
trexio_t parent ;
int lock_file;
@ -66,128 +56,40 @@ typedef struct trexio_text_s {
electron_t* electron;
rdm_t* rdm;
} trexio_text_t;
/* Structs for the text back end:1 ends here */
/* Init/deinit functions */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:1]] */
trexio_exit_code trexio_text_init(trexio_t* file);
/* Init/deinit functions:1 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:3]] */
trexio_exit_code trexio_text_lock(trexio_t* file);
/* Init/deinit functions:3 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:5]] */
trexio_exit_code trexio_text_finalize(trexio_t* file);
/* Init/deinit functions:5 ends here */
/* [[file:trexio_text.org::*Init/deinit functions][Init/deinit functions:7]] */
trexio_exit_code trexio_text_unlock(trexio_t* file);
/* Init/deinit functions:7 ends here */
/* Read the struct */
/* [[file:trexio_text.org::*Read the struct][Read the struct:1]] */
nucleus_t* trexio_text_read_nucleus(trexio_text_t* file);
/* Read the struct:1 ends here */
/* Flush the struct */
/* [[file:trexio_text.org::*Flush the struct][Flush the struct:1]] */
trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file);
/* Flush the struct:1 ends here */
/* Free memory */
/* Memory is allocated when reading. The following function frees memory. */
/* [[file:trexio_text.org::*Free memory][Free memory:1]] */
trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file);
/* Free memory:1 ends here */
/* Read/Write the num attribute */
/* [[file:trexio_text.org::*Read/Write the num attribute][Read/Write the num attribute:1]] */
trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num);
trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num);
/* Read/Write the num attribute:1 ends here */
/* Read/Write the coord attribute */
/* The ~coord~ array is assumed allocated with the appropriate size. */
/* [[file:trexio_text.org::*Read/Write the coord attribute][Read/Write the coord attribute:1]] */
trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims);
/* Read/Write the coord attribute:1 ends here */
/* Read/Write the charge attribute */
/* The ~charge~ array is assumed allocated with the appropriate size. */
/* [[file:trexio_text.org::*Read/Write the charge attribute][Read/Write the charge attribute:1]] */
trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims);
/* Read/Write the charge attribute:1 ends here */
/* Read the complete struct */
/* [[file:trexio_text.org::*Read the complete struct][Read the complete struct:1]] */
rdm_t* trexio_text_read_rdm(trexio_text_t* file);
/* Read the complete struct:1 ends here */
/* Flush the complete struct */
/* [[file:trexio_text.org::*Flush the complete struct][Flush the complete struct:1]] */
trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file);
/* Flush the complete struct:1 ends here */
/* Free memory */
/* Memory is allocated when reading. The followig function frees memory. */
/* [[file:trexio_text.org::*Free memory][Free memory:1]] */
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file);
/* Free memory:1 ends here */
/* Read/Write the one_e attribute */
/* The ~one_e~ array is assumed allocated with the appropriate size. */
/* [[file:trexio_text.org::*Read/Write the one_e attribute][Read/Write the one_e attribute:1]] */
trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e, const uint64_t dim_one_e);
trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double* one_e, const uint64_t dim_one_e);
/* Read/Write the one_e attribute:1 ends here */
/* Read/Write the two_e attribute */
/* ~two_e~ is a sparse data structure, which can be too large to fit */
/* in memory. So we provide functions to read and write it by */
/* chunks. */
/* In the text back end, the easiest way to do it is to create a */
/* file for each sparse float structure. */
/* [[file:trexio_text.org::*Read/Write the two_e attribute][Read/Write the two_e attribute:1]] */
trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, int64_t* index, double* value);
trexio_exit_code trexio_text_buffered_write_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, const int64_t* index, const double* value);
/* Read/Write the two_e attribute:1 ends here */
/* File suffixes :noxport: */
/* [[file:trexio_text.org::*File suffixes][File suffixes:1]] */
#endif
/* File suffixes:1 ends here */

View File

@ -100,13 +100,6 @@ typedef struct rdm_s {
int to_flush;
} rdm_t;
#+end_src
*** TO DO
- to_flush = 1 in write
- to_flush = 0 when flushed
- name
*** Structs for the text back end
#+begin_src c :tangle trexio_text.h
@ -321,11 +314,11 @@ DEBUG
}
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
uint j=-1;
unsigned int j=-1;
rc = fscanf(f, "%s %u", buffer, &j);
if ((rc != 1) || (strcmp(buffer, "dims_charge") != 0) || (j!=i)) {
if ((rc != 2) || (strcmp(buffer, "dims_charge") != 0) || (j!=i)) {
FREE(buffer);
FREE(file_name);
FREE(nucleus);
@ -366,11 +359,11 @@ DEBUG
}
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
uint j=-1;
unsigned int j=-1;
rc = fscanf(f, "%s %u", buffer, &j);
if ((rc != 1) || (strcmp(buffer, "dims_coord") != 0) || (j!=i)) {
if ((rc != 2) || (strcmp(buffer, "dims_coord") != 0) || (j!=i)) {
FREE(buffer);
FREE(file_name);
FREE(nucleus);
@ -534,7 +527,7 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
fprintf(f, "rank_charge %d\n", nucleus->rank_charge);
uint64_t size_charge = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
fprintf(f, "dims_charge %d %ld\n", i, nucleus->dims_charge[i]);
size_charge *= nucleus->dims_charge[i];
}
@ -542,7 +535,7 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) {
fprintf(f, "rank_coord %d\n", nucleus->rank_coord);
uint64_t size_coord = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
fprintf(f, "dims_coord %d %ld\n", i, nucleus->dims_coord[i]);
size_coord *= nucleus->dims_coord[i];
}
@ -573,33 +566,33 @@ trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file);
#+end_src
#+begin_src c :tangle trexio_text.c
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) {
trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_exit_code rc;
if (file->parent.mode != 'r') {
rc = trexio_text_flush_rdm(file);
rc = trexio_text_flush_nucleus(file);
if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE;
}
rdm_t* rdm = file->rdm;
if (rdm == NULL) return TREXIO_SUCCESS;
nucleus_t* nucleus = file->nucleus;
if (nucleus == NULL) return TREXIO_SUCCESS;
if (rdm->file != NULL) {
fclose(rdm->file);
rdm->file = NULL;
if (nucleus->file != NULL) {
fclose(nucleus->file);
nucleus->file = NULL;
}
if (rdm->one_e != NULL) {
FREE (rdm->one_e);
if (nucleus->coord != NULL) {
FREE (nucleus->coord);
}
if (rdm->two_e_file_name != NULL) {
FREE (rdm->two_e_file_name);
if (nucleus->charge != NULL) {
FREE (nucleus->charge);
}
free (rdm);
file->rdm = NULL;
FREE (nucleus);
return TREXIO_SUCCESS;
}
#+end_src
@ -663,7 +656,7 @@ trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* co
if (rank != nucleus->rank_coord) return TREXIO_INVALID_ARG_3;
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
for (unsigned int i=0; i<rank; i++){
if (dims[i] != nucleus->dims_coord[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
@ -692,7 +685,7 @@ trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const dou
nucleus->rank_coord = rank;
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_coord; i++){
for (unsigned int i=0; i<nucleus->rank_coord; i++){
nucleus->dims_coord[i] = dims[i];
dim_size *= dims[i];
}
@ -728,7 +721,7 @@ trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* c
if (rank != nucleus->rank_charge) return TREXIO_INVALID_ARG_3;
uint64_t dim_size = 1;
for (uint i=0; i<rank; i++){
for (unsigned int i=0; i<rank; i++){
if (dims[i] != nucleus->dims_charge[i]) return TREXIO_INVALID_ARG_4;
dim_size *= dims[i];
}
@ -757,7 +750,7 @@ trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const do
nucleus->rank_charge = rank;
uint64_t dim_size = 1;
for (uint i=0; i<nucleus->rank_charge; i++){
for (unsigned int i=0; i<nucleus->rank_charge; i++){
nucleus->dims_charge[i] = dims[i];
dim_size *= dims[i];
}