Commit c03223a9 authored by gbalduzz's avatar gbalduzz
Browse files

Parallelize phi over threads instead of processes.

parent 1be84e51
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -304,21 +304,22 @@ void CoarsegrainingSp<Parameters>::updateSigmaInterpolated(const LatticeFreqFunc
template <typename Parameters>
template <typename RDmn>
void CoarsegrainingSp<Parameters>::compute_phi_r(func::function<ScalarType, RDmn>& phi_r) const {
  phi_r = 0.;

  using KCluster = typename KClusterDmn::parameter_type;
  math::geometry::tetrahedron_mesh<KCluster> mesh(parameters_.get_k_mesh_recursion());

  using tetrahedron_dmn = func::dmn_0<math::geometry::tetrahedron_mesh<KClusterDmn>>;
  using quadrature_dmn = math::geometry::gaussian_quadrature_domain<tetrahedron_dmn>;
  quadrature_dmn::translate_according_to_period(parameters_.get_coarsegraining_periods(), mesh);

  std::vector<math::geometry::tetrahedron<dimension>>& tetrahedra = mesh.get_tetrahedra();
  std::vector<std::vector<double>> super_basis = RDmn::parameter_type::get_super_basis_vectors();

  phi_r = 0.;
  double tot_weight = 0;
  for (auto w : QDmn::parameter_type::get_weights())
    tot_weight += w;

  RDmn r_domain;
  std::pair<int, int> bounds = concurrency_.get_bounds(r_domain);

  std::vector<std::vector<double>> super_basis = RDmn::parameter_type::get_super_basis_vectors();
  Threading().execute(parameters_.get_coarsegraining_threads(), [&](int id, int threads) {
    const std::pair<int, int> bounds = parallel::util::getBounds(id, threads, RDmn());

    for (int l = bounds.first; l < bounds.second; l++) {
      std::vector<double> r_vec = RDmn::get_elements()[l];
@@ -329,15 +330,10 @@ void CoarsegrainingSp<Parameters>::compute_phi_r(func::function<ScalarType, RDmn
          phi_r(l) += std::real(tetrahedron_routines_harmonic_function::execute(
                          r_vecs[0], tetrahedra[tet_ind])) /
                      r_vecs.size();
  }

  concurrency_.sum(phi_r);

  double tot_weight = 0;
  for (auto w : QDmn::parameter_type::get_weights())
    tot_weight += w;

  phi_r /= tot_weight;
      phi_r(l) /= tot_weight;
    }
  });
}

}  // namespace clustermapping
+11 −11
Original line number Diff line number Diff line
@@ -25,20 +25,20 @@ namespace clustermapping {
class tetrahedron_routines_harmonic_function {
public:
  // 1D
  static std::complex<double> execute(std::vector<double>& r_vec,
                                      math::geometry::tetrahedron<1>& tetrahedron);
  static std::complex<double> execute(const std::vector<double>& r_vec,
                                      const math::geometry::tetrahedron<1>& tetrahedron);
  // 2D
  static std::complex<double> execute(std::vector<double>& r_vec,
                                      math::geometry::tetrahedron<2>& tetrahedron);
  static std::complex<double> execute(const std::vector<double>& r_vec,
                                      const math::geometry::tetrahedron<2>& tetrahedron);

  // 3D
  static std::complex<double> execute(std::vector<double>& r_vec,
                                      math::geometry::tetrahedron<3>& tetrahedron);
  static std::complex<double> execute(const std::vector<double>& r_vec,
                                      const math::geometry::tetrahedron<3>& tetrahedron);

private:
  // 2D cases:
  static void permute(math::geometry::tetrahedron<2>& tetrahedron_new,
                      math::geometry::tetrahedron<2>& tetrahedron_old);
                      const math::geometry::tetrahedron<2>& tetrahedron_old);

  static std::complex<double> case_2D(double dotRD1, double dotRD2, double dotRD2minD1);
  static std::complex<double> case_d1_2D(double dotRD1, double dotRD2, double dotRD2minD1);
@@ -46,7 +46,7 @@ private:

  // 3D
  static void permute(math::geometry::tetrahedron<3>& tetrahedron_new,
                      math::geometry::tetrahedron<3>& tetrahedron_old);
                      const math::geometry::tetrahedron<3>& tetrahedron_old);

  static std::complex<double> case_3D(double dotRD1, double dotRD2, double dotRD3,
                                      double dotRD2minD1, double dotRD3minD2, double dotRD1minD3);
@@ -73,8 +73,8 @@ private:
                                            double dotRD1minD3);
};

}  // clustermapping
}  // phys
}  // dca
}  // namespace clustermapping
}  // namespace phys
}  // namespace dca

#endif  // DCA_PHYS_DCA_STEP_CLUSTER_MAPPING_COARSEGRAINING_TETRAHEDRON_ROUTINES_HARMONIC_FUNCTION_HPP
+9 −10
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ namespace clustermapping {
 ************************************/

std::complex<double> tetrahedron_routines_harmonic_function::execute(
    std::vector<double>& r_vec, math::geometry::tetrahedron<1>& tetrahedron) {
    const std::vector<double>& r_vec, const math::geometry::tetrahedron<1>& tetrahedron) {
  assert(r_vec.size() == 1);

  double r = r_vec[0];
@@ -87,7 +87,7 @@ std::complex<double> tetrahedron_routines_harmonic_function::execute(
 *
 */
std::complex<double> tetrahedron_routines_harmonic_function::execute(
    std::vector<double>& r_vec, math::geometry::tetrahedron<2>& tetrahedron) {
    const std::vector<double>& r_vec, const math::geometry::tetrahedron<2>& tetrahedron) {
  assert(r_vec.size() == 2);

  const static std::complex<double> I(0, 1);
@@ -148,7 +148,7 @@ std::complex<double> tetrahedron_routines_harmonic_function::execute(
}

void tetrahedron_routines_harmonic_function::permute(math::geometry::tetrahedron<2>& tetrahedron_new,
                                                     math::geometry::tetrahedron<2>& tetrahedron_old) {
                                                     const math::geometry::tetrahedron<2> &tetrahedron_old) {
  tetrahedron_new.vec_1 = tetrahedron_old.vec_0;
  tetrahedron_new.vec_2 = tetrahedron_old.vec_1;
  tetrahedron_new.vec_0 = tetrahedron_old.vec_2;
@@ -234,7 +234,7 @@ std::complex<double> tetrahedron_routines_harmonic_function::case_d2_2D(double d
 ************************************/

void tetrahedron_routines_harmonic_function::permute(math::geometry::tetrahedron<3>& tetrahedron_new,
                                                     math::geometry::tetrahedron<3>& tetrahedron_old) {
                                                     const math::geometry::tetrahedron<3> &tetrahedron_old) {
  tetrahedron_new.vec_1 = tetrahedron_old.vec_0;
  tetrahedron_new.vec_2 = tetrahedron_old.vec_1;
  tetrahedron_new.vec_3 = tetrahedron_old.vec_2;
@@ -461,7 +461,7 @@ std::complex<double> tetrahedron_routines_harmonic_function::case_d3_d1_3D(
}

std::complex<double> tetrahedron_routines_harmonic_function::execute(
    std::vector<double>& r_vec, math::geometry::tetrahedron<3>& tetrahedron) {
    const std::vector<double>& r_vec, const math::geometry::tetrahedron<3>& tetrahedron) {
  assert(r_vec.size() == 3);

  const static std::complex<double> I(0, 1);
@@ -509,8 +509,7 @@ std::complex<double> tetrahedron_routines_harmonic_function::execute(

    if (std::abs(dot_R_D1) > EPSILON and std::abs(dot_R_D2) > EPSILON and
        std::abs(dot_R_D3) > EPSILON and std::abs(dot_R_D2_min_D1) > EPSILON and
        std::abs(dot_R_D3_min_D2) > EPSILON and
        std::abs(dot_R_D1_min_D3) > EPSILON)  // general case
        std::abs(dot_R_D3_min_D2) > EPSILON and std::abs(dot_R_D1_min_D3) > EPSILON)  // general case
    {
      result =
          case_3D(dot_R_D1, dot_R_D2, dot_R_D3, dot_R_D2_min_D1, dot_R_D3_min_D2, dot_R_D1_min_D3) *
@@ -580,6 +579,6 @@ std::complex<double> tetrahedron_routines_harmonic_function::execute(
  return result;
}

}  // clustermapping
}  // phys
}  // dca
}  // namespace clustermapping
}  // namespace phys
}  // namespace dca
+2 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
dca_add_gtest(lattice_mapping_sp_test EXTENSIVE
  GTEST_MAIN
  INCLUDE_DIRS ${SIMPLEX_GM_RULE_INCLUDE_DIR} ${FFTW_INCLUDE_DIR}
  LIBS json function cluster_domains time_and_frequency_domains quantum_domains gaussian_quadrature
  LIBS json function cluster_domains parallel_stdthread parallel_util time_and_frequency_domains
       quantum_domains gaussian_quadrature
       tetrahedron_mesh coarsegraining enumerations dca_hdf5 ${LAPACK_LIBRARIES} ${HDF5_LIBRARIES}
       lapack)
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ dca_add_gtest(tp_accumulator_particle_hole_test
  GTEST_MAIN
  INCLUDE_DIRS ${PROJECT_SOURCE_DIR} ${FFTW_INCLUDE_DIR} ${HDF5_INCLUDE_DIR}
  LIBS function cluster_domains time_and_frequency_domains quantum_domains timer json random
       enumerations dca_algorithms ${LAPACK_LIBRARIES})
       enumerations dca_algorithms parallel_stdthread parallel_util ${LAPACK_LIBRARIES})

dca_add_gtest(tp_accumulator_gpu_test
  CUDA
Loading