Skip to content

Commit 45d572a

Browse files
committed
step by step
1 parent 6c3e742 commit 45d572a

File tree

190 files changed

+1961
-36348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1961
-36348
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY .)
1010
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY .)
1111
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY .)
1212

13-
add_subdirectory(modules/cvodes_old)
1413
add_subdirectory(modules/sacess)
1514
add_subdirectory(modules/cuqdyn-c)
1615
add_subdirectory(modules/cli)

deps.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
include(FetchContent)
22

3+
# Building v7.30 of CVODES
4+
include(ExternalProject)
5+
6+
FetchContent_Declare(
7+
cvodes
8+
URL https://github.com/LLNL/sundials/releases/download/v7.3.0/cvodes-7.3.0.tar.gz
9+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
10+
)
11+
12+
FetchContent_MakeAvailable(cvodes)
13+
14+
315
# Building GSL dependency
416
find_package(GSL 2.7)
517

modules/cli/src/handlers/solve.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
int handle_solve(int argc, char *argv[]);
20-
void print_matrix(DlsMat mat, FILE *output_file, char *name);
20+
void print_matrix(SUNMatrix mat, FILE *output_file, char *name);
2121
void print_vector(N_Vector vec, FILE *output_file, char *name);
2222

2323
Handler create_solve_handler()
@@ -116,10 +116,10 @@ int handle_solve(int argc, char *argv[])
116116
{
117117

118118
N_Vector params_median = cuqdyn_result->predicted_params_median;
119-
DlsMat data_median = cuqdyn_result->predicted_data_median;
119+
SUNMatrix data_median = cuqdyn_result->predicted_data_median;
120120

121-
DlsMat q_low = cuqdyn_result->q_low;
122-
DlsMat q_up = cuqdyn_result->q_up;
121+
SUNMatrix q_low = cuqdyn_result->q_low;
122+
SUNMatrix q_up = cuqdyn_result->q_up;
123123
N_Vector times = cuqdyn_result->times;
124124

125125
char *output_file_path = malloc(strlen(output_dir) + strlen("/cuqdyn-results.txt") + 1);
@@ -145,7 +145,7 @@ int handle_solve(int argc, char *argv[])
145145
return 0;
146146
}
147147

148-
void print_matrix(DlsMat mat, FILE *output_file, char *name)
148+
void print_matrix(SUNMatrix mat, FILE *output_file, char *name)
149149
{
150150
fprintf(output_file, "[%s]\n", name);
151151
fprintf(output_file, "%ld %ld\n", SM_ROWS_D(mat), SM_COLUMNS_D(mat));

modules/cuqdyn-c/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ target_include_directories(cuqdyn-c
2929
PUBLIC
3030
include
3131
generated
32+
${cvodes_BINARY_DIR}/include
3233
${matio_SOURCE_DIR}/src
3334
${muparser_SOURCE_DIR}/include
3435
${RUST_LIB_DIR}/include
@@ -37,7 +38,9 @@ target_include_directories(cuqdyn-c
3738
target_link_directories(cuqdyn-c PUBLIC ${RUST_TARGET_DIR})
3839

3940
target_link_libraries(cuqdyn-c
41+
PUBLIC
4042
sacess
4143
matio
4244
mexpreval
45+
SUNDIALS::core
4346
)

modules/cuqdyn-c/include/config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#ifndef CONFIG_H
22
#define CONFIG_H
33

4-
#include <sundials_old/sundials_nvector.h>
4+
#include <sundials/sundials_nvector.h>
55

66
typedef struct
77
{
8-
realtype rtol;
8+
sunsunrealtype rtol;
99
N_Vector atol;
1010

1111
} Tolerances;
1212

13-
Tolerances create_tolerances(realtype rtol, N_Vector atol);
13+
Tolerances create_tolerances(sunsunrealtype rtol, N_Vector atol);
1414
void destroy_tolerances(Tolerances);
1515

1616
typedef struct

modules/cuqdyn-c/include/cuqdyn.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
#ifndef CUQDYN_H
22
#define CUQDYN_H
33

4-
#include <sundials_old/sundials_nvector.h>
4+
#include <sundials/sundials_nvector.h>
55

66
#include "ode_solver.h"
77

8-
#define SM_ROWS_D(mat) mat->M
9-
#define SM_COLUMNS_D(mat) mat->N
10-
#define SUNDenseMatrix(m, n) NewDenseMat(m, n)
11-
#define SM_ELEMENT_D(mat, i, j) DENSE_ELEM(mat, i, j)
12-
#define SM_DATA_D(mat) mat->data
13-
#define SUNMatDestroy(mat) DestroyMat(mat)
8+
#define NewDenseMatrix(m, n) SUNDenseMatrix(m, n, get_sundials_ctx())
9+
#define New_Serial(n) N_VNew_Serial(n, get_sundials_ctx())
1410

15-
#define MIth(v, i) NV_Ith_S(v, i - 1) /* i-th vector component i=1..n */
16-
#define MIJth(A, i, j) SM_ELEMENT_D(A, i - 1, j - 1) /* (i,j)-th matrix component i,j=1..n */
11+
SUNContext get_sundials_ctx();
1712

1813
/// Result of the cuqdyn algorithm
1914
typedef struct
2015
{
21-
DlsMat predicted_data_median;
16+
SUNMatrix predicted_data_median;
2217
N_Vector predicted_params_median;
23-
DlsMat q_low;
24-
DlsMat q_up;
18+
SUNMatrix q_low;
19+
SUNMatrix q_up;
2520
N_Vector times;
2621
} CuqdynResult;
2722

28-
CuqdynResult* create_cuqdyn_result(DlsMat predicted_data_median, N_Vector predicted_params_median,
29-
DlsMat q_low, DlsMat q_up, N_Vector times);
23+
CuqdynResult* create_cuqdyn_result(SUNMatrix predicted_data_median, N_Vector predicted_params_median,
24+
SUNMatrix q_low, SUNMatrix q_up, N_Vector times);
3025
void destroy_cuqdyn_result(CuqdynResult* result);
3126
CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, const char *output_file, int rank, int nproc);
3227

@@ -42,22 +37,22 @@ long array_get_index(LongArray array, long index);
4237

4338
typedef struct
4439
{
45-
DlsMat *data;
40+
SUNMatrix *data;
4641
long len;
4742
} MatrixArray;
4843

4944
MatrixArray create_matrix_array(long depth);
5045
void destroy_matrix_array(MatrixArray array);
51-
DlsMat matrix_array_get_index(MatrixArray array, long index);
46+
SUNMatrix matrix_array_get_index(MatrixArray array, long index);
5247
/// Sets the i-th matrix of the array
53-
void matrix_array_set_index(MatrixArray array, long index, DlsMat matrix);
48+
void matrix_array_set_index(MatrixArray array, long index, SUNMatrix matrix);
5449
/// Returns a matrix where the i-th row and j-th column is the median
5550
/// of all the i-th row and j-th column of the matrices inside the array
56-
DlsMat matrix_array_get_median(MatrixArray array);
51+
SUNMatrix matrix_array_get_median(MatrixArray array);
5752
/// Resturns a vector containing the i-th row and j-th column of each matrix inside the array
5853
N_Vector matrix_array_depth_vector_at(MatrixArray array, long i, long j);
5954

6055
/// Creates a vector where the i-th element is the median of the i-th column of the matrix
61-
N_Vector get_matrix_cols_median(DlsMat matrix);
56+
N_Vector get_matrix_cols_median(SUNMatrix matrix);
6257

6358
#endif // CUQDYN_H

modules/cuqdyn-c/include/data_reader.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#ifndef FILE_READER_H
22
#define FILE_READER_H
33

4-
#include <sundials_old/sundials_direct.h>
5-
#include <sundials_old/sundials_nvector.h>
4+
#include <sundials/sundials_nvector.h>
5+
#include <sunmatrix/sunmatrix_dense.h>
66

77
/* This function wich type of data file is being read (.txt or .mat) and
88
* calls the appropriate function to read it.
99
*/
10-
int read_data_file(const char *data_file, N_Vector *t, DlsMat *y);
10+
int read_data_file(const char *data_file, N_Vector *t, SUNMatrix *y);
1111

1212
/*
1313
* The file should be two ints, m and n, and a matrix mxn
@@ -30,7 +30,7 @@ int read_data_file(const char *data_file, N_Vector *t, DlsMat *y);
3030
* . .
3131
* ym0 ym1 ym2 ... ymn
3232
*/
33-
int read_txt_data_file(const char *data_file, N_Vector *t, DlsMat *y);
33+
int read_txt_data_file(const char *data_file, N_Vector *t, SUNMatrix *y);
3434
/*
3535
* The file should be a single matrix mxn
3636
* All the data contained in the matrix is the observed data and has this form:
@@ -50,6 +50,6 @@ int read_txt_data_file(const char *data_file, N_Vector *t, DlsMat *y);
5050
* . .
5151
* ym0 ym1 ym2 ... ymn
5252
*/
53-
int read_mat_data_file(const char *data_file, N_Vector *t, DlsMat *y);
53+
int read_mat_data_file(const char *data_file, N_Vector *t, SUNMatrix *y);
5454

5555
#endif //FILE_READER_H
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef ESS_SOLVER_H
22
#define ESS_SOLVER_H
3+
#include <sundials/sundials_matrix.h>
34

45
/// Executes the ESS solver for a given sacess config file using the given objective function.
56
/// texp, yexp and initial_values are arguments needed to execute certain objective functions, like
67
/// the one defined in lotka_volterra.c.
78
/// rank and nproc are used to define the rank of the process and the number of processes in a MPI environment.
89
N_Vector execute_ess_solver(const char *config_file, const char *output,
9-
N_Vector texp, DlsMat yexp, N_Vector initial_values, int rank, int nproc);
10+
N_Vector texp, SUNMatrix yexp, N_Vector initial_values, int rank, int nproc);
1011

1112
#endif //ESS_SOLVER_H

modules/cuqdyn-c/include/functions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#ifndef LOTKA_VOLTERRA_H
22
#define LOTKA_VOLTERRA_H
3-
#include <sundials_old/sundials_direct.h>
4-
#include <sundials_old/sundials_nvector.h>
3+
#include <sundials/sundials_direct.h>
4+
#include <sundials/sundials_nvector.h>
55

66
#include "config.h"
77

88
void mexpreval_init_wrapper(OdeExpr ode_expr);
99
/// Function used to solve the ODE using cvodes
10-
int ode_model_fun(realtype t, N_Vector y, N_Vector ydot, void *data);
10+
int ode_model_fun(sunsunrealtype t, N_Vector y, N_Vector ydot, void *data);
1111
/// Objetive function for the lotka_volterra problem used by the sacess library
1212
void* ode_model_obj_func(double *x, void *data);
1313

modules/cuqdyn-c/include/matlab.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
N_Vector copy_vector_remove_indices(N_Vector original, LongArray indices);
99
// Return a copy of a matrix removing the indicated rows.
1010
// The indices should be sorted in ascending order and 1-based.
11-
DlsMat copy_matrix_remove_rows(DlsMat matrix, LongArray indices);
11+
SUNMatrix copy_matrix_remove_rows(SUNMatrix matrix, LongArray indices);
1212
// Return a copy of a matrix removing the indicated cols.
1313
// // The indices should be sorted in ascending order and 1-based.
14-
DlsMat copy_matrix_remove_columns(DlsMat matrix, LongArray indices);
14+
SUNMatrix copy_matrix_remove_columns(SUNMatrix matrix, LongArray indices);
1515
// Return a copy of a matrix removing the indicated rows and cols.
1616
// // The indices should be sorted in ascending order and 1-based.
17-
DlsMat copy_matrix_remove_rows_and_columns(DlsMat matrix, LongArray row_indices, LongArray col_indices);
17+
SUNMatrix copy_matrix_remove_rows_and_columns(SUNMatrix matrix, LongArray row_indices, LongArray col_indices);
1818

1919
// Set a row of a matrix with the values of a vector from start (inclusive) to end (exclusive)
20-
void set_matrix_row(DlsMat matrix, N_Vector vec, long row_index, long start, long end);
20+
void set_matrix_row(SUNMatrix matrix, N_Vector vec, long row_index, long start, long end);
2121
// Set a column of a matrix with the values of a vector from start (inclusive) to end (exclusive)
22-
void set_matrix_column(DlsMat matrix, N_Vector vec, long col_index, long start, long end);
22+
void set_matrix_column(SUNMatrix matrix, N_Vector vec, long col_index, long start, long end);
2323

2424
// Copy a row of a matrix into a vector from start (inclusive) to end (exclusive)
25-
N_Vector copy_matrix_row(DlsMat matrix, long row_index, long start, long end);
25+
N_Vector copy_matrix_row(SUNMatrix matrix, long row_index, long start, long end);
2626
// Copy a column of a matrix into a vector from start (inclusive) to end (exclusive)
27-
N_Vector copy_matrix_column(DlsMat matrix, long col_index, long start, long end);
27+
N_Vector copy_matrix_column(SUNMatrix matrix, long col_index, long start, long end);
2828

2929
/*
3030
* Sums matrix a + b. Note that 'b' can have fewer cols or rows than 'a' but not otherwise
3131
* Returns NULL if the dimensions are not compatible
3232
*/
33-
DlsMat sum_two_matrices(DlsMat a, DlsMat b);
33+
SUNMatrix sum_two_matrices(SUNMatrix a, SUNMatrix b);
3434
/*
3535
* Substracts b from a. Note that 'b' can have fewer cols or rows than 'a' but not otherwise
3636
* Returns NULL if the dimensions are not compatible
3737
*/
38-
DlsMat subtract_two_matrices(DlsMat a, DlsMat b);
38+
SUNMatrix subtract_two_matrices(SUNMatrix a, SUNMatrix b);
3939

4040
/*
4141
* For an n-element vector A, quantile computes quantiles by using a sorting-based algorithm:
@@ -53,5 +53,5 @@ DlsMat subtract_two_matrices(DlsMat a, DlsMat b);
5353
* For the quantiles corresponding to the probabilities outside that range,
5454
* quantile assigns the minimum or maximum values of the elements in A.
5555
*/
56-
realtype quantile(N_Vector, realtype);
56+
sunsunrealtype quantile(N_Vector, sunsunrealtype);
5757
#endif //MATLAB_H

0 commit comments

Comments
 (0)