Skip to content

Commit f2b0da3

Browse files
Merge pull request #72 from Algebraic-Programming/types_in_arch_file_and_app
types in arch file reader + app update + fixes
2 parents 665abf1 + 04f0c47 commit f2b0da3

4 files changed

Lines changed: 62 additions & 8 deletions

File tree

apps/osp.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ int main(int argc, char *argv[]) {
7979
continue;
8080
}
8181

82-
std::cout << "Warning: assuming all node types can be scheduled on all processor types!\n";
83-
bspInstance.SetAllOnesCompatibilityMatrix();
82+
if (bspInstance.GetComputationalDag().NumVertexTypes() == bspInstance.GetArchitecture().GetNumberOfProcessorTypes()) {
83+
bspInstance.SetDiagonalCompatibilityMatrix(bspInstance.GetComputationalDag().NumVertexTypes());
84+
} else {
85+
std::cout << "Warning: Mismatch in number of node & processor types - assuming full compatibility instead!\n";
86+
bspInstance.SetAllOnesCompatibilityMatrix();
87+
}
8488

8589
std::vector<std::string> schedulersName(parser.scheduler_.size(), "");
8690
std::vector<bool> schedulersFailed(parser.scheduler_.size(), false);
@@ -93,6 +97,14 @@ int main(int argc, char *argv[]) {
9397
for (auto &algorithm : parser.scheduler_) {
9498
schedulersName[algorithmCounter] = algorithm.second.get_child("name").get_value<std::string>();
9599

100+
if (schedulersName[algorithmCounter].find("GrowLocal") != std::string::npos && bspInstance.HasAnyTypeRestrictions()) {
101+
schedulersFailed[algorithmCounter] = true;
102+
std::cerr << "Error: Algorithm" + algorithm.second.get_child("name").get_value<std::string>()
103+
+ " skipped, since GrowLocal cannot handle heterogeneous problem instances." << std::endl;
104+
algorithmCounter++;
105+
continue;
106+
}
107+
96108
const auto startTime = std::chrono::high_resolution_clock::now();
97109

98110
ReturnStatus returnStatus;
@@ -105,6 +117,7 @@ int main(int argc, char *argv[]) {
105117
std::cerr << "Error during execution of Scheduler " + algorithm.second.get_child("name").get_value<std::string>()
106118
+ "."
107119
<< std::endl;
120+
algorithmCounter++;
108121
continue;
109122
}
110123

@@ -198,13 +211,12 @@ int main(int argc, char *argv[]) {
198211
std::cout << "Number of Vertices: " + std::to_string(bspInstance.GetComputationalDag().NumVertices())
199212
+ " Number of Edges: " + std::to_string(bspInstance.GetComputationalDag().NumEdges())
200213
<< std::endl;
214+
std::vector<std::string> listOfFailed;
201215
for (size_t j = 0; j < parser.scheduler_.size(); j++) {
202-
size_t i = j;
203-
204-
i = ordering[j];
216+
size_t i = ordering[j];
205217

206218
if (schedulersFailed[i]) {
207-
std::cout << "scheduler " << schedulersName[i] << " failed." << std::endl;
219+
listOfFailed.push_back(schedulersName[i]);
208220
} else {
209221
std::cout << "total costs: " << std::right << std::setw(tw) << schedulersCosts[i]
210222
<< " work costs: " << std::right << std::setw(ww) << schedulersWorkCosts[i]
@@ -214,6 +226,13 @@ int main(int argc, char *argv[]) {
214226
<< " scheduler: " << schedulersName[i] << std::endl;
215227
}
216228
}
229+
if (listOfFailed.size() > 0) {
230+
std::cout << "The following schedulers failed: ";
231+
for(unsigned i = 0; i < listOfFailed.size(); ++i) {
232+
std::cout << ((i > 0) ? ", " : "") << listOfFailed[i];
233+
}
234+
std::cout << std::endl;
235+
}
217236
}
218237

219238
return 0;

apps/test_suite_runner/StringToScheduler/run_bsp_scheduler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ std::unique_ptr<ImprovementScheduler<GraphT>> GetBspImproverByName(const ConfigP
7979
const std::string improverName = algorithm.get_child("name").get_value<std::string>();
8080

8181
if (improverName == "kl_total_comm") {
82-
return std::make_unique<KlTotalCommImproverMt<GraphT>>();
82+
return std::make_unique<KlTotalCommImproverMt<GraphT>>(0);
8383
} else if (improverName == "kl_total_lambda_comm") {
84-
return std::make_unique<KlTotalLambdaCommImproverMt<GraphT>>();
84+
return std::make_unique<KlTotalLambdaCommImproverMt<GraphT>>(0);
8585
} else if (improverName == "hill_climb") {
8686
return std::make_unique<HillClimbingScheduler<GraphT>>();
8787
}

include/osp/auxiliary/io/arch_file_reader.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ bool ReadBspArchitecture(std::ifstream &infile, BspArchitecture<GraphT> &archite
8989
return false;
9090
}
9191

92+
// Read indicator bit of whether we have processor types
93+
bool hasProcTypes;
94+
if ((iss >> hasProcTypes) && hasProcTypes) {
95+
96+
// next line must have p non-negative integers with the processor types
97+
while (std::getline(infile, line)) {
98+
if (!line.empty() && line[0] != '%') {
99+
break;
100+
}
101+
}
102+
std::istringstream procTypes(line);
103+
unsigned type;
104+
for (unsigned proc = 0; proc < p; ++proc) {
105+
if (!(procTypes >> type)) {
106+
std::cerr << "Error: Failed to parse processor types in second line.\n";
107+
return false;
108+
}
109+
architecture.SetProcessorType(proc, type);
110+
}
111+
}
112+
92113
// Parse NUMA matrix (p x p entries)
93114
for (unsigned i = 0; i < p * p; ++i) {
94115
do {

include/osp/bsp/model/BspInstance.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,20 @@ class BspInstance {
313313
std::vector<bool>(architecture_.GetNumberOfProcessorTypes(), true));
314314
}
315315

316+
/**
317+
* @brief Checks if there are any incompatible nodetype-processortype pairs in the instance.
318+
*/
319+
bool HasAnyTypeRestrictions() const {
320+
for (VertexTypeTOrDefault node_type = 0; node_type < nodeProcessorCompatibility_.size(); ++node_type) {
321+
for (VertexTypeTOrDefault proc_type = 0; proc_type < nodeProcessorCompatibility_[node_type].size(); ++proc_type) {
322+
if(!nodeProcessorCompatibility_[node_type][proc_type]) {
323+
return true;
324+
}
325+
}
326+
}
327+
return false;
328+
}
329+
316330
/**
317331
* @brief Returns false if there is a node whose weight does not fit on any of its compatible processors.
318332
* @return True if the memory constraints are feasible, false otherwise.

0 commit comments

Comments
 (0)