45 using X = CuVector<field_type>;
48 : m_cpuOwnerOverlapCopy(cpuOwnerOverlapCopy)
58 void dot(
const X& x,
const X& y, field_type& output)
const
60 std::call_once(m_initializedIndices, [&]() { initIndexSet(); });
62 const auto dotAtRank = x.dot(y, *m_indicesOwner);
63 output = m_cpuOwnerOverlapCopy.communicator().sum(dotAtRank);
72 field_type
norm(
const X& x)
const
74 auto xDotX = field_type(0);
75 this->
dot(x, x, xDotX);
90 std::call_once(m_initializedIndices, [&]() { initIndexSet(); });
91 x.setZeroAtIndexSet(*m_indicesCopy);
104 auto sourceAsDuneVector = source.template asDuneBlockVector<block_size>();
105 auto destAsDuneVector = dest.template asDuneBlockVector<block_size>();
106 m_cpuOwnerOverlapCopy.copyOwnerToAll(sourceAsDuneVector, destAsDuneVector);
107 dest.copyFromHost(destAsDuneVector);
113 const OwnerOverlapCopyCommunicationType& m_cpuOwnerOverlapCopy;
118 mutable std::once_flag m_initializedIndices;
119 mutable std::unique_ptr<CuVector<int>> m_indicesCopy;
120 mutable std::unique_ptr<CuVector<int>> m_indicesOwner;
123 void initIndexSet()
const
127 const auto& pis = m_cpuOwnerOverlapCopy.indexSet();
128 std::vector<int> indicesCopyOnCPU;
129 std::vector<int> indicesOwnerCPU;
130 for (
const auto& index : pis) {
131 if (index.local().attribute() == Dune::OwnerOverlapCopyAttributeSet::copy) {
132 for (
int component = 0; component < block_size; ++component) {
133 indicesCopyOnCPU.push_back(index.local().local() * block_size + component);
137 if (index.local().attribute() == Dune::OwnerOverlapCopyAttributeSet::owner) {
138 for (
int component = 0; component < block_size; ++component) {
139 indicesOwnerCPU.push_back(index.local().local() * block_size + component);
144 m_indicesCopy = std::make_unique<CuVector<int>>(indicesCopyOnCPU);
145 m_indicesOwner = std::make_unique<CuVector<int>>(indicesOwnerCPU);
void copyOwnerToAll(const X &source, X &dest) const
copyOwnerToAll will copy source to the CPU, then call OwnerOverlapCopyCommunicationType::copyOwnerToA...
Definition CuOwnerOverlapCopy.hpp:100
void dot(const X &x, const X &y, field_type &output) const
dot will carry out the dot product between x and y on the owned indices, then sum up the result acros...
Definition CuOwnerOverlapCopy.hpp:58