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

Use combined W matrix for primary and secondary data in IQN #2010

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Fujikawas
Copy link
Contributor

@Fujikawas Fujikawas commented Apr 21, 2024

Main changes of this PR

The secondary data is handled together with primary data in the W matrix both in IQN-ILS and IQN-IMVJ method.

Motivation and additional information

Relating to #1996

To do

  • Check if the secondaryDataIDs and _values with only primary data are still needed; -> Yes, for computing V, warn zero update of V;
  • The preconditioning of Wtil should still be done, currently commented out;
  • With the tests with secondary data in Add secondary data to exsting QN tests #2006, this method could work. Still the QNTest9EmptyPartition which is to test SVD-restart failed. Other tests with SVD could work.

Author's checklist

  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I added a test to cover the proposed changes in our test suite.
  • I squashed / am about to squash all commits that should be seen as one.

Reviewers' checklist

  • Does the changelog entry make sense? Is it formatted correctly?
  • Do you understand the code changes?

Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

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

Looks promising!
I guess the SVD changes could go to a separate refactoring PR.

src/acceleration/BaseQNAcceleration.hpp Show resolved Hide resolved
src/acceleration/BaseQNAcceleration.hpp Outdated Show resolved Hide resolved
@Fujikawas Fujikawas requested a review from uekerman April 25, 2024 09:24
Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

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

Nice to see how these changes reduce code duplication 👍

Still a bit of work to do, especially for parallel runs I guess, see below.

Requires a changelog as we now have support of secondary data for IMVJ

Comment on lines 91 to 94
virtual std::vector<int> getDataIDs() const
{
return _dataIDs;
return _primaryDataIDs;
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's change the name of this function as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the whole acceleration method? Other under-relaxation methods also use this function

Copy link
Member

Choose a reason for hiding this comment

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

For Aitken, we in principle also have the primary vs secondary story.

src/acceleration/BaseQNAcceleration.cpp Show resolved Hide resolved
Comment on lines -152 to +170
size_t unknowns = _dimOffsets[utils::IntraComm::getRank() + 1] - _dimOffsets[utils::IntraComm::getRank()];
PRECICE_ASSERT(entries == unknowns, entries, unknowns);
// size_t unknowns = _dimOffsets[utils::IntraComm::getRank() + 1] - _dimOffsets[utils::IntraComm::getRank()];
// PRECICE_ASSERT(entries == unknowns, entries, unknowns); //?
Copy link
Member

Choose a reason for hiding this comment

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

This is a tricky point. Should _dimOffsets include secondary data or not? Probably makes a difference for IMVJ. Let's try to also add a test with secondary data that runs in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's used to initialize the size of Wtil, I would say that the _dimOffsets should include the secondary data. But I'm a little confused with this function now:

int BaseQNAcceleration::getLSSystemRows()
{
if (utils::IntraComm::isParallel()) {
return _dimOffsets.back();
}
return _primaryResiduals.size();
}

In the extended tests, the parallel tests with IMVJ include also secondary data. They could work with this implementation here(secondary data included in the _dimOffsets). This assert should be modified a bit then.

PRECICE_ASSERT(_oldPrimaryResiduals.size() == _oldPrimaryXTilde.size(), _oldPrimaryResiduals.size(), _oldPrimaryXTilde.size());
PRECICE_ASSERT(_primaryValues.size() == _oldPrimaryXTilde.size(), _primaryValues.size(), _oldPrimaryXTilde.size());
PRECICE_ASSERT(_oldPrimaryValues.size() == _oldPrimaryXTilde.size(), _oldPrimaryValues.size(), _oldPrimaryXTilde.size());
PRECICE_ASSERT(_primaryResiduals.size() == _oldPrimaryXTilde.size(), _primaryResiduals.size(), _oldPrimaryXTilde.size());

// assume data structures associated with the LS system can be updated easily.

// scale data values (and secondary data values)
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment correct? I don't think that there is any scaling in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only concatenate happens until the next comment

Comment on lines 319 to +320
_residuals *= _initialRelaxation;
_residuals += _oldValues;
_values = _residuals;
_values = _oldValues + _residuals;
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? Now _residuals has a different value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the test results I didn't see difference. If you mean that the _residuals is not updated here, I see that the _residuals would be calculated from _values and _oldValues by updating differences and is not stored like _values, so the step here still works.

Copy link
Member

Choose a reason for hiding this comment

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

If you mean that the _residuals is not updated here

Exactly.

If such a change is unrelated to this PR, I would always do it separately as a refactoring. Otherwise, we might get side effects.

From the test results I didn't see difference

Remember that tests are never perfect.

@@ -136,7 +136,6 @@ class ParallelMatrixOperations {

PRECICE_ASSERT(_needCyclicComm);
PRECICE_ASSERT(leftMatrix.cols() == q, leftMatrix.cols(), q);
PRECICE_ASSERT(leftMatrix.rows() == rightMatrix.cols(), leftMatrix.rows(), rightMatrix.cols());
Copy link
Member

Choose a reason for hiding this comment

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

Removing this doesn't feel good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the comment it says that For multiplication W_til * Z = J, p = r = n_global, q = m, which is not the case now. I'm not so sure why this assertion is necessary for the operation unless these two variables are mixed used. Need to check.

Comment on lines +61 to +62
PRECICE_WARN_IF(M.cols() < (int) _weights.size(), "Matrix and weights size mismatch, only part of the preconditioning weights will be used.");
PRECICE_WARN_IF(M.cols() > (int) _weights.size(), "Matrix and weights size mismatch, only part of the matrix will be preconditioned.");
Copy link
Member

Choose a reason for hiding this comment

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

Let's find a better solution here. Such warnings will confuse 99% of users.

Copy link
Member

Choose a reason for hiding this comment

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

Could we add unit tests to cover these changes?

Copy link
Member

Choose a reason for hiding this comment

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

I still think it would be better to do these changes in a separate PR before this one. And add unit tests for the new functionality.

Copy link
Contributor Author

@Fujikawas Fujikawas Apr 26, 2024

Choose a reason for hiding this comment

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

How about do one PR for SVD and one preconditioning and one for IQN itself

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.

None yet

2 participants