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

Unify linear solvers #2848

Merged
merged 11 commits into from
Oct 13, 2020
Merged

Unify linear solvers #2848

merged 11 commits into from
Oct 13, 2020

Conversation

atgeirr
Copy link
Member

@atgeirr atgeirr commented Oct 10, 2020

This is the last (I hope) take on this, replacing #2706. There are still two requests @blattms made in that PR that need to be addressed here:

If we skip --use-cpr like in this PR then to the very least I would suggest having "cpr" here.
But "--linear-solver-configuration=cpr" is stil a lot more to type than "--use-cpr"

Part of my goal was to get rid of parameters that were redundant or came into conflict with each other. Adding "cpr" to the set of strings accepted by "--linear-solver-configuration" is no problem, just not sure if we should choose the trueimpes or quasiimpes as default (probably trueimpes, as that is what you get with --use-cpr right now). However keeping the "--use-cpr" will then conflict with the other one potentially. Would it address your concern if we shortened "--linear-solver-configuration" to "--linear-solver" or even "--linsolver"?

How do I select AMG as preconditioner (formerly --use-amg), I think that proved good for some 2-phase problems of @totto82?

I think adding the option string "amg" to the above-discussed parameter (and an associated setup like for "ilu0" and the "cpr_*" options) should handle this. Could you advise about the actual case that benefited from it @totto82 or @blattms? Would be good to verify that the new is no worse.

The replacement consists of using the FlexibleSolver code.
When using the ParallelOverlappingILU0 it is not necessary to fix the overlap rows.
@atgeirr
Copy link
Member Author

atgeirr commented Oct 10, 2020

jenkins build this serial please

@atgeirr atgeirr mentioned this pull request Oct 10, 2020
@atgeirr
Copy link
Member Author

atgeirr commented Oct 10, 2020

benchmark please

@ytelses
Copy link

ytelses commented Oct 10, 2020

Benchmark result overview:

Test Configuration Relative
opm-git OPM Benchmark: flow_mpi_extra - Threads: 1 1.006
opm-git OPM Benchmark: flow_mpi_extra - Threads: 8 1.005
opm-git OPM Benchmark: flow_mpi_norne - Threads: 1 0.997
opm-git OPM Benchmark: flow_mpi_norne - Threads: 8 0.992
  • Speed-up = Total time master / Total time pull request. Above 1.0 is an improvement. *

View result details @ https://www.ytelses.com/opm/?page=result&id=922

@alfbr
Copy link
Member

alfbr commented Oct 10, 2020

Please note that the variance in results have been significantly reduced, performance differences at the 1% level should be detectable now. In this case, it is clear that there are no significant performance impact of this PR,

Copy link
Member

@bska bska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd personally write the shouldCreateSolver() function using early returns like below, but it's a style issue so I'm not going to insist. Otherwise this looks good to me.


bool shouldCreateSolver() const
{
    // Decide if we should recreate the solver or just do
    // a minimal preconditioner update.
    if (!flexibleSolver_) {
         return true;
    }

    if (this->parameters_.cpr_reuse_setup_ == 0) {
        return true;
    }

    if (this->parameters_.cpr_reuse_setup_ == 1) {
        // Recreate solver on the first iteration of every timestep.
        return this->simulator_.model().newtonMethod().numIterations() == 0;
    }

    if (this->parameters_.cpr_reuse_setup_ == 2) {
        // Recreate solver if the last solve used more than 10 iterations.
        return this->iterations() > 10;
    }

    // Never recreate solver.
    assert(this->parameters_.cpr_reuse_setup_ == 3);

    return false;
}

@atgeirr
Copy link
Member Author

atgeirr commented Oct 11, 2020

write the shouldCreateSolver() function using early returns

I'll adopt your suggestion.

@atgeirr
Copy link
Member Author

atgeirr commented Oct 11, 2020

The following changes have been made:

  • Make the changes suggested by @bska.
  • Refactor setupPropertyTree() and add new option "amg" to --linear-solver-configuration, as requested by @blattms.

I have tested the amg option on Norne, and it seems to work, although slower than either "ilu0" (default) or "cpr_trueimpes" for that case. It could probably benefit from some tuning to be as good as possible for the two-phase cases mentioned where it was good before, such testing should be very easy using the JSON file approach (start testing from the tree printed in the DBG file) with no recompilation. When the best defaults are found, they can be changed in setupPropertyTree.cpp.

The one change I have not made (yet) is changing the parameter name --linear-solver-configuration. I am tempted to change it to --linsolver, but that can be done in a separate PR.

@atgeirr
Copy link
Member Author

atgeirr commented Oct 11, 2020

jenkins build this serial please

Copy link
Member

@bska bska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates to shouldCreateSolver. I just noticed a couple of problems with the new logic, but otherwise it looks good to me.

@atgeirr
Copy link
Member Author

atgeirr commented Oct 11, 2020

jenkins build this serial please

Copy link
Member

@blattms blattms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note, that with the deletion of some of the files we might also be loosing some implemented functionality. Not sure whether this is intended (because they proofed to be bad/not working) or not, but it might be hard to recover it:

  • BlackoilAMG had the option to start the second step on the first coarse level pressure system (now it will be only the finest one).
  • I think some different scaling techniques to recover the pressure system might be lost (or were already lost previously).

There has been a vast amount of refactoring. Please make sure that proper credit is given and that copyright for copied/refactored stuff is correct.

EWOMS_REGISTER_PARAM(TypeTag, int, CprReuseSetup, "Reuse Amg Setup");
EWOMS_REGISTER_PARAM(TypeTag, std::string, LinearSolverConfiguration, "Configuration of solver valid is: ilu0 (default), cpr_quasiimpes, cpr_trueimpes or file (specified in LinearSolverConfigurationJsonFile) ");
EWOMS_REGISTER_PARAM(TypeTag, int, CprReuseSetup, "Reuse preconditioner setup. Valid options are 0: recreate the preconditioner for every linear solve, 1: recreate once every timestep, 2: recreate if last linear solve took more than 10 iterations, 3: never recreate");
EWOMS_REGISTER_PARAM(TypeTag, std::string, LinearSolverConfiguration, "Configuration of solver. Valid options are: ilu0 (default), cpr_quasiimpes, cpr_trueimpes or file (specified in LinearSolverConfigurationJsonFile) ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an update as it seems to be missing options: (e.g. amg)

@blattms
Copy link
Member

blattms commented Oct 12, 2020

jenkins build this serial please

Not sure: Does this build parallel, too?

@akva2
Copy link
Member

akva2 commented Oct 12, 2020

yes.

@blattms
Copy link
Member

blattms commented Oct 12, 2020

I have another suggestion. Why not skip the --linear-solver-configuration-file option and just intrepret --linear-solver-configuration as a file if the name matches ".*.json"?

@atgeirr
Copy link
Member Author

atgeirr commented Oct 12, 2020

I have another suggestion. Why not skip the --linear-solver-configuration-file option and just intrepret --linear-solver-configuration as a file if the name matches ".*.json"?

I like that idea. Should we also shorten it to --linsolver?

@blattms
Copy link
Member

blattms commented Oct 12, 2020 via email

@atgeirr
Copy link
Member Author

atgeirr commented Oct 12, 2020

The shorter the better, if you ask me.

I have implemented that (--linsolver). I have also removed the separate file parameter, replacing it with passing "--linsolver=options.json" as suggested. The doc string has been updated.

There has been a vast amount of refactoring. Please make sure that proper credit is given and that copyright for copied/refactored stuff is correct.

I have added 2020 SINTEF and Equinor copyright to the ISTLSolver.hpp file. However I have not done any other additions to copyrights in the PR. Looking at the files changed by this PR, I see no other significant enough changes to warrant adding a SINTEF copyright, the rest is just removing stuff. Did you have any particular concern?

With that, I hope this can be merged when green again.

@atgeirr
Copy link
Member Author

atgeirr commented Oct 12, 2020

jenkins build this serial please

@atgeirr
Copy link
Member Author

atgeirr commented Oct 12, 2020

I made a serious mistake in one of the last commits, and it is a very embarrassing one. I'll amend ASAP...

@atgeirr
Copy link
Member Author

atgeirr commented Oct 12, 2020

jenkins build this serial please

@blattms blattms merged commit 884e02c into OPM:master Oct 13, 2020
{
prm_ = setupPropertyTree<TypeTag>(parameters_);
}
prm_ = setupPropertyTree<TypeTag>(parameters_);
const auto& gridForConn = simulator_.vanguard().grid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object (gridForConn) is unused now.

@atgeirr atgeirr deleted the unify-linsolve-only branch October 15, 2020 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants