ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
lobpcg_internal.h
Go to the documentation of this file.
1#ifndef HSOLVER_LOBPCG_INTERNAL_H_
2#define HSOLVER_LOBPCG_INTERNAL_H_
3
4// Shared implementation details, included only by the LOBPCG .cpp files.
5#include "diago_lobpcg.h"
8
9#include <algorithm>
10#include <cstdint>
11#include <type_traits>
12#include <utility>
13
14namespace hsolver
15{
17{
19template <typename T>
20ct::Tensor host_tensor(const int64_t count, const T value)
21{
23 ct::Tensor tensor(type, ct::DeviceType::CpuDevice, {count});
24 std::fill_n(tensor.data<T>(), count, value);
25 return tensor;
26}
27
29template <typename T, typename U>
31{
33 if (std::is_same<T, U>::value)
34 {
35 ct::TensorMap view(input, type, ct::DeviceType::CpuDevice, {count});
36 return ct::Tensor(std::move(view));
37 }
38 ct::Tensor tensor(type, ct::DeviceType::CpuDevice, {count});
39 std::copy_n(input, count, tensor.data<T>());
40 return tensor;
41}
42
43} // namespace lobpcg_internal
44
46template <typename T, typename Device>
47template <typename Value>
48void DiagoLOBPCG<T, Device>::broadcast(Value* data, const int count) const
49{
50#ifdef __MPI
51 if (comm_.nproc > 1)
52 {
53 Parallel_Common::bcast_data(data, count, comm_.comm, 0);
54 }
55#endif
56}
57
58} // namespace hsolver
59
60#endif // HSOLVER_LOBPCG_INTERNAL_H_
A multi-dimensional reference array of elements of a single data type.
Definition tensor_map.h:19
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
void broadcast(Value *data, const int count) const
Share root-owned coefficients or status within the eigensolve communicator.
Definition lobpcg_internal.h:48
const diag_comm_info comm_
Communicator/rank for distributed rows of one eigensolve.
Definition diago_lobpcg.h:114
#define T
Definition exp.cpp:237
void bcast_data(std::complex< double > *object, const int &n, const MPI_Comm &comm, int root)
Definition parallel_device.cpp:305
DataType
Definition tensor_enums.h:15
@ CpuDevice
Definition tensor_enums.h:30
Definition lobpcg_internal.h:17
ct::Tensor host_tensor(const int64_t count, const T value)
Allocate and fill a host Tensor for small projected matrices or scalar work arrays.
Definition lobpcg_internal.h:20
ct::Tensor host_tensor_cast_or_view(U *input, const int64_t count)
Borrow host storage when types match; otherwise own a converted copy. The view must not outlive input...
Definition lobpcg_internal.h:30
Definition dense_eigensolver.cpp:23
static constexpr DataType value
Definition tensor_enums.h:61
Input_para input
Definition test_io_sys_var.cpp:58