-
Notifications
You must be signed in to change notification settings - Fork 198
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
Question: Externally owned data in hypre_CSRMatrix #1095
Comments
I am re-opening this to update it to what seems to be working. I have only medium confidence here, so grain of salt. Any input on whether this is valid would still be appreciated. The setup is as follows. This is not a direct copy of the code but should get the point across.
A few of these steps are non-trivial and potentially wrong. Step 6 allocates the Step 13 and the layouts of |
@ictmay thank you for the update and apologize for the delay. On the surface, the logic seems correct including your comments about column ordering (except for remaining column indices being sorted in ascending order: that is not strictly necessary but advisable). Is this implementation openly available somewhere in AMP so we can take a look? We can also discuss about adding Thank you! |
@victorapm No worries on the delay, and thank you for getting back to us. For access to the source I'll have to talk to Bobby. I only work on the internal (restricted enclave) version, and I'm not sure what all has made it into the externally viewable version. Regarding the The column map isn't so large (except when it is...), so it could easily fall into the same category as the A nice solution that would avoid most of the touchy steps above, though one that would take some non-zero dev time and testing time, would be to make I don't know how often people want to do shallow-copies into Hypre, and without broader demand it makes more sense to have this as an interface we maintain rather than something that gets added to Hypre. |
@victorapm All of the shallow copy code is present in our external code here: Lines 41 -- 43 create the IJMatrix, and the process described above starts on line 136 and continues to the end of the file. |
I am working with the LANL AMP team. We have a parallel CSR matrix format that should be compatible with the Hypre format. Ideally we would wrap our format into a Hypre IJMatrix with a minimal amount of duplicate data.
Question #609 provides some initial information on how to approach this. I have looked at which (de)allocations are guarded by
owns_data
insidehypre_ParCSRMatrixCreate
,hypre_CSRMatrixCreate
, and the matching destroy functions to decide what we should own versus what Hypre should own. The heavy data all lives in thediag
andoffd
blocks.At present I do the following:
IJMatrix
and set type toHYPRE_PARCSR
, do not call initialize.hypre_IJMatrixCreateParCSR
. This sets owns_data inParCSR
to 1 and createsdiag
andoffd
structs.need_aux
to zero inside theIJMatrix->translator
.diag
andoffd
blocks and callhypre_CSRMatrixInitialize
manually. This allocates the->i
field which is not guarded byowns_data
.diag
andoffd
viahypre_CSRMatrixSetDataOwner
.->i
fields.->big_j
,->j
, and->data
fields ofdiag
andoffd
to reference our data. These are all guarded byowns_data
and are the heaviest memory requirements.The issue comes from the
ParCSR->col_map_offd
field. I'd prefer to leaveParCSR->owns_data==1
so that it will manage the setup/teardown of the CSRMatrix structs themselves and then I can just setowns_data
to zero in there. This means that Hypre needs to also own thecol_map_offd
field. The main benefit is thatHYPRE_IJMatrixDestroy
does (seem to) do all of the correct deallocations.That is a long-winded set up to premise a couple of questions:
ParCSR->owns_data=0
and manage more of the setup/teardown on my end?HYPRE_IJMatrixAssemble
to getcol_map_offd
created and filled. The internal functionhypre_IJMatrixAssembleParCSR
does not check the value ofoffd->owns_data
and freesoffd->big_j
yielding an eventual double-free (line 2922 of IJMatrix_parcsr.c).col_map_offd
and rearrangesoffd->j
. What are the exact requirements oncol_map_offd
? It must be more than just a map from local->global indices sinceoffd->j
also gets shuffled.I did add a check for the
offd->owns_data
flag intohypre_IJMatrixAssembleParCSR
, and that does avoid the double-free issue. Surprisingly this allows BoomerAMG to work as a solver, but I think that is a fluke. This doesn't really solve the overall issue. That function still modifies values in thebig_j
andj
arrays that it doesn't own. As a minimal solution it should check theowns_data
flag and throw an error.That's quite the wall of text. I appreciate any help, and please let me know if any clarifications are needed.
The text was updated successfully, but these errors were encountered: