-
Notifications
You must be signed in to change notification settings - Fork 145
Refactor IO cube (Useful Information: excellent example for discussions and actions among ABACUS developers) #5362
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
Conversation
kirk0830
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your effort, however, as I have mentioned in issue #5191 , the function read_cube and write_cube themselves should not have any knowledge about how to handle grid parallelism.
For my preference, I prone not agree with ideas bundling many parameters together then pass it to a function that will not fully use it, it is not in aspect of waste but additional dependency risk.
|
According to the suggestion of @kirk0830 , I rewrite this PR in the the following way (coincident to the prefered option by @jinzx10 for item 1):
|
@maki49 Hi, I think most of problems have been solved in a satisfying way, then may be the last one: I think the names read/write_grid are not clear enough. Will you prefer something like read/write_vdata_palgrid? in which palgrid stands for the parallized grid, and vdata for volumetric data. |
Make sense. I've renamed them. |
kirk0830
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have finished my review, if there is no further code changes.
This PR refactors the clean read/write_cube functions, allowing other developers to fully trust and use them as basic utility functions. The argument list of the read/write_cube functions will also not need to be modified for a considerable period of time, as the collection and distribution operations have been moved to its superior, the functions that call it.
From the principle of program design, there is still a concern that the Pgrid class object seems to be used to carry parallel information and contains broadcast and reduce methods for operating on charge density data. However, the object managing the charge density data (the Charge class object) does not have the capability to perform broadcast and reduce operations on its data, thus failing to achieve a cleaner abstraction, meaning that there will inevitably be coupling between Parallel_Grid and Charge based on the current class design.
However, eliminating the dependency on Parallel_Grid can be considered in stages for more things (but this has already exceeded the scope of this PR):
-
(Noting that it is actually unnatural from the principle of code design to call a function named read_vdata_palgrid in the chg_init function. At the most basic level) while retaining the Parallel_Grid class and before implementing the methods within it as free functions, it is possible to consider constructing the Parallel_Grid object within a function that will perform charge density collection and distribution operations, at the cost of that function requiring all variables to construct the Parallel_Grid object.
-
(Further) transform the collection and distribution operation functions into free functions, and then call them as needed (at this point, the dependency on the Parallel_Grid class has been removed).
-
Store the data required for parallel distribution as attributes within the data management object, and let the data management object handle the collection and distribution of data (at this point, better encapsulation and abstraction can be achieved).
|
This ia an excellent example for discussions and actions among ABACUS developers. |
* remove the redundant info in read_cube * remove redundant code in write_cube * make Pgrid a serial-or-parallel grid class * Pgrid contains nxyz * [pre-commit.ci lite] apply automatic fixes * rename reduce * rewrite io_cube * rename previous read/write_cube as read/write_grid * remove CubeInfo and xyz-zxy permutation * minor interface changes * revert the call in rho_sym to fix SDFT failure * rename r/w_grid as r/w_vdata_palgrid * [pre-commit.ci lite] apply automatic fixes * add rank parameter to pgrid.bcast to fix SDFT --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
fix #5191
Finally I made io_cube depend on
Pgrid.I think this class is actually pretty well-designed (after a little modification). It can be made as the key structure of grid info. It encapsulates all the parallel communication (whose copy in
write_cubehave been deleted), while the serial version is just like a struct containing grid sizes.With
Pgrid, all thosenxyz, bxyz, nplane, startzas well as the caller-sidepw_rhoandpw_bighave been dropped.In case of the file-comparison test booms, spin and efermi info are kept in
write_cube.However, the logic of
iterto append seems strange: shouldn't the cube file and the grid info correspond one-to-one?abacus-develop/source/module_io/write_cube.cpp
Lines 38 to 45 in 7a29e2f