Skip to content

Refactor spsi interface in hsolver #5204

@Cstandardlib

Description

@Cstandardlib

Describe the Code Quality Issue

The spsi_func in HSolverPW is an encapsulation of sPsi of Hamilt.
It takes 3 dimension parameters:

// sPsi
void sPsi(const T* psi_in, // psi
                      T* spsi,         // spsi
                      const int nrow,  // dimension of spsi: nbands * nrow
                      const int npw,   // number of plane waves
                      const int nbands // number of bands
    ) const;
// spsi_func in hsolver_pw
auto spsi_func = [hm](const T* psi_in, T* spsi_out,
                               const int ld_spsi,  // Leading dimension of spsi. Dimension of SX: nbands * nrow.
                               const int ld_psi,   // Leading dimension of psi. Number of plane waves.
                               const int nvec      // Number of vectors(bands)
                            );

While ld_spsi and ld_psi are two different leading dimensions, in practice they are always the same, so that it is called like

spsi_func(basis + dim*m, &this->spsi[m * dim], dim, dim, 1);

with duplicate argument of leading dimension.
The wrapper could be changed to take uniform leading dimension values of psi-like blocks to eliminate duplicate arguments.

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Identify the specific code file or section with the code quality issue.
  • Investigate the issue and determine the root cause.
  • Research best practices and potential solutions for the identified issue.
  • Refactor the code to improve code quality, following the suggested solution.
  • Ensure the refactored code adheres to the project's coding standards.
  • Test the refactored code to ensure it functions as expected.
  • Update any relevant documentation, if necessary.
  • Submit a pull request with the refactored code and a description of the changes made.

Metadata

Metadata

Assignees

Labels

The Absolute ZeroReduce the "entropy" of the code to 0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions