From 9d1ffc4cb64e031d34f4f274efa662c3ebfde4e2 Mon Sep 17 00:00:00 2001 From: q-posev <45995097+q-posev@users.noreply.github.com> Date: Mon, 14 Jun 2021 07:35:37 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20TREX-CoE?= =?UTF-8?q?/trexio@cdf25b41621a5f05e8a605f7e0f8824592cc486c=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.html | 4 +- index.html | 4 +- templator_front.html | 273 ++++++++++++++++++++++++++++--------------- templator_hdf5.html | 40 +++---- templator_text.html | 100 ++++++++-------- 5 files changed, 254 insertions(+), 167 deletions(-) diff --git a/README.html b/README.html index 6924990..843d76c 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -341,7 +341,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-06-11 Fri 07:56

+

Created: 2021-06-14 Mon 07:35

Validate

diff --git a/index.html b/index.html index 6924990..843d76c 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -341,7 +341,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-06-11 Fri 07:56

+

Created: 2021-06-14 Mon 07:35

Validate

diff --git a/templator_front.html b/templator_front.html index 8793b2b..b622868 100644 --- a/templator_front.html +++ b/templator_front.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Front end API @@ -333,47 +333,47 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 Coding conventions

+
+

1 Coding conventions

  • integer types will be defined using types given in stdint.h
  • @@ -388,8 +388,8 @@ for the JavaScript code in this tag.
-
-

1.1 Memory allocation

+
+

1.1 Memory allocation

Memory allocation of structures can be facilitated by using the @@ -424,8 +424,8 @@ The maximum string size for the filenames is 4096 characters.

-
-

2 Front end

+
+

2 Front end

All calls to TREXIO are thread-safe. @@ -433,10 +433,10 @@ TREXIO front end is modular, which simplifies implementation of new back ends.

-
-

2.1 Error handling

+
+

2.1 Error handling

- +
@@ -727,8 +727,8 @@ The text strings are extracted from the previous table. -
-

2.2 Back ends

+
+

2.2 Back ends

TREXIO has several back ends: @@ -758,8 +758,8 @@ lines that correspond to the TREXIO_JSON back end (not implemented

-
-

2.3 Read/write behavior

+
+

2.3 Read/write behavior

Every time a reading function is called, the data is read from the @@ -787,8 +787,8 @@ concurrent programs, the behavior is not specified.

-
-

2.4 TREXIO file type

+
+

2.4 TREXIO file type

trexio_s is the the main type for TREXIO files, visible to the users @@ -810,18 +810,19 @@ TREXIO files will have as a first argument the TREXIO file handle.

struct trexio_s {
-  char*             file_name;
+  char              file_name[TREXIO_MAX_FILENAME_LENGTH];
   pthread_mutex_t   thread_lock;
   back_end_t        back_end;
   char              mode;
-  char              padding[7];   /* Ensures the proper alignment of back ends */
+  bool              one_based;
+  char              padding[6];   /* Ensures the proper alignment of back ends */
 };
 
-
-

2.5 Polymorphism of the file handle

+
+

2.5 Polymorphism of the file handle

Polymorphism of the trexio_t type is handled by ensuring that the @@ -840,8 +841,8 @@ corresponding types for all back ends can be safely casted to

-
-

2.6 File opening

+
+

2.6 File opening

trexio_open creates a new TREXIO file or opens existing one. @@ -870,11 +871,13 @@ output:

-Note: the file_name in TEXT back end actually corresponds to the name of the folder where .txt -data files are stored. The actual name of each .txt file corresponds to the group name provided in -trex.config (e.g. nucleus.txt for nuclei-related data). -These names are populated by the generator.py (i.e. they are hard-coded), which is why the user -should tend to avoid renaming the .txt data files. +Note: the file_name in TEXT back end actually corresponds to the +name of the directory where .txt data files are stored. The +actual name of each .txt file corresponds to the group name +provided in trex.config (e.g. nucleus.txt for nuclei-related +data). These names are populated by the generator.py (i.e. they +are hard-coded), which is why the user should tend to avoid +renaming the .txt data files.

@@ -918,16 +921,15 @@ should tend to avoid renaming the .txt data files. /* Data for the parent type */ - result->file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char); strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH); if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { - free(result->file_name); free(result); return NULL; } result->back_end = back_end; result->mode = mode; + result->one_based = false; // Need to be flipped in Fortran interface int irc = pthread_mutex_init ( &(result->thread_lock), NULL); assert (irc == 0); @@ -954,7 +956,6 @@ should tend to avoid renaming the .txt data files. } if (rc != TREXIO_SUCCESS) { - free(result->file_name); free(result); return NULL; } @@ -980,7 +981,6 @@ should tend to avoid renaming the .txt data files. } if (rc != TREXIO_SUCCESS) { - free(result->file_name); free(result); return NULL; } @@ -1002,11 +1002,39 @@ should tend to avoid renaming the .txt data files. end interface
+ +

+Because arrays are zero-based in Fortran, we need to set a flag to +know if we need to shift by 1 arrays of indices. +

+ +
+
trexio_exit_code trexio_set_one_based(trexio_t* file)
+{
+  if (file == NULL)
+    return TREXIO_FILE_ERROR;
+
+  file->one_based = true;
+
+  return TREXIO_SUCCESS;
+}
+
+
+ +
+
interface
+   integer function trexio_set_one_based(trex_file) bind(C)
+     use, intrinsic :: iso_c_binding
+     integer(8), intent(in), value :: trex_file
+   end function trexio_set_one_based
+end interface
+
+
-
-

2.7 File closing

+
+

2.7 File closing

trexio_close closes an existing trexio_t file. @@ -1051,7 +1079,6 @@ output: } if (rc != TREXIO_SUCCESS) { - FREE(file->file_name); FREE(file); return rc; } @@ -1078,8 +1105,6 @@ output: /* Terminate front end */ - FREE(file->file_name); - int irc = pthread_mutex_destroy( &(file->thread_lock) ); free(file); @@ -1104,8 +1129,8 @@ output:

-
-

2.8 C helper functions

+
+

2.8 C helper functions

#+beginsrc c :tangle prefixfront.c @@ -1143,8 +1168,8 @@ for (int i=0; i<strmaxnum; i++){

-
-

3 Templates for front end

+
+

3 Templates for front end

Consider the following block of trex.json: @@ -1333,8 +1358,8 @@ or double precision for integer and floating point numbers.

-
-

3.1 Templates for front end has/read/write a dimension

+
+

3.1 Templates for front end has/read/write a dimension

This section concerns API calls related to dimensioning variables. @@ -1403,8 +1428,8 @@ This section concerns API calls related to dimensioning variables.

-
-

3.1.1 C templates for front end

+
+

3.1.1 C templates for front end

The C templates that correspond to each of the abovementioned @@ -1599,8 +1624,8 @@ precision (see Table above).

-
-

3.1.2 Fortran templates for front end

+
+

3.1.2 Fortran templates for front end

The Fortran templates that provide an access to the C API calls from Fortran. @@ -1686,8 +1711,8 @@ These templates are based on the use of iso_c_binding. Pointers hav

-
-

3.2 Templates for front end has/read/write a dataset

+
+

3.2 Templates for front end has/read/write a dataset

This section concerns API calls related to datasets. @@ -1756,8 +1781,8 @@ This section concerns API calls related to datasets.

-
-

3.2.1 C templates for front end

+
+

3.2.1 C templates for front end

The C templates that correspond to each of the abovementioned functions can be found below. @@ -1781,6 +1806,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T /* Error handling for this call is added by the generator */ rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + if (rc != TREXIO_SUCCESS) return rc; if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; @@ -1789,22 +1815,36 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T assert(file->back_end < TREXIO_INVALID_BACK_END); + rc = TREXIO_FAILURE; switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_text_read_$group_dset$(file, $group_dset$, rank, dims); break; case TREXIO_HDF5: - return trexio_hdf5_read_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_hdf5_read_$group_dset$(file, $group_dset$, rank, dims); break; /* case TREXIO_JSON: - return trexio_json_read_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_json_read_$group_dset$(file, $group_dset$, rank, dims); break; */ } - return TREXIO_FAILURE; + if (rc != TREXIO_SUCCESS) return rc; + + /* Handle index type */ + if ($is_index$) { + uint64_t dim_size = 1; + for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; + } + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$[i] += ($group_dset_dtype_single$) 1; + } + } + + return TREXIO_SUCCESS; }

@@ -1823,30 +1863,56 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T /* Error handling for this call is added by the generator */ rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + if (rc != TREXIO_SUCCESS) return rc; if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; uint32_t rank = $group_dset_rank$; uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + $group_dset_dtype_double$* $group_dset$_p = $group_dset$; + + /* Handle index type */ + if ($is_index$) { + + uint64_t dim_size = 1; + for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; + } + + $group_dset$_p = CALLOC(dim_size, $group_dset_dtype_double$); + if ($group_dset$_p == NULL) return TREXIO_ALLOCATION_FAILED; + + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$_p[i] = $group_dset$_p[i] - ($group_dset_dtype_single$) 1; + } + } + assert(file->back_end < TREXIO_INVALID_BACK_END); + rc = TREXIO_FAILURE; switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_write_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_text_write_$group_dset$(file, $group_dset$_p, rank, dims); break; case TREXIO_HDF5: - return trexio_hdf5_write_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_p, rank, dims); break; /* case TREXIO_JSON: - return trexio_json_write_$group_dset$(file, $group_dset$, rank, dims); + rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims); break; */ } - return TREXIO_FAILURE; + + /* Handle index type */ + if ($is_index$) { + FREE($group_dset$_p); + } + + return rc; }
@@ -1871,7 +1937,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; uint64_t dim_size = 1; - for (unsigned int i=0; i<rank; ++i){ + for (uint32_t i=0; i<rank; ++i){ dim_size *= dims[i]; } @@ -1903,8 +1969,14 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T return rc; } - for (uint64_t i=0; i<dim_size; ++i){ - $group_dset$[i] = ($group_dset_dtype_single$) $group_dset$_64[i]; + if ($is_index$) { + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$[i] = ($group_dset_dtype_single$) $group_dset$_64[i] + ($group_dset_dtype_single$) 1; + } + } else { + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$[i] = ($group_dset_dtype_single$) $group_dset$_64[i]; + } } FREE($group_dset$_64); @@ -1934,7 +2006,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; uint64_t dim_size = 1; - for (unsigned int i=0; i<rank; ++i){ + for (uint32_t i=0; i<rank; ++i){ dim_size *= dims[i]; } @@ -1942,8 +2014,14 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T if ($group_dset$_64 == NULL) return TREXIO_ALLOCATION_FAILED; /* A type conversion from single precision to double reqired since back end only accepts 64-bit data */ - for (uint64_t i=0; i<dim_size; ++i){ - $group_dset$_64[i] = ($group_dset_dtype_double$) $group_dset$[i]; + if ($is_index$) { + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$_64[i] = ($group_dset_dtype_double$) $group_dset$[i] - ($group_dset_dtype_double$) 1; + } + } else { + for (uint64_t i=0; i<dim_size; ++i){ + $group_dset$_64[i] = ($group_dset_dtype_double$) $group_dset$[i]; + } } assert(file->back_end < TREXIO_INVALID_BACK_END); @@ -2023,8 +2101,8 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
-
-

3.2.2 Fortran templates for front end

+
+

3.2.2 Fortran templates for front end

The Fortran templates that provide an access to the C API calls from Fortran. @@ -2110,8 +2188,8 @@ These templates are based on the use of iso_c_binding. Pointers hav

-
-

3.3 Sparse data structures

+
+

3.3 Sparse data structures

Sparse data structures are used typically for large tensors such as @@ -2253,8 +2331,8 @@ For the values,

-
-

4 Fortran helper/wrapper functions

+
+

4 Fortran helper/wrapper functions

The function below adapts the original C-based trexio_open for Fortran. @@ -2268,13 +2346,22 @@ Note, that Fortran interface calls the main TREXIO API, which is wr integer(8) function trexio_open (filename, mode, backend) use, intrinsic :: iso_c_binding implicit none - character(len=*) :: filename - character, intent(in), value :: mode + character(len=*) :: filename + character, intent(in), value :: mode integer(trexio_backend), intent(in), value :: backend character(len=len_trim(filename)+1) :: filename_c + integer :: rc filename_c = trim(filename) // c_null_char trexio_open = trexio_open_c(filename_c, mode, backend) + if (trexio_open == 0_8) then + return + endif + rc = trexio_set_one_based(trexio_open) + if (rc /= TREXIO_SUCCESS) then + rc = trexio_close(trexio_open) + trexio_open = 0_8 + endif end function trexio_open

@@ -2283,7 +2370,7 @@ Note, that Fortran interface calls the main TREXIO API, which is wr

Author: TREX-CoE

-

Created: 2021-06-11 Fri 07:56

+

Created: 2021-06-14 Mon 07:35

Validate

diff --git a/templator_hdf5.html b/templator_hdf5.html index 65bf1e3..7f62e86 100644 --- a/templator_hdf5.html +++ b/templator_hdf5.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + HDF5 back end @@ -311,25 +311,25 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 HDF5 back end

+
+

1 HDF5 back end

-
-

1.1 Template for HDF5 definitions

+
+

1.1 Template for HDF5 definitions

#define $GROUP$_GROUP_NAME          "$group$"
@@ -340,8 +340,8 @@ for the JavaScript code in this tag.
 
-
-

1.2 Template for HDF5 structures

+
+

1.2 Template for HDF5 structures

typedef struct trexio_hdf5_s {
@@ -356,8 +356,8 @@ for the JavaScript code in this tag.
 
-
-

1.3 Template for HDF5 init/deinit

+
+

1.3 Template for HDF5 init/deinit

trexio_exit_code
@@ -437,8 +437,8 @@ for the JavaScript code in this tag.
 
-
-

1.4 Template for HDF5 has/read/write a number

+
+

1.4 Template for HDF5 has/read/write a number

trexio_exit_code
@@ -560,8 +560,8 @@ for the JavaScript code in this tag.
 
-
-

1.5 Template for HDF5 has/read/write a dataset

+
+

1.5 Template for HDF5 has/read/write a dataset

trexio_exit_code
@@ -695,7 +695,7 @@ for the JavaScript code in this tag.
 

Author: TREX-CoE

-

Created: 2021-06-11 Fri 07:56

+

Created: 2021-06-14 Mon 07:35

Validate

diff --git a/templator_text.html b/templator_text.html index befab5a..33e5264 100644 --- a/templator_text.html +++ b/templator_text.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TEXT back end @@ -311,24 +311,24 @@ for the JavaScript code in this tag.

Table of Contents

-
-

1 TEXT back end

+
+

1 TEXT back end

The "file" produced by the text back end is a directory with one @@ -359,8 +359,8 @@ The file is written when closed, or when the flush function is called.

-
-

1.1 Template for group-related structures in text back end

+
+

1.1 Template for group-related structures in text back end

typedef struct $group$_s {
@@ -376,8 +376,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.2 Template for general structure in text back end

+
+

1.2 Template for general structure in text back end

typedef struct rdm_s {
@@ -403,8 +403,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.3 Initialize function (constant part)

+
+

1.3 Initialize function (constant part)

trexio_exit_code
@@ -505,8 +505,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.4 Deinitialize function (templated part)

+
+

1.4 Deinitialize function (templated part)

trexio_exit_code
@@ -531,8 +531,8 @@ The file is written when closed, or when the flush function is called.
 
-
-

1.5 Template for text read struct

+
+

1.5 Template for text read struct

$group$_t*
@@ -698,8 +698,8 @@ trexio_text_read_$group$ (trexio_text_t* 
 
-
-

1.6 Template for text flush struct

+
+

1.6 Template for text flush struct

trexio_exit_code
@@ -758,8 +758,8 @@ trexio_text_read_$group$ (trexio_text_t* 
 
-
-

1.7 Template for text free memory

+
+

1.7 Template for text free memory

Memory is allocated when reading. The following function frees memory. @@ -795,8 +795,8 @@ Memory is allocated when reading. The following function frees memory.

-
-

1.8 Template for has/read/write the $group_num$ attribute

+
+

1.8 Template for has/read/write the $group_num$ attribute

trexio_exit_code
@@ -858,8 +858,8 @@ Memory is allocated when reading. The following function frees memory.
 
-
-

1.9 Template for has/read/write the $group_dset$ dataset

+
+

1.9 Template for has/read/write the $group_dset$ dataset

The group_dset array is assumed allocated with the appropriate size. @@ -956,12 +956,12 @@ The group_dset array is assumed allocated with the appropriate size

-
-

1.10 RDM struct (hard-coded)

+
+

1.10 RDM struct (hard-coded)

-
-

1.10.1 Read the complete struct

+
+

1.10.1 Read the complete struct

rdm_t* trexio_text_read_rdm(trexio_text_t* const file);
@@ -1056,8 +1056,8 @@ The group_dset array is assumed allocated with the appropriate size
 
-
-

1.10.2 Flush the complete struct

+
+

1.10.2 Flush the complete struct

trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
@@ -1099,8 +1099,8 @@ The group_dset array is assumed allocated with the appropriate size
 
-
-

1.10.3 Free memory

+
+

1.10.3 Free memory

Memory is allocated when reading. The followig function frees memory. @@ -1136,8 +1136,8 @@ Memory is allocated when reading. The followig function frees memory.

-
-

1.10.4 Read/Write the onee attribute

+
+

1.10.4 Read/Write the onee attribute

The one_e array is assumed allocated with the appropriate size. @@ -1203,8 +1203,8 @@ The one_e array is assumed allocated with the appropriate size.

-
-

1.10.5 Read/Write the twoe attribute

+
+

1.10.5 Read/Write the twoe attribute

two_e is a sparse data structure, which can be too large to fit @@ -1312,7 +1312,7 @@ file for each sparse float structure.

Author: TREX-CoE

-

Created: 2021-06-11 Fri 07:56

+

Created: 2021-06-14 Mon 07:35

Validate