Skip to content

Commit 8d0100e

Browse files
committed
m_low and m_up calculation wasn't considering the media_matrix matrix as transposed when it should
1 parent 73aea27 commit 8d0100e

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

modules/cuqdyn-c/src/cuqdyn.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
100100
const long m = SM_COLUMNS_D(observed_data);
101101

102102
SUNMatrix resid_loo = NULL;
103-
MatrixArray media_matrix = create_matrix_array(m - 1);
103+
MatrixArray media_matrix = create_matrix_array(m - 1); // We will save transposed matrices inside the array
104104
SUNMatrix predicted_params_matrix = NULL;
105105
N_Vector initial_params = New_Serial(config->ode_expr.p_count);
106106

@@ -131,20 +131,7 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
131131
long min_iters_per_node = (long) ((m - 1) / (long) nproc);
132132
long remainder = (m - 1) % (long) nproc;
133133

134-
// Old and optimal version. It accepts any number of processes but causes deadlock when the number of processes
135-
// is not a divisor of m - 1 due to the use of MPI_Barrier(MPI_COMM_WORLD);
136-
// if (remainder > rank)
137-
// {
138-
// iterations = min_iters_per_node;
139-
// start_index = rank * iterations + 1;
140-
// }
141-
// else
142-
// {
143-
// iterations = min_iters_per_node;
144-
// start_index = (remainder * (min_iters_per_node + 1)) + ((rank - remainder) * min_iters_per_node) + 1;
145-
// }
146-
147-
// New version. Only iterates over every row if the number of processes is a divisor of m - 1
134+
// Only iterates over every column if the number of processes is a divisor of m - 1
148135
if (remainder != 0 && rank == 0)
149136
{
150137
fprintf(stderr, "Number of processes is not a divisor of m - 1. Please use a number of processes that is a "
@@ -254,7 +241,8 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
254241
return NULL;
255242
}
256243

257-
SUNMatrix predicted_data_median = matrix_array_get_median(media_matrix);
244+
// media_matrix is transposed so predicted data median is also transposed
245+
TransposedStates predicted_data_median = matrix_array_get_median(media_matrix);
258246
N_Vector predicted_params_median = get_matrix_cols_median(predicted_params_matrix);
259247

260248
double alp = 0.05;
@@ -284,10 +272,10 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
284272
for (int k = 1; k < m; ++k)
285273
{
286274
SM_ELEMENT_D(matrix_array_get_index(m_low, k - 1), i, j) =
287-
SM_ELEMENT_D(matrix_array_get_index(media_matrix, k - 1), i, j) - SM_ELEMENT_D(resid_loo, k, j);
275+
SM_ELEMENT_D(matrix_array_get_index(media_matrix, k - 1), j, i) - SM_ELEMENT_D(resid_loo, k, j);
288276

289277
SM_ELEMENT_D(matrix_array_get_index(m_up, k - 1), i, j) =
290-
SM_ELEMENT_D(matrix_array_get_index(media_matrix, k - 1), i, j) + SM_ELEMENT_D(resid_loo, k, j);
278+
SM_ELEMENT_D(matrix_array_get_index(media_matrix, k - 1), j, i) + SM_ELEMENT_D(resid_loo, k, j);
291279
}
292280

293281
SM_ELEMENT_D(q_low, i, j) = quantile(matrix_array_depth_vector_at(m_low, i, j), alp);

0 commit comments

Comments
 (0)