Skip to content

Inconsistent interface of hpsi and spsi #5133

Description

@Cstandardlib

Describe the Code Quality Issue

In hsolver module, the encapsulated interfaces of hpsi_func and spsi_func are different, which is confusing when passing in/out parameters.

auto hpsi_func = [hm, ngk_pointer](T* hpsi_out,
                                           T* psi_in,
                                           const int nband_in,
                                           const int nbasis_in,
                                           const int band_index1,
                                           const int band_index2) {
            ModuleBase::timer::tick("David", "hpsi_func");

            // Convert "pointer data stucture" to a psi::Psi object
            auto psi_iter_wrapper = psi::Psi<T, Device>(psi_in, 1, nband_in, nbasis_in, ngk_pointer);

            psi::Range bands_range(true, 0, band_index1, band_index2);

            using hpsi_info = typename hamilt::Operator<T, Device>::hpsi_info;
            hpsi_info info(&psi_iter_wrapper, bands_range, hpsi_out);
            hm->ops->hPsi(info);

            ModuleBase::timer::tick("David", "hpsi_func");
        };

        /// wrap spsi into lambda function, Matrix \times blockvector
        /// spsi(X, SX, nrow, npw, nbands)
        auto spsi_func = [hm](const T* psi_in, T* spsi_out,
                               const int nrow,  // dimension of spsi: nbands * nrow
                               const int npw,   // number of plane waves
                               const int nbands // number of bands
                            ){
            ModuleBase::timer::tick("David", "spsi_func");
            // sPsi determines S=I or not by GlobalV::use_uspp inside
            hm->sPsi(psi_in, spsi_out, nrow, npw, nbands);
            ModuleBase::timer::tick("David", "spsi_func");
        };

The in/out parameters should be in the same order.

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions