Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computational inefficiency #198

Open
ofloveandhate opened this issue Sep 8, 2024 · 8 comments
Open

computational inefficiency #198

ofloveandhate opened this issue Sep 8, 2024 · 8 comments

Comments

@ofloveandhate
Copy link
Contributor

I found some pessimizations in explicit_predictors.hpp, in FullStep(). A temp vector is set to 0 when it doesn't need to be. It can just be set to the first of them, and then the loops can run from 1 to bla instead of from 0 to bla. this is probably a fairly important improvement to make.

@ofloveandhate
Copy link
Contributor Author

ofloveandhate commented Sep 8, 2024

I think there's a mathematical error in this code, from explicit_predictors.hpp 741:

// TODO this random vector should not be made fresh every time.  especiallyif the numeric type is mpfr_complex!
Vec<ComplexType> randy = RandomOfUnits<ComplexType>(numVariables_);
Vec<ComplexType> temp_soln = LUref.solve(randy);

norm_J = NumErrorT(dhdxref.norm());
norm_J_inverse = NumErrorT(temp_soln.norm());

@ofloveandhate
Copy link
Contributor Author

No, this is actually correct. But doing that extra LU is potentially VERY expensive. do we really need this? Is there a better way?

@ofloveandhate
Copy link
Contributor Author

I think that the ODE predictor information, the numbers for the Butcher tables, etc, should be written in at compile time. Refactor to use a typetraits system?

@ofloveandhate
Copy link
Contributor Author

EvalRHS() overwrites the columns of K. It does not add to them. Is it pointless to set K to 0 before calling this function?

In FullStep, we tell EvalRHS the stage. Does EvalRHS already have the logic for "on stage 0, just overwrite; other stages add"?

@ofloveandhate
Copy link
Contributor Author

ofloveandhate commented Sep 8, 2024

Why do stages later than 0 NOT re-use the LU decomposition member variable? Are we saving the one for stage 0 for something special?

S.SetAndReset<ComplexType>(space, time);

Mat<ComplexType>& dhdxtempref = std::get< Mat<ComplexType> >(dh_dx_temp_);
S.JacobianInPlace(dhdxtempref);
auto LU = dhdxtempref.lu();  //<<<<---- here!!!!

line 886, explicit_predictors in EvalRHS(

@ofloveandhate
Copy link
Contributor Author

Inside all stages, EvalRHS overwrites the stage-th column of K. They both have this line of code:

K.col(stage) = LUref.solve(-dhdtref);

@ofloveandhate
Copy link
Contributor Author

See https://eigen.tuxfamily.org/dox/group__InplaceDecomposition.html, where they describe how to do in-place LU decompositions. This could really be nice.

Todo: rewrite the LU stuff in explicit_predictors.hpp to use In-place. Warning: if there are later things wanting to use the temp matrices and they depend on the previous state of the matrices, using LU will make that code erroneous. Need to be better about describing when a thing is expected to remain something special.

Actually, I think @jbcolli2 did a decent job of making variables for temps that have some purpose beyond their first use, by adding _0_ to their names. So maybe a naming convention? I'd prefer something expressed at compile time, but hey, just names are a good place to start.

@ofloveandhate
Copy link
Contributor Author

in LUPartialPivotDecompositionSuccessful, why doesn't the (0,0) entry come first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant