forked from lijiext/lammps
Merge branch 'OSO' of github.com:alxvov/lammps into OSO
This commit is contained in:
commit
5924c558fb
|
@ -346,13 +346,13 @@ void MinSpinOSO_CG::calc_search_direction(int iter)
|
|||
MPI_Allreduce(&g2, &g2_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
MPI_Allreduce(&g2old, &g2old_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
|
||||
// we don't know yet if we need this. Needs to be tested with multiple replica.
|
||||
// if (update->multireplica == 1) {
|
||||
// g2 = g2_global;
|
||||
// g2old = g2old_global;
|
||||
// MPI_Allreduce(&g2,&g2_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
// MPI_Allreduce(&g2old,&g2old_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
// }
|
||||
// Sum over all replicas. Good for GNEB.
|
||||
if (update->multireplica == 1) {
|
||||
g2 = g2_global;
|
||||
g2old = g2old_global;
|
||||
MPI_Allreduce(&g2,&g2_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
MPI_Allreduce(&g2old,&g2old_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
//if (fabs(g2_global) < 1.0e-40) beta = 0.0;
|
||||
//else beta = g2_global / g2old_global;
|
||||
|
|
|
@ -376,7 +376,7 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
|
|||
MPI_Allreduce(&dyds, &dyds_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
dyds = dyds_global;
|
||||
MPI_Allreduce(&dyds_global,&dyds,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
MPI_Allreduce(&dyds, &dyds_global, 1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
if (fabs(dyds_global) > 1.0e-60) rho[m_index] = 1.0 / dyds_global;
|
||||
|
@ -403,7 +403,7 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
|
|||
MPI_Allreduce(&sq, &sq_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
sq = sq_global;
|
||||
MPI_Allreduce(&sq_global,&sq,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
MPI_Allreduce(&sq,&sq_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
// update alpha
|
||||
|
@ -425,7 +425,7 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
|
|||
MPI_Allreduce(&yy, &yy_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
yy = yy_global;
|
||||
MPI_Allreduce(&yy_global,&yy,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
MPI_Allreduce(&yy,&yy_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
// calculate now search direction
|
||||
|
@ -455,7 +455,7 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
|
|||
MPI_Allreduce(&yr, &yr_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
yr = yr_global;
|
||||
MPI_Allreduce(&yr_global,&yr,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
MPI_Allreduce(&yr,&yr_global,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
beta = rho[c_ind] * yr_global;
|
||||
|
|
|
@ -216,6 +216,9 @@ int MinSpinOSO_LBFGS_LS::iterate(int maxiter)
|
|||
}
|
||||
MPI_Allreduce(&der_e_cur, &der_e_cur_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
der_e_cur = der_e_cur_global;
|
||||
if (update->multireplica == 1) {
|
||||
MPI_Allreduce(&der_e_cur_global,&der_e_cur,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
}
|
||||
|
||||
if (use_line_search){
|
||||
|
@ -388,7 +391,7 @@ void MinSpinOSO_LBFGS_LS::calc_search_direction(int iter)
|
|||
|
||||
// for some reason on a second iteration g_old = 0
|
||||
// so we make two iterations as steepest descent
|
||||
|
||||
|
||||
if (iter == 0){ // steepest descent direction
|
||||
for (int i = 0; i < 3 * nlocal; i++) {
|
||||
p_s[i] = -g_cur[i];
|
||||
|
@ -405,7 +408,12 @@ void MinSpinOSO_LBFGS_LS::calc_search_direction(int iter)
|
|||
dyds += ds[m_index][i] * dy[m_index][i];
|
||||
}
|
||||
MPI_Allreduce(&dyds, &dyds_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (fabs(dyds) > 1.0e-60) rho[m_index] = 1.0 / dyds_global;
|
||||
if (update->multireplica == 1) {
|
||||
dyds = dyds_global;
|
||||
MPI_Allreduce(&dyds_global,&dyds,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
if (fabs(dyds_global) > 1.0e-60) rho[m_index] = 1.0 / dyds_global;
|
||||
else rho[m_index] = 1.0e60;
|
||||
|
||||
// set the q vector
|
||||
|
@ -427,7 +435,10 @@ void MinSpinOSO_LBFGS_LS::calc_search_direction(int iter)
|
|||
sq += ds[c_ind][i] * q[i];
|
||||
}
|
||||
MPI_Allreduce(&sq, &sq_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
|
||||
if (update->multireplica == 1) {
|
||||
sq = sq_global;
|
||||
MPI_Allreduce(&sq_global,&sq,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
// update alpha
|
||||
|
||||
alpha[c_ind] = rho[c_ind] * sq_global;
|
||||
|
@ -445,8 +456,12 @@ void MinSpinOSO_LBFGS_LS::calc_search_direction(int iter)
|
|||
yy += dy[m_index][i] * dy[m_index][i];
|
||||
}
|
||||
MPI_Allreduce(&yy, &yy_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
yy = yy_global;
|
||||
MPI_Allreduce(&yy_global,&yy,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
// calculate now search direction
|
||||
// calculate now search direction
|
||||
|
||||
if (fabs(yy_global) > 1.0e-60) {
|
||||
for (int i = 0; i < 3 * nlocal; i++) {
|
||||
|
@ -470,6 +485,10 @@ void MinSpinOSO_LBFGS_LS::calc_search_direction(int iter)
|
|||
yr += dy[c_ind][i] * p_s[i];
|
||||
}
|
||||
MPI_Allreduce(&yr, &yr_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
if (update->multireplica == 1) {
|
||||
yr = yr_global;
|
||||
MPI_Allreduce(&yr_global,&yr,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
beta = rho[c_ind] * yr_global;
|
||||
for (int i = 0; i < 3 * nlocal; i++) {
|
||||
|
@ -661,6 +680,9 @@ void MinSpinOSO_LBFGS_LS::make_step(double c, double *energy_and_der)
|
|||
}
|
||||
MPI_Allreduce(&der_e_cur, &der_e_cur_global, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
der_e_cur = der_e_cur_global;
|
||||
if (update->multireplica == 1) {
|
||||
MPI_Allreduce(&der_e_cur_global,&der_e_cur,1,MPI_DOUBLE,MPI_SUM,universe->uworld);
|
||||
}
|
||||
|
||||
energy_and_der[0] = ecurrent;
|
||||
energy_and_der[1] = der_e_cur;
|
||||
|
@ -685,10 +707,9 @@ int MinSpinOSO_LBFGS_LS::calc_and_make_step(double a, double b, int index)
|
|||
|
||||
if (awc(der_e_pr, eprevious, e_and_d[1], e_and_d[0]) || index == 3){
|
||||
MPI_Bcast(&b,1,MPI_DOUBLE,0,world);
|
||||
|
||||
for (int i = 0; i < 3 * nlocal; i++) {
|
||||
p_s[i] = b * p_s[i];
|
||||
}
|
||||
for (int i = 0; i < 3 * nlocal; i++) {
|
||||
p_s[i] = b * p_s[i];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
|
|
Loading…
Reference in New Issue