Skip to content

Commit

Permalink
Merge branch 'develop' into fixLR
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanchen authored Jul 18, 2024
2 parents 86d0eaa + be8f40f commit 1a53320
Show file tree
Hide file tree
Showing 54 changed files with 2,932 additions and 526 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ time.json
*.pyc
__pycache__
abacus.json
*.npy
*.npy

4 changes: 2 additions & 2 deletions examples/bsse/water/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ echo "E_H1: $E_H1" >> result.out
echo "E_H2: $E_H2" >> result.out
result_ref=$(cat result.ref | head -1)
difference=$(echo "scale=12; $result - $result_ref" | bc -l)
difference=$(awk -v a=$difference 'BEGIN{if(a<0) print -1*a; else print a}')
abs_difference=$(echo "scale=12; if ($difference < 0) $difference * -1 else $difference" | bc)

if [[ ! -f H2O_scf.output ]] ||
[[ ! -f O_scf.output ]] ||
Expand All @@ -49,7 +49,7 @@ if [[ ! -f H2O_scf.output ]] ||
[[ ! ( "$(tail -1 OUT.ABACUS/running_scf_O.log)" == " Total Time :"* ) ]] ||
[[ ! ( "$(tail -1 OUT.ABACUS/running_scf_H1.log)" == " Total Time :"* ) ]] ||
[[ ! ( "$(tail -1 OUT.ABACUS/running_scf_H2.log)" == " Total Time :"* ) ]] ||
[[ $difference > 0.000001 ]]
[ $(echo "$abs_difference < 0.00001" | bc) -ne 1 ]
then
echo "job is failed!"
exit 1
Expand Down
8 changes: 0 additions & 8 deletions examples/dft_plus_u/NiO/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@ calculation scf
ecutwfc 100
scf_thr 1.0e-6
scf_nmax 200
out_chg 1

#init_chg file
#out_dos 1
#dos_sigma 0.07
#out_band 1

smearing_method gaussian
smearing_sigma 0.05


mixing_type broyden
mixing_beta 0.4
#mixing_gg0 1.5
Expand Down
1 change: 0 additions & 1 deletion examples/relax/pw_al/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mixing_beta 0.7
scf_thr 1e-08
cal_force 1
cal_stress 1
out_stru 1
kspacing 0.12
chg_extrap second-order #atomic; first-order; second-order; dm:coefficients of SIA
pseudo_dir ../../../tests/PP_ORB
Expand Down
2 changes: 2 additions & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ OBJS_MODULE_RI=conv_coulomb_pot_k.o\

OBJS_PARALLEL=parallel_common.o\
parallel_global.o\
parallel_comm.o\
parallel_grid.o\
parallel_kpoints.o\
parallel_reduce.o\
Expand All @@ -593,6 +594,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
forces.o\
forces_us.o\
forces_nl.o\
forces_cc.o\
fs_nonlocal_tools.o\
force_op.o\
stress_op.o\
Expand Down
1 change: 1 addition & 0 deletions source/module_base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_library(
abfs-vector3_order.cpp
parallel_common.cpp
parallel_global.cpp
parallel_comm.cpp
parallel_reduce.cpp
spherical_bessel_transformer.cpp
cubic_spline.cpp
Expand Down
12 changes: 12 additions & 0 deletions source/module_base/parallel_comm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if defined __MPI

#include "mpi.h"

MPI_Comm POOL_WORLD;
MPI_Comm INTER_POOL = MPI_COMM_NULL; // communicator among different pools
MPI_Comm STO_WORLD;
MPI_Comm PARAPW_WORLD;
MPI_Comm GRID_WORLD; // mohan add 2012-01-13
MPI_Comm DIAG_WORLD; // mohan add 2012-01-13

#endif
14 changes: 7 additions & 7 deletions source/module_base/parallel_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define PARALLEL_COMM_H

#ifdef __MPI
#include "mpi.h"

MPI_Comm POOL_WORLD;
MPI_Comm INTER_POOL = MPI_COMM_NULL; // communicator among different pools
MPI_Comm STO_WORLD;
MPI_Comm PARAPW_WORLD;
MPI_Comm GRID_WORLD; // mohan add 2012-01-13
MPI_Comm DIAG_WORLD; // mohan add 2012-01-13
#include "mpi.h"
extern MPI_Comm POOL_WORLD;
extern MPI_Comm INTER_POOL; // communicator among different pools
extern MPI_Comm STO_WORLD;
extern MPI_Comm PARAPW_WORLD;
extern MPI_Comm GRID_WORLD; // mohan add 2012-01-13
extern MPI_Comm DIAG_WORLD; // mohan add 2012-01-13

#endif

Expand Down
8 changes: 0 additions & 8 deletions source/module_base/parallel_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@

#include <iostream>
#include <thread>

#if defined __MPI
MPI_Comm POOL_WORLD;
MPI_Comm INTER_POOL = MPI_COMM_NULL;
MPI_Comm STO_WORLD;
MPI_Comm PARAPW_WORLD; // qianrui add it for sto-dft 2021-4-14
MPI_Comm GRID_WORLD; // mohan add 2012-01-13z
MPI_Comm DIAG_WORLD; // mohan add 2012-01-13

namespace Parallel_Global
{
int mpi_number = 0;
Expand Down
12 changes: 1 addition & 11 deletions source/module_base/parallel_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
#define PARALLEL_GLOBAL_H

#include <complex>

#ifdef __MPI
#include "mpi.h"
extern MPI_Comm POOL_WORLD;
extern MPI_Comm INTER_POOL; // communicator among different pools
extern MPI_Comm STO_WORLD;
extern MPI_Comm PARAPW_WORLD;
extern MPI_Comm GRID_WORLD; // mohan add 2012-01-13
extern MPI_Comm DIAG_WORLD; // mohan add 2012-01-13

#endif
#include "parallel_comm.h"

// void myProd(std::complex<double> *in,std::complex<double> *inout,int *len,MPI_Datatype *dptr);

Expand Down
2 changes: 1 addition & 1 deletion source/module_base/parallel_reduce.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "parallel_reduce.h"

#include "parallel_global.h"
#include "parallel_comm.h"

#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions source/module_base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ AddTest(
TARGET base_ylmreal
LIBS ${math_libs} device
SOURCES math_ylmreal_test.cpp ../math_ylmreal.cpp ../complexmatrix.cpp ../global_variable.cpp ../ylm.cpp ../realarray.cpp ../timer.cpp ../matrix.cpp ../vector3.h
../parallel_reduce.cpp ../parallel_global.cpp ../parallel_common.cpp
../parallel_reduce.cpp ../parallel_global.cpp ../parallel_comm.cpp ../parallel_common.cpp
../memory.cpp ../libm/branred.cpp ../libm/sincos.cpp
)
AddTest(
Expand Down Expand Up @@ -187,7 +187,7 @@ AddTest(
AddTest(
TARGET clebsch_gordan_coeff_test
SOURCES clebsch_gordan_coeff_test.cpp ../clebsch_gordan_coeff.cpp ../intarray.cpp ../realarray.cpp ../complexmatrix.cpp ../matrix.cpp ../timer.cpp
../math_ylmreal.cpp ../global_variable.cpp ../ylm.cpp ../timer.cpp ../vector3.h ../parallel_reduce.cpp ../parallel_global.cpp ../parallel_common.cpp
../math_ylmreal.cpp ../global_variable.cpp ../ylm.cpp ../timer.cpp ../vector3.h ../parallel_reduce.cpp ../parallel_global.cpp ../parallel_comm.cpp ../parallel_common.cpp
../memory.cpp ../libm/branred.cpp ../libm/sincos.cpp ../inverse_matrix.cpp ../lapack_connector.h
LIBS ${math_libs} device
)
Expand Down
4 changes: 2 additions & 2 deletions source/module_base/test_parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ AddTest(
AddTest(
TARGET base_ParaGlobal
LIBS MPI::MPI_CXX
SOURCES parallel_global_test.cpp ../global_variable.cpp ../parallel_global.cpp
SOURCES parallel_global_test.cpp ../global_variable.cpp ../parallel_global.cpp ../parallel_comm.cpp
)

AddTest(
TARGET base_ParaReduce
LIBS MPI::MPI_CXX
SOURCES parallel_reduce_test.cpp ../global_variable.cpp ../parallel_global.cpp ../parallel_common.cpp ../parallel_reduce.cpp
SOURCES parallel_reduce_test.cpp ../global_variable.cpp ../parallel_global.cpp ../parallel_comm.cpp ../parallel_common.cpp ../parallel_reduce.cpp
)

install(FILES parallel_common_test.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
1 change: 1 addition & 0 deletions source/module_basis/module_pw/kernels/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ AddTest(
SOURCES pw_op_test.cpp
../../../../module_base/tool_quit.cpp ../../../../module_base/global_variable.cpp
../../../../module_base/parallel_global.cpp ../../../../module_base/parallel_reduce.cpp
../../../../module_base/parallel_comm.cpp
../../../../module_base/complexmatrix.cpp ../../../../module_base/matrix.cpp ../../../../module_base/memory.cpp
../../../../module_base/libm/branred.cpp ../../../../module_base/libm/sincos.cpp
)
2 changes: 1 addition & 1 deletion source/module_cell/setup_nonlocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void InfoNonlocal::Set_NonLocal(const int& it,
}
else
{
if (is1 == is2 && ip1 == ip2)
if (is1 == is2 && m1 == m2)
{
coefficient_D_nc_in(ip1 + nh * is1, ip2 + nh * is2) = atom->ncpp.dion(p1, p2);
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ AddTest(
TARGET cell_ParaKpoints
LIBS MPI::MPI_CXX
SOURCES parallel_kpoints_test.cpp ../../module_base/global_variable.cpp ../../module_base/parallel_global.cpp
../../module_base/parallel_common.cpp ../parallel_kpoints.cpp
../../module_base/parallel_common.cpp ../../module_base/parallel_comm.cpp ../parallel_kpoints.cpp
)

find_program(BASH bash)
Expand Down
71 changes: 28 additions & 43 deletions source/module_hamilt_lcao/hamilt_lcaodft/LCAO_nl_mu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
const int iw1_all = start1 + iw1;
const int iw1_local = pv.global2local_row(iw1_all);
const int iw2_local = pv.global2local_col(iw1_all);
if (iw1_local < 0 && iw2_local < 0)
if (iw1_local < 0 && iw2_local < 0) {
continue;
}
const int iw1_0 = iw1 / npol;
std::vector<std::vector<double>> nlm;
// nlm is a vector of vectors, but size of outer vector is only 1 here
Expand Down Expand Up @@ -214,9 +215,9 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
// this rcut is in order to make nnr consistent
// with other matrix.
rcut = pow(orb.Phi[T1].getRcut() + orb.Phi[T2].getRcut(), 2);
if (distance < rcut)
if (distance < rcut) {
is_adj = true;
else if (distance >= rcut)
} else if (distance >= rcut)
{
for (int ad0 = 0; ad0 < adjs.adj_num + 1; ++ad0)
{
Expand Down Expand Up @@ -301,8 +302,9 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
const int j0 = j / npol; // added by zhengdy-soc
const int iw1_all = start1 + j;
const int mu = pv.global2local_row(iw1_all);
if (mu < 0)
if (mu < 0) {
continue;
}

// fix a serious bug: atom2[T2] -> atom2
// mohan 2010-12-20
Expand All @@ -311,8 +313,9 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
const int k0 = k / npol;
const int iw2_all = start2 + k;
const int nu = pv.global2local_col(iw2_all);
if (nu < 0)
if (nu < 0) {
continue;
}

if (!calc_deri)
{
Expand All @@ -321,22 +324,14 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,
if (nspin == 2 || nspin == 1)
{
double nlm_tmp = 0.0;
const int nproj = ucell.infoNL.nproj[T0];
int ib = 0;
for (int nb = 0; nb < nproj; nb++)
const double* tmp_d = nullptr;
for (int no = 0; no < ucell.atoms[T0].ncpp.non_zero_count_soc[0]; no++)
{
const int L0 = ucell.infoNL.Beta[T0].Proj[nb].getL();
for (int m = 0; m < 2 * L0 + 1; m++)
{
if (nlm_1[ib] != 0.0 && nlm_2[ib] != 0.0)
{
nlm_tmp += nlm_1[ib] * nlm_2[ib]
* ucell.atoms[T0].ncpp.dion(nb, nb);
}
ib += 1;
}
const int p1 = ucell.atoms[T0].ncpp.index1_soc[0][no];
const int p2 = ucell.atoms[T0].ncpp.index2_soc[0][no];
ucell.atoms[T0].ncpp.get_d(0, p1, p2, tmp_d);
nlm_tmp += nlm_2[p2] * nlm_1[p1] * (*tmp_d);
}
assert(ib == nlm_1.size());

if (gamma_only_local)
{
Expand Down Expand Up @@ -467,22 +462,17 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,

assert(nlm_1.size() == nlm_2[0].size());

const int nproj = ucell.infoNL.nproj[T0];
int ib = 0;
for (int nb = 0; nb < nproj; nb++)
const double* tmp_d = nullptr;
for (int no = 0; no < ucell.atoms[T0].ncpp.non_zero_count_soc[0]; no++)
{
const int L0 = ucell.infoNL.Beta[T0].Proj[nb].getL();
for (int m = 0; m < 2 * L0 + 1; m++)
const int p1 = ucell.atoms[T0].ncpp.index1_soc[0][no];
const int p2 = ucell.atoms[T0].ncpp.index2_soc[0][no];
ucell.atoms[T0].ncpp.get_d(0, p1, p2, tmp_d);
for (int ir = 0; ir < 3; ir++)
{
for (int ir = 0; ir < 3; ir++)
{
nlm[ir] += nlm_2[ir][ib] * nlm_1[ib]
* ucell.atoms[T0].ncpp.dion(nb, nb);
}
ib += 1;
nlm[ir] += nlm_2[ir][p2] * nlm_1[p1] * (*tmp_d);
}
}
assert(ib == nlm_1.size());

LCAO_domain::set_force(pv,
iw1_all,
Expand Down Expand Up @@ -516,22 +506,17 @@ void build_Nonlocal_mu_new(const Parallel_Orbitals& pv,

assert(nlm_1.size() == nlm_2[0].size());

const int nproj = ucell.infoNL.nproj[T0];
int ib = 0;
for (int nb = 0; nb < nproj; nb++)
const double* tmp_d = nullptr;
for (int no = 0; no < ucell.atoms[T0].ncpp.non_zero_count_soc[0]; no++)
{
const int L0 = ucell.infoNL.Beta[T0].Proj[nb].getL();
for (int m = 0; m < 2 * L0 + 1; m++)
const int p1 = ucell.atoms[T0].ncpp.index1_soc[0][no];
const int p2 = ucell.atoms[T0].ncpp.index2_soc[0][no];
ucell.atoms[T0].ncpp.get_d(0, p1, p2, tmp_d);
for (int ir = 0; ir < 3; ir++)
{
for (int ir = 0; ir < 3; ir++)
{
nlm[ir] += nlm_2[ir][ib] * nlm_1[ib]
* ucell.atoms[T0].ncpp.dion(nb, nb);
}
ib += 1;
nlm[ir] += nlm_2[ir][p2] * nlm_1[p1] * (*tmp_d);
}
}
assert(ib == nlm_1.size());

fsr.DHloc_fixedR_x[nnr + nnr_inner] += nlm[0];
fsr.DHloc_fixedR_y[nnr + nnr_inner] += nlm[1];
Expand Down
Loading

0 comments on commit 1a53320

Please sign in to comment.