DNDSR 0.1.0.dev1+gcd065ad
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
11namespace py = pybind11;
12
13namespace DNDS
14{
15 inline auto pybind11_GlobalOffsetsMapping_declare(py::module_ m)
16 {
17 return py_class_ssp<GlobalOffsetsMapping>(m, "GlobalOffsetsMapping");
18 }
19
20 inline auto pybind11_GlobalOffsetsMapping_get_class(py::module_ m)
21 {
22 return py_class_ssp<GlobalOffsetsMapping>(m.attr("GlobalOffsetsMapping"));
23 }
24
25 inline void pybind11_GlobalOffsetsMapping_define(py::module_ m)
26 {
27 auto Py_GlobalOffsetsMapping = pybind11_GlobalOffsetsMapping_declare(m);
28
29 Py_GlobalOffsetsMapping
30 .def(py::init<>())
31 .def("globalSize", &GlobalOffsetsMapping::globalSize)
32 .def("setMPIAlignBcast", &GlobalOffsetsMapping::setMPIAlignBcast)
33 .def(
34 "RLengths",
35 [](GlobalOffsetsMapping &self)
36 {
37 return py_vector_as_memory_view(self.RLengths(), true);
38 },
39 py::keep_alive<0, 1>())
40 .def(
41 "ROffsets",
42 [](GlobalOffsetsMapping &self)
43 {
44 return py_vector_as_memory_view(self.ROffsets(), true);
45 },
46 py::keep_alive<0, 1>())
47 .def("search", [](GlobalOffsetsMapping &self, index globalQuery)
48 { return self.search(globalQuery); }, py::arg("globalQuery"))
49 .def("__call__", [](GlobalOffsetsMapping &self, MPI_int rank, index val)
50 { return self.operator()(rank, val); }, py::arg("rank"), py::arg("val"));
51 }
52
54 {
55 return py_class_ssp<OffsetAscendIndexMapping>(m, "OffsetAscendIndexMapping");
56 }
57
59 {
60 return py_class_ssp<OffsetAscendIndexMapping>(m.attr("OffsetAscendIndexMapping"));
61 }
62
64 {
65 auto Py_OffsetAscendIndexMapping = pybind11_OffsetAscendIndexMapping_declare(m);
66
67 Py_OffsetAscendIndexMapping
68 .def(
69 py::init(
70 [](index nmainOffset, index nmainSize,
71 std::vector<index> pullingIndexGlobal,
72 const GlobalOffsetsMapping &LGlobalMapping, const MPIInfo &mpi)
73 { return std::make_shared<OffsetAscendIndexMapping>(nmainOffset, nmainSize, pullingIndexGlobal, LGlobalMapping, mpi); }),
74 py::arg("nmainOffset"), py::arg("nmainSize"),
75 py::arg("pullingIndexGlobal"),
76 py::arg("LGlobalMapping"), py::arg("mpi"))
77 .def(
78 py::init([](index nmainOffset, index nmainSize,
79 std::vector<index> pushingIndexesLocal, // which stores local index
80 std::vector<index> pushingStarts,
81 const GlobalOffsetsMapping &LGlobalMapping,
82 const MPIInfo &mpi)
83 { return std::make_shared<OffsetAscendIndexMapping>(
84 nmainOffset, nmainSize, pushingIndexesLocal, pushingStarts, LGlobalMapping, mpi); }),
85 py::arg("nmainOffset"), py::arg("nmainSize"),
86 py::arg("pushingIndexLocal"), py::arg("pushingStarts"),
87 py::arg("LGlobalMapping"), py::arg("mpi"))
88 .def("ghostAt", &OffsetAscendIndexMapping::ghostAt)
89 .def_property_readonly(
90 "ghostIndex",
92 {
93 return py_vector_as_memory_view(self.ghostIndex, true);
94 },
95 py::keep_alive<0, 1>())
96 .def_property_readonly(
97 "ghostSizes",
99 {
100 return py_vector_as_memory_view(self.ghostSizes, true);
101 },
102 py::keep_alive<0, 1>())
103 .def_property_readonly(
104 "ghostStart",
106 {
107 return py_vector_as_memory_view(self.ghostStart, true);
108 },
109 py::keep_alive<0, 1>())
110 .def_property_readonly(
111 "pullingRequestLocal",
113 {
115 },
116 py::keep_alive<0, 1>())
117 .def_property_readonly(
118 "pushingIndexGlobal",
120 {
122 },
123 py::keep_alive<0, 1>())
124 .def_property_readonly(
125 "pushIndexSizes",
127 {
128 return py_vector_as_memory_view(self.pushIndexSizes, true);
129 },
130 py::keep_alive<0, 1>())
131 .def_property_readonly(
132 "pushIndexStarts",
134 {
135 return py_vector_as_memory_view(self.pushIndexStarts, true);
136 },
137 py::keep_alive<0, 1>())
138 .def("search", [&](OffsetAscendIndexMapping &self, index globalQuery)
139 { return self.search(globalQuery); }, py::arg("globalQuery"))
140 .def("search_indexAppend", [&](OffsetAscendIndexMapping &self, index globalQuery)
141 { return self.search_indexAppend(globalQuery); }, py::arg("globalQuery"))
142 .def("search_indexRank", [&](OffsetAscendIndexMapping &self, index globalQuery)
143 { return self.search_indexRank(globalQuery); }, py::arg("globalQuery"))
144 .def("__call__", [&](OffsetAscendIndexMapping &self, MPI_int rank, index val)
145 { return self.operator()(rank, val); }, py::arg("rank"), py::arg("val"));
146 ;
147 }
148
154}
Shared pybind11 plumbing used by every *_bind.hpp in DNDS (buffer-protocol type check,...
Global-to-local index mapping for distributed arrays.
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
py::classh< T > py_class_ssp
auto pybind11_GlobalOffsetsMapping_declare(py::module_ m)
void pybind11_bind_IndexMapping_All(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:107
auto pybind11_OffsetAscendIndexMapping_declare(py::module_ m)
auto pybind11_OffsetAscendIndexMapping_get_class(py::module_ m)
void pybind11_GlobalOffsetsMapping_define(py::module_ m)
auto pybind11_GlobalOffsetsMapping_get_class(py::module_ m)
py::memoryview py_vector_as_memory_view(std::vector< T > &vec, bool readonly)
int MPI_int
MPI counterpart type for MPI_int (= C int). Used for counts and ranks in MPI calls.
Definition MPI.hpp:43
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:215