Commit 6a2a4d5c authored by alxvov's avatar alxvov
Browse files

parallelisation of lbfgs

parent 5f74f6dd
Loading
Loading
Loading
Loading
+9 −6
Changes for src/SPIN/min_spin_oso_lbfgs.cpp: 9 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -356,8 +356,8 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
        dy[m_index][i] = g[i] - g_old[i];
        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;
    MPI_Allreduce(&dyds, &dyds_global, 1, MPI_DOUBLE, MPI_SUM, world);
    if (fabs(dyds) > 1.0e-60) rho[m_index] = 1.0 / dyds_global;
    else rho[m_index] = 1.0e60;

    // set the q vector
@@ -378,10 +378,11 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
      for (int i = 0; i < 3 * nlocal; i++) {
        sq += ds[c_ind][i] * q[i];
      }
      MPI_Allreduce(&sq, &sq_global, 1, MPI_DOUBLE, MPI_SUM, world);

      // update alpha

      alpha[c_ind] = rho[c_ind] * sq;
      alpha[c_ind] = rho[c_ind] * sq_global;

      // update q

@@ -395,12 +396,13 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
    for (int i = 0; i < 3 * nlocal; i++) {
      yy += dy[m_index][i] * dy[m_index][i];
    }
    MPI_Allreduce(&yy, &yy_global, 1, MPI_DOUBLE, MPI_SUM, world);

      // calculate now search direction

    if (fabs(yy) > 1.0e-60) {
    if (fabs(yy_global) > 1.0e-60) {
      for (int i = 0; i < 3 * nlocal; i++) {
        p[i] = q[i] / (rho[m_index] * yy);
        p[i] = q[i] / (rho[m_index] * yy_global);
      }
    }else{
      for (int i = 0; i < 3 * nlocal; i++) {
@@ -419,8 +421,9 @@ void MinSpinOSO_LBFGS::calc_search_direction(int iter)
      for (int i = 0; i < 3 * nlocal; i++) {
        yr += dy[c_ind][i] * p[i];
      }
      MPI_Allreduce(&yr, &yr_global, 1, MPI_DOUBLE, MPI_SUM, world);

      beta = rho[c_ind] * yr;
      beta = rho[c_ind] * yr_global;
      for (int i = 0; i < 3 * nlocal; i++) {
        p[i] += ds[c_ind][i] * (alpha[c_ind] - beta);
      }