@@ -90,11 +90,12 @@ inline std::ostream &operator<<(std::ostream &os, MEMORY_CONSTRAINT_TYPE type) {
9090 * bounds. It provides methods to set and retrieve these values.
9191 *
9292 * **Processors:**
93- * The architecture consists of p processors, indexed from 0 to p-1.
93+ * The architecture consists of p processors, indexed from 0 to p-1. Note that processor indices are represented using `unsigned`.
9494 *
9595 * **Processor Types:**
9696 * Processors can have different types, which are represented by non-negative integers.
97- * Processor types are assumed to be consecutive integers starting from 0.
97+ * Processor types are assumed to be consecutive integers starting from 0. Note that processor types are represented using `unsigned`.
98+ * Processor types are used to express compatabilities, which can be specified in the BspInstance, regarding node types.
9899 *
99100 * **Communication and Synchronization Costs:**
100101 * - Communication Cost (g): The cost of communicating a unit of data between processors, i.e., the bandwidth.
@@ -185,46 +186,53 @@ class BspArchitecture {
185186 }
186187
187188 public:
188- /* *
189- * @brief Default constructor.
190- * Initializes a BSP architecture with 2 processors, 1 processor type,
191- * communication costs of 1, synchronisation costs of 2, memory bounds of 100,
192- * and send costs of 1 between all processors.
193- */
194- BspArchitecture ()
195- : numberOfProcessors_(2U ), numberOfProcessorTypes_(1U ), communicationCosts_(1U ), synchronisationCosts_(2U ),
196- memoryBound_ (numberOfProcessors_, 100U ), isNuma_(false ),
197- processorTypes_(numberOfProcessors_, 0U ), sendCosts_(numberOfProcessors_ * numberOfProcessors_, 1U ) {
198- SetSendCostDiagonalToZero ();
199- }
200-
201- BspArchitecture (const BspArchitecture &other) = default;
202- BspArchitecture (BspArchitecture &&other) noexcept = default;
203- BspArchitecture &operator =(const BspArchitecture &other) = default ;
204- BspArchitecture &operator =(BspArchitecture &&other) noexcept = default ;
205- virtual ~BspArchitecture () = default ;
206-
207189 /* *
208190 * @brief Constructs a BspArchitecture object with the specified number of processors, communication cost, and
209191 * synchronization cost.
210192 *
211- * @param NumberOfProcessors The number of processors in the architecture. Must be greater than 0.
212- * @param CommunicationCost The communication cost between processors.
213- * @param SynchronisationCost The synchronization cost between processors.
193+ * @param NumberOfProcessors The number of processors in the architecture. Must be greater than 0. Default: 2.
194+ * @param CommunicationCost The communication cost between processors. Default: 1.
195+ * @param SynchronisationCost The synchronization cost between processors. Default: 2.
214196 * @param MemoryBound The memory bound for each processor (default: 100).
197+ * @param SendCosts The matrix of send costs between processors. Needs to be a processors x processors matrix. Diagonal entries are forced to zero. Default: empty (uniform costs).
215198 */
216- BspArchitecture (const unsigned NumberOfProcessors, const v_commw_t <Graph_t> CommunicationCost, const v_commw_t <Graph_t> SynchronisationCost,
217- const v_memw_t <Graph_t> MemoryBound = 100U )
199+ BspArchitecture (const unsigned NumberOfProcessors = 2U , const v_commw_t <Graph_t> CommunicationCost = 1U , const v_commw_t <Graph_t> SynchronisationCost = 2U ,
200+ const v_memw_t <Graph_t> MemoryBound = 100U , const std::vector<std::vector< v_commw_t <Graph_t>>> &SendCosts = {} )
218201 : numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U ), communicationCosts_(CommunicationCost),
219202 synchronisationCosts_ (SynchronisationCost),
220203 memoryBound_(NumberOfProcessors, MemoryBound), isNuma_(false ),
221- processorTypes_(NumberOfProcessors, 0U ), sendCosts_(NumberOfProcessors * NumberOfProcessors, 1U ) {
204+ processorTypes_(NumberOfProcessors, 0U ) {
222205 if (NumberOfProcessors == 0U ) {
223206 throw std::runtime_error (" BspArchitecture: Number of processors must be greater than 0." );
224207 }
225- SetSendCostDiagonalToZero ();
208+
209+ if (SendCosts.empty ()) {
210+ InitializeUniformSendCosts ();
211+ } else {
212+ if (NumberOfProcessors != SendCosts.size ()) {
213+ throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
214+ }
215+ if (std::any_of (SendCosts.begin (), SendCosts.end (),
216+ [NumberOfProcessors](const auto &thing) { return thing.size () != NumberOfProcessors; })) {
217+ throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
218+ }
219+
220+ sendCosts_.reserve (NumberOfProcessors * NumberOfProcessors);
221+ for (const auto &row : SendCosts) {
222+ sendCosts_.insert (sendCosts_.end (), row.begin (), row.end ());
223+ }
224+
225+ SetSendCostDiagonalToZero ();
226+ isNuma_ = AreSendCostsNuma ();
227+ }
226228 }
227229
230+ BspArchitecture (const BspArchitecture &other) = default;
231+ BspArchitecture (BspArchitecture &&other) noexcept = default;
232+ BspArchitecture &operator =(const BspArchitecture &other) = default ;
233+ BspArchitecture &operator =(BspArchitecture &&other) noexcept = default ;
234+ virtual ~BspArchitecture () = default ;
235+
228236 /* *
229237 * @brief Copy constructor from a BspArchitecture with a different graph type.
230238 *
@@ -258,62 +266,7 @@ class BspArchitecture {
258266 */
259267 BspArchitecture (const unsigned NumberOfProcessors, const v_commw_t <Graph_t> CommunicationCost, const v_commw_t <Graph_t> SynchronisationCost,
260268 const std::vector<std::vector<v_commw_t <Graph_t>>> &SendCosts)
261- : numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U ), communicationCosts_(CommunicationCost),
262- synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, 100U ),
263- processorTypes_(NumberOfProcessors, 0U ) {
264- if (NumberOfProcessors == 0U ) {
265- throw std::runtime_error (" BspArchitecture: Number of processors must be greater than 0." );
266- }
267- if (NumberOfProcessors != SendCosts.size ()) {
268- throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
269- }
270- if (std::any_of (SendCosts.begin (), SendCosts.end (),
271- [NumberOfProcessors](const auto &thing) { return thing.size () != NumberOfProcessors; })) {
272- throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
273- }
274-
275- sendCosts_.reserve (NumberOfProcessors * NumberOfProcessors);
276- for (const auto &row : SendCosts) {
277- sendCosts_.insert (sendCosts_.end (), row.begin (), row.end ());
278- }
279-
280- SetSendCostDiagonalToZero ();
281- isNuma_ = AreSendCostsNuma ();
282- }
283-
284- /* *
285- * @brief Constructs a BspArchitecture object with custom send costs and memory bound.
286- *
287- * @param NumberOfProcessors The number of processors. Must be greater than 0.
288- * @param CommunicationCost The communication cost.
289- * @param SynchronisationCost The synchronization cost.
290- * @param MemoryBound The memory bound for each processor.
291- * @param SendCosts The matrix of send costs between processors. Needs to be a processors x processors matrix. Diagonal entries are forced to zero.
292- */
293- BspArchitecture (const unsigned NumberOfProcessors, const v_commw_t <Graph_t> CommunicationCost, const v_commw_t <Graph_t> SynchronisationCost,
294- const v_memw_t <Graph_t> MemoryBound, const std::vector<std::vector<v_commw_t <Graph_t>>> &SendCosts)
295- : numberOfProcessors_(NumberOfProcessors), numberOfProcessorTypes_(1U ), communicationCosts_(CommunicationCost),
296- synchronisationCosts_(SynchronisationCost), memoryBound_(NumberOfProcessors, MemoryBound),
297- processorTypes_(NumberOfProcessors, 0U ) {
298- if (NumberOfProcessors == 0U ) {
299- throw std::runtime_error (" BspArchitecture: Number of processors must be greater than 0." );
300- }
301- if (NumberOfProcessors != SendCosts.size ()) {
302- throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
303- }
304- if (std::any_of (SendCosts.begin (), SendCosts.end (),
305- [NumberOfProcessors](const auto &thing) { return thing.size () != NumberOfProcessors; })) {
306- throw std::invalid_argument (" sendCosts_ needs to be a processors x processors matrix.\n " );
307- }
308-
309- sendCosts_.reserve (NumberOfProcessors * NumberOfProcessors);
310- for (const auto &row : SendCosts) {
311- sendCosts_.insert (sendCosts_.end (), row.begin (), row.end ());
312- }
313-
314- SetSendCostDiagonalToZero ();
315- isNuma_ = AreSendCostsNuma ();
316- }
269+ : BspArchitecture(NumberOfProcessors, CommunicationCost, SynchronisationCost, 100U , SendCosts) {}
317270
318271 /* *
319272 * @brief Sets the uniform send cost for each pair of processors.
@@ -636,6 +589,7 @@ class BspArchitecture {
636589
637590 /* *
638591 * @brief Returns the send costs between two processors. Does not perform bounds checking.
592+ * Does not the communication costs into account.
639593 *
640594 * @param p1 The index of the first processor.
641595 * @param p2 The index of the second processor.
0 commit comments