Skip to content

Commit d3bab40

Browse files
committed
[dist] revert coll-comm creator function
1 parent a8119d6 commit d3bab40

File tree

7 files changed

+47
-49
lines changed

7 files changed

+47
-49
lines changed

core/distributed/dense_communicator.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,15 @@ request DenseCommunicator::i_all_to_all_v_impl(
110110
}
111111

112112

113-
CollectiveCommunicator::creator_fn DenseCommunicator::creator_with_same_type()
114-
const
113+
std::unique_ptr<CollectiveCommunicator>
114+
DenseCommunicator::create_with_same_type(communicator base,
115+
index_map_ptr imap) const
115116
{
116-
return [](communicator base, index_map_ptr imap) {
117-
return std::visit(
118-
[base](auto imap_) {
119-
return std::make_unique<DenseCommunicator>(base, *imap_);
120-
},
121-
imap);
122-
};
117+
return std::visit(
118+
[base](const auto* imap) {
119+
return std::make_unique<DenseCommunicator>(base, *imap);
120+
},
121+
imap);
123122
}
124123

125124

core/distributed/matrix.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
101101

102102
row_gatherer_ = RowGatherer<LocalIndexType>::create(
103103
row_gatherer_->get_executor(),
104-
row_gatherer_->get_collective_communicator()->creator_with_same_type(),
105-
comm, imap_);
104+
row_gatherer_->get_collective_communicator()->create_with_same_type(
105+
comm, &imap_),
106+
imap_);
106107
}
107108

108109

@@ -340,8 +341,9 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::read_distributed(
340341

341342
row_gatherer_ = RowGatherer<LocalIndexType>::create(
342343
row_gatherer_->get_executor(),
343-
row_gatherer_->get_collective_communicator()->creator_with_same_type(),
344-
comm, imap_);
344+
row_gatherer_->get_collective_communicator()->create_with_same_type(
345+
comm, &imap_),
346+
imap_);
345347
}
346348

347349

core/distributed/neighborhood_communicator.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,16 @@ request NeighborhoodCommunicator::i_all_to_all_v_impl(
156156
}
157157

158158

159-
CollectiveCommunicator::creator_fn
160-
NeighborhoodCommunicator::creator_with_same_type() const
159+
std::unique_ptr<CollectiveCommunicator>
160+
NeighborhoodCommunicator::create_with_same_type(communicator base,
161+
index_map_ptr imap) const
161162
{
162-
return [](communicator base, index_map_ptr imap) {
163-
return std::visit(
164-
[base](auto imap_) {
165-
return std::unique_ptr<CollectiveCommunicator>(
166-
std::make_unique<NeighborhoodCommunicator>(base, *imap_));
167-
},
168-
imap);
169-
};
163+
return std::visit(
164+
[base](const auto* imap) {
165+
return std::unique_ptr<CollectiveCommunicator>(
166+
new NeighborhoodCommunicator(base, *imap));
167+
},
168+
imap);
170169
}
171170

172171

include/ginkgo/core/distributed/collective_communicator.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ class CollectiveCommunicator {
3838
const distributed::index_map<int32, int64>*,
3939
const distributed::index_map<int64, int64>*>;
4040

41-
/**
42-
* Creator function to create a new CollectiveCommunicator from a
43-
* communicator and a pointer to an index_map.
44-
*/
45-
using creator_fn = std::function<std::unique_ptr<CollectiveCommunicator>(
46-
communicator, index_map_ptr)>;
47-
4841
virtual ~CollectiveCommunicator() = default;
4942

5043
explicit CollectiveCommunicator(communicator base = MPI_COMM_NULL);
@@ -81,10 +74,15 @@ class CollectiveCommunicator {
8174
void* recv_buffer, MPI_Datatype recv_type) const;
8275

8376
/**
84-
* Returns a CollectiveCommunicator::creator_fn which will create a new
85-
* CollectiveCommunicator with the same dynamic type.
77+
* Creates a new CollectiveCommunicator with the same dynamic type.
78+
*
79+
* @param base The base communicator
80+
* @param imap The index_map that defines the communication pattern
81+
*
82+
* @return a CollectiveCommunicator with the same dynamic type
8683
*/
87-
[[nodiscard]] virtual creator_fn creator_with_same_type() const = 0;
84+
[[nodiscard]] virtual std::unique_ptr<CollectiveCommunicator>
85+
create_with_same_type(communicator base, index_map_ptr imap) const = 0;
8886

8987
/**
9088
* Creates a CollectiveCommunicator with the inverse communication pattern
@@ -97,16 +95,16 @@ class CollectiveCommunicator {
9795
create_inverse() const = 0;
9896

9997
/**
100-
* Get the total number of received elements this communication patterns
101-
* expects.
98+
* Get the number of elements received by this process within this
99+
* communication pattern.
102100
*
103101
* @return number of received elements.
104102
*/
105103
[[nodiscard]] virtual comm_index_type get_recv_size() const = 0;
106104

107105
/**
108-
* Get the total number of sent elements this communication patterns
109-
* expects.
106+
* Get the number of elements sent by this process within this communication
107+
* pattern.
110108
*
111109
* @return number of sent elements.
112110
*/

include/ginkgo/core/distributed/dense_communicator.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class DenseCommunicator final : public CollectiveCommunicator {
6464
communicator base,
6565
const distributed::index_map<LocalIndexType, GlobalIndexType>& imap);
6666

67-
[[nodiscard]] creator_fn creator_with_same_type() const override;
67+
[[nodiscard]] std::unique_ptr<CollectiveCommunicator> create_with_same_type(
68+
communicator base, index_map_ptr imap) const override;
6869

6970
/**
7071
* Creates the inverse DenseCommunicator by switching sources

include/ginkgo/core/distributed/neighborhood_communicator.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class NeighborhoodCommunicator final : public CollectiveCommunicator {
6868
communicator base,
6969
const distributed::index_map<LocalIndexType, GlobalIndexType>& imap);
7070

71-
creator_fn creator_with_same_type() const override;
71+
std::unique_ptr<CollectiveCommunicator> create_with_same_type(
72+
communicator base, index_map_ptr imap) const override;
7273

7374
/**
7475
* Creates the inverse NeighborhoodCommunicator by switching sources

include/ginkgo/core/distributed/row_gatherer.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,31 @@ class RowGatherer final
128128
* @tparam GlobalIndexType the global index type of the index map
129129
*
130130
* @param exec the executor
131-
* @param coll_comm_creator the collective communicator creator_fn
131+
* @param coll_comm the collective communicator
132132
* @param imap the index map defining which rows to gather
133133
*
134+
* @note The coll_comm and imap have to be compatible. The coll_comm must
135+
* send and recv exactly as many rows as the imap defines.
136+
*
134137
* @return a shared_ptr to the created distributed::RowGatherer
135138
*/
136139
template <typename GlobalIndexType = int64,
137140
typename = std::enable_if_t<sizeof(GlobalIndexType) >=
138141
sizeof(LocalIndexType)>>
139142
static std::unique_ptr<RowGatherer> create(
140143
std::shared_ptr<const Executor> exec,
141-
mpi::CollectiveCommunicator::creator_fn coll_comm_creator,
142-
mpi::communicator base_comm,
144+
std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
143145
const index_map<LocalIndexType, GlobalIndexType>& imap)
144146
{
145-
return std::unique_ptr<RowGatherer>(new RowGatherer(
146-
std::move(exec), coll_comm_creator(base_comm, &imap), imap));
147+
return std::unique_ptr<RowGatherer>(
148+
new RowGatherer(std::move(exec), std::move(coll_comm), imap));
147149
}
148150

149151
/*
150152
* Create method for an empty RowGatherer.
151153
*/
152154
static std::unique_ptr<RowGatherer> create(
153-
std::shared_ptr<const Executor> exec, mpi::communicator comm)
154-
{
155-
return std::unique_ptr<RowGatherer>(
156-
new RowGatherer(std::move(exec), std::move(comm)));
157-
}
155+
std::shared_ptr<const Executor> exec, mpi::communicator comm);
158156

159157
RowGatherer(const RowGatherer& o);
160158

0 commit comments

Comments
 (0)