Skip to content
Closed
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
92 changes: 50 additions & 42 deletions source/source_base/kernels/math_kernel_op_vec.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "source_base/kernels/math_kernel_op.h"
#include "source_base/module_external/blas_connector.h"
#include "source_base/parallel_reduce.h"
#include "source_base/tool_threading.h"


namespace ModuleBase
Expand All @@ -23,13 +25,14 @@ struct vector_mul_real_op<T, base_device::DEVICE_CPU>
using Real = typename GetTypeReal<T>::type;
void operator()(const int dim, T* result, const T* vector, const Real constant)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
#endif
for (int i = 0; i < dim; i++)
{
result[i] = vector[i] * constant;
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] = vector[i] * constant;
}
});
}
};

Expand All @@ -41,23 +44,25 @@ struct vector_mul_vector_op<T, base_device::DEVICE_CPU>
{
if (add)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
#endif
for (int i = 0; i < dim; i++)
{
result[i] += vector1[i] * vector2[i];
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] += vector1[i] * vector2[i];
}
});
}
else
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
#endif
for (int i = 0; i < dim; i++)
{
result[i] = vector1[i] * vector2[i];
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] = vector1[i] * vector2[i];
}
});
}
}
};
Expand All @@ -68,13 +73,14 @@ struct vector_div_constant_op<T, base_device::DEVICE_CPU>
using Real = typename GetTypeReal<T>::type;
void operator()(const int& dim, T* result, const T* vector, const Real constant)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
#endif
for (int i = 0; i < dim; i++)
{
result[i] = vector[i] / constant;
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] = vector[i] / constant;
}
});
}
};

Expand All @@ -84,13 +90,14 @@ struct vector_div_vector_op<T, base_device::DEVICE_CPU>
using Real = typename GetTypeReal<T>::type;
void operator()(const int& dim, T* result, const T* vector1, const Real* vector2)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 4096 / sizeof(Real))
#endif
for (int i = 0; i < dim; i++)
{
result[i] = vector1[i] / vector2[i];
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] = vector1[i] / vector2[i];
}
});
}
};

Expand Down Expand Up @@ -120,13 +127,14 @@ struct vector_add_vector_op<T, base_device::DEVICE_CPU>
const T* vector2,
const Real constant2)
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 8192 / sizeof(T))
#endif
for (int i = 0; i < dim; i++)
{
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
}
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, dim, (int)(4096 / sizeof(T)), beg, len);
for (int i = beg; i < beg + len; i++)
{
result[i] = vector1[i] * constant1 + vector2[i] * constant2;
}
});
}
};

Expand Down
1 change: 1 addition & 0 deletions source/source_hsolver/diago_cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <source_base/parallel_reduce.h>
#include <source_base/timer.h>
#include <source_base/tool_title.h> // ModuleBase::TITLE
#include <source_base/tool_threading.h>
#include <source_base/global_function.h> // ModuleBase::GlobalFunc::NOTE
#include <source_hsolver/diago_cg.h>

Expand Down
49 changes: 29 additions & 20 deletions source/source_hsolver/diago_dav_subspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "source_base/memory.h"
#include "source_base/module_device/device.h"
#include "source_base/timer.h"
#include "source_base/tool_threading.h"
#include "source_hsolver/kernels/dngvd_op.h"
#include "source_base/kernels/math_kernel_op.h"
#include "source_hsolver/kernels/bpcg_kernel_op.h" // normalize_op, precondition_op, apply_eigenvalues_op
Expand Down Expand Up @@ -604,14 +605,18 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
std::vector<std::vector<T>> h_diag(nbase, std::vector<T>(nbase, *this->zero));
std::vector<std::vector<T>> s_diag(nbase, std::vector<T>(nbase, *this->zero));

for (size_t i = 0; i < nbase; i++)
{
for (size_t j = 0; j < nbase; j++)
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, (int)nbase, 8, beg, len);
for (int i = beg; i < beg + len; i++)
{
h_diag[i][j] = hcc[i * this->nbase_x + j];
s_diag[i][j] = scc[i * this->nbase_x + j];
for (size_t j = 0; j < nbase; j++)
{
h_diag[i][j] = hcc[i * this->nbase_x + j];
s_diag[i][j] = scc[i * this->nbase_x + j];
}
}
}
});
dngvx_op<T, Device>()(this->ctx,
nbase,
this->nbase_x,
Expand All @@ -621,22 +626,26 @@ void Diago_DavSubspace<T, Device>::diag_zhegvx(const int& nbase,
(*eigenvalue_iter).data(),
this->vcc);
// reset:
for (size_t i = 0; i < nbase; i++)
{
for (size_t j = 0; j < nbase; j++)
ModuleBase::OMP_PARALLEL([&](int num_thread, int thread_id) {
int beg = 0, len = 0;
ModuleBase::BLOCK_TASK_DIST_1D(num_thread, thread_id, (int)nbase, 8, beg, len);
for (int i = beg; i < beg + len; i++)
{
hcc[i * this->nbase_x + j] = h_diag[i][j];
scc[i * this->nbase_x + j] = s_diag[i][j];
for (size_t j = 0; j < nbase; j++)
{
hcc[i * this->nbase_x + j] = h_diag[i][j];
scc[i * this->nbase_x + j] = s_diag[i][j];
}

for (size_t j = nbase; j < this->nbase_x; j++)
{
hcc[i * this->nbase_x + j] = *this->zero;
hcc[j * this->nbase_x + i] = *this->zero;
scc[i * this->nbase_x + j] = *this->zero;
scc[j * this->nbase_x + i] = *this->zero;
}
}

for (size_t j = nbase; j < this->nbase_x; j++)
{
hcc[i * this->nbase_x + j] = *this->zero;
hcc[j * this->nbase_x + i] = *this->zero;
scc[i * this->nbase_x + j] = *this->zero;
scc[j * this->nbase_x + i] = *this->zero;
}
}
});
}
}
else
Expand Down