Quantum 3xplorer (Q3)
Loading...
Searching...
No Matches
factory.hpp
Go to the documentation of this file.
1
#pragma once
2
3
/**
4
* SubspaceDiagonalizerFactory — chooses the best subspace solver.
5
*
6
* Automatically selects SerialSubspaceDiagonalizer for serial execution
7
* and MPISubspaceDiagonalizer (ScaLAPACK) for parallel execution.
8
*
9
* Dispatch is based on the runtime group_size() of the execution policy.
10
* The MPI subspace header self-guards with Q3_WITH_MPI, so this factory
11
* includes it unconditionally. In non-MPI builds, MPISubspaceDiagonalizer
12
* is not defined and the MPI branch is unreachable (group_size() is always 1).
13
*/
14
15
#include "
layer_0_core/execution/init.hpp
"
16
#include "
layer_4_computation/diagonalizer/planewave/subspace/init.hpp
"
17
#include "
layer_4_computation/diagonalizer/planewave/subspace/mpi.hpp
"
18
#include "
layer_4_computation/diagonalizer/planewave/subspace/serial.hpp
"
19
20
#include <memory>
21
#include <stdexcept>
22
23
namespace
q3
{
24
25
class
SubspaceDiagonalizerFactory
{
26
public
:
27
static
std::unique_ptr<SubspaceDiagonalizer>
28
create
(
const
execution::ExecutionPolicy
& execution_policy) {
29
if
(execution_policy.
group_size
() > 1) {
30
return
create_mpi_subspace_diagonalizer(execution_policy);
31
}
32
return
std::make_unique<SerialSubspaceDiagonalizer>();
33
}
34
35
private
:
36
/**
37
* Create an MPI subspace diagonalizer from the execution policy.
38
*
39
* This is a separate function so that the MPISubspaceDiagonalizer type
40
* reference is isolated behind the Q3_WITH_MPI self-guard in mpi.hpp.
41
* In non-MPI builds, group_size() is always 1 so this is never called,
42
* and the linker never needs to resolve the MPI symbols.
43
*/
44
static
std::unique_ptr<SubspaceDiagonalizer> create_mpi_subspace_diagonalizer(
45
[[maybe_unused]]
const
execution::ExecutionPolicy
& execution_policy) {
46
#ifdef Q3_WITH_MPI
47
const
auto
& mpi_policy =
48
dynamic_cast<
const
execution::MPIExecutionPolicy
&
>
(execution_policy);
49
return
std::make_unique<MPISubspaceDiagonalizer>(mpi_policy);
50
#else
51
throw
std::runtime_error(
52
"group_size() > 1 requires MPI support, but Q3 was built without Q3_WITH_MPI."
);
53
#endif
54
}
55
};
56
57
}
// namespace q3
q3::SubspaceDiagonalizerFactory
Definition
factory.hpp:25
q3::SubspaceDiagonalizerFactory::create
static std::unique_ptr< SubspaceDiagonalizer > create(const execution::ExecutionPolicy &execution_policy)
Definition
factory.hpp:28
q3::execution::ExecutionPolicy
Definition
init.hpp:85
q3::execution::ExecutionPolicy::group_size
virtual int group_size() const =0
q3::execution::MPIExecutionPolicy
Definition
mpi.hpp:44
init.hpp
init.hpp
mpi.hpp
serial.hpp
q3
Definition
q3_core_api.hpp:33
src
layer_4_computation
diagonalizer
planewave
subspace
factory.hpp
Generated by
1.9.8