DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
IndexMapping_bind.hpp
Go to the documentation of this file.
1#pragma once
2/// @file IndexMapping_bind.hpp
3/// @brief pybind11 bindings for @ref DNDS::GlobalOffsetsMapping "GlobalOffsetsMapping" and @ref DNDS::OffsetAscendIndexMapping "OffsetAscendIndexMapping".
4
5#include "IndexMapping.hpp"
6#include "Defines_bind.hpp"
7
8#include <pybind11/pybind11.h>
9#include <pybind11/stl.h>
10
11#include <utility>
12
13namespace py = pybind11;
14
15namespace DNDS
16{
18 {
19 return py_class_ssp<GlobalOffsetsMapping>(std::move(m), "GlobalOffsetsMapping");
20 }
21
22 inline auto pybind11_GlobalOffsetsMapping_get_class(const py::module_ &m)
23 {
24 return py_class_ssp<GlobalOffsetsMapping>(m.attr("GlobalOffsetsMapping"));
25 }
26
27 inline void pybind11_GlobalOffsetsMapping_define(py::module_ m)
28 {
29 auto Py_GlobalOffsetsMapping = pybind11_GlobalOffsetsMapping_declare(std::move(m));
30
31 Py_GlobalOffsetsMapping
32 .def(py::init<>())
33 .def("globalSize", &GlobalOffsetsMapping::globalSize)
34 .def("setMPIAlignBcast", &GlobalOffsetsMapping::setMPIAlignBcast)
35 .def(
36 "RLengths",
37 [](GlobalOffsetsMapping &self)
38 {
39 return py_vector_as_memory_view(self.RLengths(), true);
40 },
41 py::keep_alive<0, 1>())
42 .def(
43 "ROffsets",
44 [](GlobalOffsetsMapping &self)
45 {
46 return py_vector_as_memory_view(self.ROffsets(), true);
47 },
48 py::keep_alive<0, 1>())
49 .def("search", [](GlobalOffsetsMapping &self, index globalQuery)
50 { return self.search(globalQuery); }, py::arg("globalQuery"))
51 .def("__call__", [](GlobalOffsetsMapping &self, MPI_int rank, index val)
52 { return self.operator()(rank, val); }, py::arg("rank"), py::arg("val"));
53 }
54
56 {
57 return py_class_ssp<OffsetAscendIndexMapping>(std::move(m), "OffsetAscendIndexMapping");
58 }
59
60 inline auto pybind11_OffsetAscendIndexMapping_get_class(const py::module_ &m)
61 {
62 return py_class_ssp<OffsetAscendIndexMapping>(m.attr("OffsetAscendIndexMapping"));
63 }
64
66 {
67 auto Py_OffsetAscendIndexMapping = pybind11_OffsetAscendIndexMapping_declare(std::move(m));
68
69 Py_OffsetAscendIndexMapping
70 .def(
71 py::init(
72 [](index nmainOffset, index nmainSize,
73 std::vector<index> pullingIndexGlobal,
74 const GlobalOffsetsMapping &LGlobalMapping, const MPIInfo &mpi)
75 { return std::make_shared<OffsetAscendIndexMapping>(nmainOffset, nmainSize, pullingIndexGlobal, LGlobalMapping, mpi); }),
76 py::arg("nmainOffset"), py::arg("nmainSize"),
77 py::arg("pullingIndexGlobal"),
78 py::arg("LGlobalMapping"), py::arg("mpi"))
79 .def(
80 py::init([](index nmainOffset, index nmainSize,
81 std::vector<index> pushingIndexesLocal, // which stores local index
82 std::vector<index> pushingStarts,
83 const GlobalOffsetsMapping &LGlobalMapping,
84 const MPIInfo &mpi)
85 { return std::make_shared<OffsetAscendIndexMapping>(
86 nmainOffset, nmainSize, pushingIndexesLocal, pushingStarts, LGlobalMapping, mpi); }),
87 py::arg("nmainOffset"), py::arg("nmainSize"),
88 py::arg("pushingIndexLocal"), py::arg("pushingStarts"),
89 py::arg("LGlobalMapping"), py::arg("mpi"))
90 .def("ghostAt", &OffsetAscendIndexMapping::ghostAt)
91 .def_property_readonly(
92 "ghostIndex",
94 {
95 return py_vector_as_memory_view(self.ghostIndex, true);
96 },
97 py::keep_alive<0, 1>())
98 .def_property_readonly(
99 "ghostSizes",
101 {
102 return py_vector_as_memory_view(self.ghostSizes, true);
103 },
104 py::keep_alive<0, 1>())
105 .def_property_readonly(
106 "ghostStart",
108 {
109 return py_vector_as_memory_view(self.ghostStart, true);
110 },
111 py::keep_alive<0, 1>())
112 .def_property_readonly(
113 "pullingRequestLocal",
115 {
117 },
118 py::keep_alive<0, 1>())
119 .def_property_readonly(
120 "pushingIndexGlobal",
122 {
124 },
125 py::keep_alive<0, 1>())
126 .def_property_readonly(
127 "pushIndexSizes",
129 {
130 return py_vector_as_memory_view(self.pushIndexSizes, true);
131 },
132 py::keep_alive<0, 1>())
133 .def_property_readonly(
134 "pushIndexStarts",
136 {
137 return py_vector_as_memory_view(self.pushIndexStarts, true);
138 },
139 py::keep_alive<0, 1>())
140 .def("search", [&](OffsetAscendIndexMapping &self, index globalQuery)
141 { return self.search(globalQuery); }, py::arg("globalQuery"))
142 .def("search_indexAppend", [&](OffsetAscendIndexMapping &self, index globalQuery)
143 { return self.search_indexAppend(globalQuery); }, py::arg("globalQuery"))
144 .def("search_indexRank", [&](OffsetAscendIndexMapping &self, index globalQuery)
145 { return self.search_indexRank(globalQuery); }, py::arg("globalQuery"))
146 .def("__call__", [&](OffsetAscendIndexMapping &self, MPI_int rank, index val)
147 { return self.operator()(rank, val); }, py::arg("rank"), py::arg("val"));
148 ;
149 }
150
156}
Shared pybind11 plumbing used by every *_bind.hpp in DNDS (buffer-protocol type check,...
Global-to-local index mapping for distributed arrays.
Eigen::Matrix< real, 3, 3 > m
Table mapping rank-local row indices to the global index space.
index globalSize() const
Total number of rows across all ranks.
t_IndexVec & ROffsets()
Prefix-sum offsets vector (size == nRanks + 1, last element == globalSize).
void setMPIAlignBcast(const MPIInfo &mpi, index myLength)
Broadcast each rank's length, then compute the global prefix sums.
bool search(index globalQuery, MPI_int &rank, index &val) const
Convert a global index to (rank, local). Returns false if out of range.
t_IndexVec & RLengths()
Per-rank lengths vector (size == nRanks).
Mapping between a rank's main data and its ghost copies.
bool search_indexAppend(index globalQuery, MPI_int &rank, index &val) const
Like search, but the returned val is in the concatenated father+son address space.
t_IndexVec ghostIndex
Global indices of all ghost rows on this rank, ascending. (a.k.a. pullingIndexGlobal)
t_IndexVec pushingIndexGlobal
Global indices this rank sends to others, grouped by receiver.
bool search_indexRank(index globalQuery, MPI_int &rank, index &val) const
Like search, but val is expressed relative to the owner rank's ghost slab (ghostStart[rank]-relative)...
index & ghostAt(MPI_int rank, index ighost)
Direct mutable access to the ighost-th ghost global index for peer rank.
tMPI_intVec pushIndexSizes
Per-peer number of rows this rank will send out on a push.
t_MapIndexVec ghostStart
Per-peer prefix-sum offsets into ghostIndex (size == nRanks + 1). (a.k.a. pullIndexStarts)
tMPI_intVec ghostSizes
Number of ghost rows pulled from each peer rank. (a.k.a. pullIndexSizes)
t_IndexVec pullingRequestLocal
Optional cached local-index form of ghostIndex (unused in current code).
t_MapIndexVec pushIndexStarts
Per-peer prefix-sum offsets into pushingIndexGlobal.
bool search(index globalQuery, MPI_int &rank, index &val) const
Search main + ghost in one call. rank == -1 signals "hit in main".
the host side operators are provided as implemented
void pybind11_bind_IndexMapping_All(const py::module_ &m)
py::classh< T > py_class_ssp
auto pybind11_GlobalOffsetsMapping_declare(py::module_ m)
void pybind11_OffsetAscendIndexMapping_define(py::module_ m)
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:112
auto pybind11_OffsetAscendIndexMapping_declare(py::module_ m)
void pybind11_GlobalOffsetsMapping_define(py::module_ m)
auto pybind11_OffsetAscendIndexMapping_get_class(const py::module_ &m)
py::memoryview py_vector_as_memory_view(std::vector< T > &vec, bool readonly)
auto pybind11_GlobalOffsetsMapping_get_class(const py::module_ &m)
int MPI_int
MPI counterpart type for MPI_int (= C int). Used for counts and ranks in MPI calls.
Definition MPI.hpp:54
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:231