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

Expose Deep Copy #77

Open
wavefunction91 opened this issue Jul 25, 2023 · 3 comments
Open

Expose Deep Copy #77

wavefunction91 opened this issue Jul 25, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@wavefunction91
Copy link

wavefunction91 commented Jul 25, 2023

Describe the problem you are solving

From what I can tell from the documentation, all copy Matrix-ctors are shallow. The only way (that's obvious to me) to perform a deep copy is via the copy API

slate::Matrix<type> A( /* some parameters */ );
// Do something with A
auto A_copy = A.emptyLike();
A_copy.insertLocalTiles();
slate::copy( A, A_copy );

This is error prone, as it requires that A and A_copy have the same meta data to avoid redistribution, etc. (found a different function, updated the code example) Is there another way to perform a deep copy other than using the copy API?

Describe your proposed solution

If not, it's canonical in these situations to expose a clone API. Per the above:

class Matrix {
  Matrix clone(); // Deep copy of meta data and contents
};

slate::Matrix<type> A( /* some parameters */ );
// Do something with A
auto A_copy = A.clone();
@mgates3
Copy link
Collaborator

mgates3 commented Aug 2, 2023

So A.clone() would create a deep copy of A, basically doing emptyLike, insertLocalTiles, and copy? That seems reasonable.

Currently, copy is the right API, and yes it requires that A and A_copy have the same distribution. copy is a local copy, it doesn't redistribute. There's another function, redistribute, that redistributes.

@mgates3 mgates3 added the enhancement New feature or request label Aug 2, 2023
@wavefunction91
Copy link
Author

So A.clone() would create a deep copy of A.

Yes, I suppose the following syntactic sugar would be

Matrix clone() { 
  auto cpy = this->emptyLike();
  cpy.insertLocalTiles();
  copy( *this, cpy );
  return cpy;
}

Thanks for pointing to redistribute, that will be useful in our application if the passed distribution doesn't align with algorithmic requirements (i.e. heev requiring GridOrder::Col for the time being). Is it possible that redistribute would do the same work as copy if no data redistribution is needed?

@mgates3
Copy link
Collaborator

mgates3 commented Aug 2, 2023

Yes, the intention is that redistribute would effectively just do copy if they have the same distribution. We haven't looked at the efficiency of these routines much, though.

Note that redistribute does not handle changing the block size. ScaLAPACK's redistribute function, P_GEMR2D, is more general in that it can change the block size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants