Loading...
Searching...
No Matches
serial.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * SerialExecutionPolicy — serial CPU implementation of ExecutionPolicy.
5 *
6 * Delegates group-collective vector operations to BLAS routines on host memory.
7 * No inter-process communication. Used for single-process builds and as
8 * the group-collective baseline inside PlanewaveSerialExecutionPolicy.
9 *
10 * No MPI headers. No CUDA headers. No global state.
11 */
12
15
16#include <cmath>
17#include <cstring>
18
19namespace q3 {
20namespace execution {
21
22class SerialExecutionPolicy : public virtual ExecutionPolicy {
23 public:
24 /**
25 * Compute the inner product x† · y using the existing q3_complex_conjugate_dot_product helper.
26 */
27 ComplexValue dot_product(int number_of_elements,
28 const ComplexValue* vector_x,
29 const ComplexValue* vector_y) const override {
30 return blas::q3_complex_conjugate_dot_product(number_of_elements, vector_x, vector_y);
31 }
32
33 /**
34 * Scaled vector addition via BLAS zaxpy_: vector_y += scaling_factor * vector_x.
35 */
36 void add_scaled_vector(int number_of_elements,
37 ComplexValue scaling_factor,
38 const ComplexValue* vector_x,
39 ComplexValue* vector_y) const override {
40 const int stride = 1;
41 blas::zaxpy_(&number_of_elements, &scaling_factor, vector_x, &stride, vector_y, &stride);
42 }
43
44 /**
45 * Euclidean norm via BLAS dznrm2_.
46 */
47 Real norm(int number_of_elements, const ComplexValue* vector_x) const override {
48 const int stride = 1;
49 return blas::dznrm2_(&number_of_elements, vector_x, &stride);
50 }
51
52 bool is_root() const override {
53 return true;
54 }
55
56 int group_rank_index() const override {
57 return 0;
58 }
59
60 int group_size() const override {
61 return 1;
62 }
63
64 int number_of_processes() const override {
65 return 1;
66 }
67
68 int global_number_of_elements(int local_number_of_elements) const override {
69 return local_number_of_elements;
70 }
71
72 void reduce_within_group(ComplexValue* /*data*/, int /*number_of_elements*/) const override {}
73
74 void reduce_within_group(Real* /*data*/, int /*number_of_elements*/) const override {}
75
76 void allgather_within_group(const Real* local_data,
77 int local_count,
78 Real* full_data,
79 int /*total_count*/) const override {
80 std::memcpy(full_data, local_data, local_count * sizeof(Real));
81 }
82};
83
84} // namespace execution
85} // namespace q3
ComplexValue dot_product(int number_of_elements, const ComplexValue *vector_x, const ComplexValue *vector_y) const override
Definition serial.hpp:27
void reduce_within_group(ComplexValue *, int) const override
Definition serial.hpp:72
int global_number_of_elements(int local_number_of_elements) const override
Definition serial.hpp:68
int number_of_processes() const override
Definition serial.hpp:64
void allgather_within_group(const Real *local_data, int local_count, Real *full_data, int) const override
Definition serial.hpp:76
int group_size() const override
Definition serial.hpp:60
bool is_root() const override
Definition serial.hpp:52
void add_scaled_vector(int number_of_elements, ComplexValue scaling_factor, const ComplexValue *vector_x, ComplexValue *vector_y) const override
Definition serial.hpp:36
Real norm(int number_of_elements, const ComplexValue *vector_x) const override
Definition serial.hpp:47
void reduce_within_group(Real *, int) const override
Definition serial.hpp:74
int group_rank_index() const override
Definition serial.hpp:56
std::complex< double > q3_complex_conjugate_dot_product(int n, const std::complex< double > *x, const std::complex< double > *y)
Definition blas.hpp:100
void zaxpy_(const int *n, const std::complex< double > *alpha, const std::complex< double > *x, const int *incx, std::complex< double > *y, const int *incy)
double dznrm2_(const int *n, const std::complex< double > *x, const int *incx)
double Real