Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/module_elecstate/module_dm/density_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void DensityMatrix<TK, TR>::init_DMR(Grid_Driver* GridD_in, const UnitCell* ucel
{
tmp_DMR->fix_gamma();
}
tmp_DMR->allocate(true);
tmp_DMR->allocate(nullptr, true);
this->_DMR.push_back(tmp_DMR);
// add another DMR if nspin==2
if (this->_nspin == 2)
Expand Down Expand Up @@ -180,7 +180,7 @@ void DensityMatrix<TK, TR>::init_DMR(Record_adj& ra, const UnitCell* ucell)
{
tmp_DMR->fix_gamma();
}
tmp_DMR->allocate(true);
tmp_DMR->allocate(nullptr, true);
this->_DMR.push_back(tmp_DMR);
// add another DMR if nspin==2
if (this->_nspin == 2)
Expand Down Expand Up @@ -242,7 +242,7 @@ void DensityMatrix<TK, TR>::init_DMR(const hamilt::HContainer<TRShift>& DMR_in)
tmp_DMR->insert_pair(tmp_ap);
}
}
tmp_DMR->allocate(true);
tmp_DMR->allocate(nullptr, true);
this->_DMR.push_back(tmp_DMR);
if(this->_nspin == 2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(Grid_Driver* Gr
// allocate the memory of BaseMatrix in HR, and set the new values to zero
if(std::is_same<TK, double>::value)
{
this->H_V_delta->allocate(true);
this->H_V_delta->allocate(nullptr, true);
}

ModuleBase::timer::tick("DeePKS", "initialize_HR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void hamilt::EkineticNew<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(Grid_Drive
}
}
// allocate the memory of BaseMatrix in HR, and set the new values to zero
this->hR->allocate(true);
this->hR->allocate(nullptr, true);

ModuleBase::timer::tick("EkineticNew", "initialize_HR");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void hamilt::NonlocalNew<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(Grid_Drive
}
}
// allocate the memory of BaseMatrix in HR, and set the new values to zero
this->hR->allocate(true);
this->hR->allocate(nullptr, true);

ModuleBase::timer::tick("NonlocalNew", "initialize_HR");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::initialize_SR(Grid_Driver
}
}
// allocate the memory of BaseMatrix in SR, and set the new values to zero
SR->allocate(true);
SR->allocate(nullptr, true);
ModuleBase::timer::tick("OverlapNew", "initialize_SR");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Veff<OperatorLCAO<TK, TR>>::initialize_HR(const UnitCell* ucell_in,
}
}
// allocate the memory of BaseMatrix in HR, and set the new values to zero
this->hR->allocate(true);
this->hR->allocate(nullptr, true);

ModuleBase::timer::tick("Veff", "initialize_HR");
}
Expand Down
8 changes: 4 additions & 4 deletions source/module_hamilt_lcao/module_gint/gint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void Gint::initialize_pvpR(
}// end T1
if(npol == 1)
{
this->hRGint->allocate(0);
this->hRGint->allocate(nullptr, 0);
ModuleBase::Memory::record("Gint::hRGint",this->hRGint->get_memory_size());
// initialize DMRGint with hRGint when NSPIN != 4
for (int is = 0; is < this->DMRGint.size(); is++)
Expand All @@ -511,15 +511,15 @@ void Gint::initialize_pvpR(
}
else
{
this->hRGintCd->allocate(0);
this->hRGintCd->allocate(nullptr, 0);
ModuleBase::Memory::record("Gint::hRGintCd",this->hRGintCd->get_memory_size());
for (int is = 0; is < this->DMRGint.size(); is++)
{
this->DMRGint[is]->allocate(0);
this->DMRGint[is]->allocate(nullptr, 0);
}
ModuleBase::Memory::record("Gint::DMRGint",this->DMRGint[0]->get_memory_size() * this->DMRGint.size());
#ifdef __MPI
this->DMRGint_full->allocate(0);
this->DMRGint_full->allocate(nullptr, 0);
ModuleBase::Memory::record("Gint::DMRGint_full",this->DMRGint_full->get_memory_size());
#endif
}
Expand Down
100 changes: 44 additions & 56 deletions source/module_hamilt_lcao/module_hcontainer/atom_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@ AtomPair<T>::AtomPair(const int& atom_i_, const int& atom_j_, const Parallel_Orb
}
this->row_size = this->paraV->get_row_size(atom_i);
this->col_size = this->paraV->get_col_size(atom_j);
this->ldc = this->paraV->get_col_size();
this->R_index.resize(3, 0);
this->current_R = 0;
if (existed_matrix != nullptr)
{
BaseMatrix<T> tmp(row_size, col_size, (existed_matrix + row_ap * ldc + col_ap));
tmp.set_ldc(this->ldc);
BaseMatrix<T> tmp(row_size, col_size, existed_matrix);
this->values.push_back(tmp);
}
else
{
BaseMatrix<T> tmp(row_size, col_size);
this->values.push_back(tmp);
this->ldc = col_size;
}
}

Expand All @@ -65,23 +62,20 @@ AtomPair<T>::AtomPair(const int& atom_i_,
}
this->row_size = this->paraV->get_row_size(atom_i);
this->col_size = this->paraV->get_col_size(atom_j);
this->ldc = this->paraV->get_col_size();
this->R_index.resize(3, 0);
this->current_R = 0;
this->R_index[0] = rx;
this->R_index[1] = ry;
this->R_index[2] = rz;
if (existed_matrix != nullptr)
{
BaseMatrix<T> tmp(row_size, col_size, (existed_matrix + row_ap * ldc + col_ap));
tmp.set_ldc(this->ldc);
BaseMatrix<T> tmp(row_size, col_size, existed_matrix);
this->values.push_back(tmp);
}
else
{
BaseMatrix<T> tmp(row_size, col_size);
this->values.push_back(tmp);
this->ldc = col_size;
}
}
// direct save whole matrix of atom-pair
Expand All @@ -103,16 +97,13 @@ AtomPair<T>::AtomPair(const int& atom_i_,
this->current_R = 0;
if (existed_matrix != nullptr)
{
this->ldc = row_atom_begin[natom] - row_atom_begin[0];
BaseMatrix<T> tmp(row_size, col_size, (existed_matrix + row_ap * ldc + col_ap));
tmp.set_ldc(this->ldc);
BaseMatrix<T> tmp(row_size, col_size, existed_matrix);
this->values.push_back(tmp);
}
else
{
BaseMatrix<T> tmp(row_size, col_size);
this->values.push_back(tmp);
this->ldc = col_size;
}
}
//
Expand Down Expand Up @@ -140,16 +131,13 @@ AtomPair<T>::AtomPair(const int& atom_i_,
this->R_index[2] = rz;
if (existed_matrix != nullptr)
{
this->ldc = row_atom_begin[natom] - row_atom_begin[0];
BaseMatrix<T> tmp(row_size, col_size, (existed_matrix + row_ap * ldc + col_ap));
tmp.set_ldc(this->ldc);
BaseMatrix<T> tmp(row_size, col_size, existed_matrix);
this->values.push_back(tmp);
}
else
{
BaseMatrix<T> tmp(row_size, col_size);
this->values.push_back(tmp);
this->ldc = col_size;
}
}

Expand All @@ -160,28 +148,51 @@ AtomPair<T>::AtomPair(const int& atom_i_, const int& atom_j_) : atom_i(atom_i_),

// copy constructor
template <typename T>
AtomPair<T>::AtomPair(const AtomPair<T>& other)
AtomPair<T>::AtomPair(const AtomPair<T>& other, T* data_pointer)
: R_index(other.R_index),
values(other.values),
paraV(other.paraV),
current_R(other.current_R),
atom_i(other.atom_i),
atom_j(other.atom_j),
row_ap(other.row_ap),
col_ap(other.col_ap),
row_size(other.row_size),
col_size(other.col_size),
ldc(other.ldc)
col_size(other.col_size)
{
if(data_pointer == nullptr)
{
this->values = other.values;
}
else
{
this->values.reserve(other.values.size());
for(int value=0;value<other.values.size();++value)
{
hamilt::BaseMatrix<T> tmp(row_size, col_size, data_pointer);
this->values.push_back(tmp);
data_pointer += this->get_size();
}
}
}

//allocate
template <typename T>
void AtomPair<T>::allocate(bool is_zero)
void AtomPair<T>::allocate(T* data_array, bool is_zero)
{
for(int value=0;value<this->values.size();++value)
if(data_array == nullptr)
{
for(int value=0;value<this->values.size();++value)
{
this->values[value].allocate(nullptr, is_zero);
}
}
else
{
this->values[value].allocate(is_zero);
for(int value=0;value<this->values.size();++value)
{
this->values[value].allocate(data_array, is_zero);
data_array += this->get_size();
}
}
}

Expand Down Expand Up @@ -211,7 +222,6 @@ AtomPair<T>& AtomPair<T>::operator=(const AtomPair<T>& other)
col_ap = other.col_ap;
row_size = other.row_size;
col_size = other.col_size;
ldc = other.ldc;
}
return *this;
}
Expand All @@ -228,8 +238,7 @@ AtomPair<T>::AtomPair(AtomPair<T>&& other) noexcept
row_ap(other.row_ap),
col_ap(other.col_ap),
row_size(other.row_size),
col_size(other.col_size),
ldc(other.ldc)
col_size(other.col_size)
{
other.paraV = nullptr;
}
Expand All @@ -251,7 +260,6 @@ AtomPair<T>& AtomPair<T>::operator=(AtomPair<T>&& other) noexcept
col_ap = other.col_ap;
row_size = other.row_size;
col_size = other.col_size;
ldc = other.ldc;
}
return *this;
}
Expand Down Expand Up @@ -367,7 +375,7 @@ BaseMatrix<T>& AtomPair<T>::get_HR_values(int rx_in, int ry_in, int rz_in)
R_index.push_back(ry_in);
R_index.push_back(rz_in);
values.push_back(BaseMatrix<T>(this->row_size, this->col_size));
values.back().allocate(true);
values.back().allocate(nullptr, true);
// return the last BaseMatrix reference in values
return this->values.back();
}
Expand Down Expand Up @@ -511,7 +519,7 @@ void AtomPair<T>::merge_to_gamma()
{
if(empty)
{
tmp.allocate(true);
tmp.allocate(nullptr, true);
empty = false;
}
tmp.add_array(this->values[i].get_pointer());
Expand All @@ -520,8 +528,6 @@ void AtomPair<T>::merge_to_gamma()
this->values.clear();
this->values.push_back(tmp);

this->ldc = this->col_size;

this->current_R = 0;
}

Expand All @@ -548,7 +554,7 @@ void AtomPair<T>::add_to_matrix(std::complex<T>* hk,
BlasConnector::axpy(this->col_size, kphase.real(), hr_tmp, 1, hk_real_pointer, 2);
BlasConnector::axpy(this->col_size, kphase.imag(), hr_tmp, 1, hk_imag_pointer, 2);
hk_tmp += ld_hk;
hr_tmp += this->ldc;
hr_tmp += this->col_size;
}
}
// column major
Expand All @@ -562,7 +568,7 @@ void AtomPair<T>::add_to_matrix(std::complex<T>* hk,
BlasConnector::axpy(this->col_size, kphase.real(), hr_tmp, 1, hk_real_pointer, ld_hk_2);
BlasConnector::axpy(this->col_size, kphase.imag(), hr_tmp, 1, hk_imag_pointer, ld_hk_2);
hk_tmp ++;
hr_tmp += this->ldc;
hr_tmp += this->col_size;
}
}
}
Expand All @@ -586,23 +592,13 @@ void AtomPair<T>::add_to_matrix(T* hk, const int ld_hk, const T& kphase, const i
hk_tmp[nu] += matrix.get_value(mu, nu) * kphase;
}*/
hk_tmp += ld_hk;
hr_tmp += this->ldc;
hr_tmp += this->col_size;
}
}
// column major
else if (hk_type == 1)
{
hk_tmp += this->col_ap * ld_hk + this->row_ap;
/*for (int nu = 0; nu < this->col_size; nu++)
{
BlasConnector::axpy(this->row_size, kphase, hr_tmp, this->ldc, hk_tmp, 1);
for (int mu = 0; mu < this->row_size; mu++)
{
hk_tmp[mu] += matrix.get_value(mu, nu) * kphase;
}
hk_tmp += ld_hk;
hr_tmp++;
}*/
for (int mu = 0; mu < this->row_size; mu++)
{
BlasConnector::axpy(this->col_size, kphase, hr_tmp, 1, hk_tmp, ld_hk);
Expand All @@ -611,7 +607,7 @@ void AtomPair<T>::add_to_matrix(T* hk, const int ld_hk, const T& kphase, const i
hk_tmp[mu] += matrix.get_value(mu, nu) * kphase;
}*/
++hk_tmp;
hr_tmp += this->ldc;
hr_tmp += this->col_size;
}
}
}
Expand Down Expand Up @@ -639,18 +635,10 @@ void AtomPair<T>::add_to_array(std::complex<T>* array, const std::complex<T>& kp
}

template <typename T>
T& AtomPair<T>::get_matrix_value(const size_t& i_row_global, const size_t& j_col_global) const
std::tuple<std::vector<int>, T*> AtomPair<T>::get_matrix_values(int ir) const
{
int i_row_local = this->paraV == nullptr ? i_row_global : this->paraV->global2local_row(i_row_global);
int j_col_local = this->paraV == nullptr ? j_col_global : this->paraV->global2local_col(j_col_global);
#ifdef __DEBUG
assert(i_row_local != -1 && j_col_local != -1);
assert(current_R < this->values.size());
assert(current_R >= 0);
#endif
size_t i_row_in = i_row_local - row_ap;
size_t j_col_in = j_col_local - col_ap;
return this->values[current_R].get_value(i_row_in, j_col_in);
if(ir<0) ir = this->current_R;
return std::tuple<std::vector<int>, T*>({this->row_ap, this->row_size, this->col_ap, this->col_size}, this->values[ir].get_pointer());
}

// interface for get (rx, ry, rz) of index-th R-index in this->R_index, the return should be int[3]
Expand Down
Loading