Skip to content

Commit

Permalink
menu problems fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Edoardo Colella s257113 committed Dec 22, 2023
1 parent 122302e commit a4b46d9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
89 changes: 69 additions & 20 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,44 @@
#include <list>
#include "partitioning.h"


GraphPtr commandLoadFile(){
GraphPtr g = nullptr;
std::cout << "Enter graph path" << std::endl;
std::string path;
std::getline(std::cin, path);
g = loadFromFile(path);

if(g == nullptr) {
std::cout << "Graph not loaded" << std::endl << std::endl;
} else {
std::cout << "Graph loaded" << std::endl << std::endl;
}
return g;
}

void partitioning_s_test(GraphPtr& g, int requestedPartitions){
auto start_time_s = std::chrono::high_resolution_clock::now();
partitioning_s(g, requestedPartitions);
auto end_time_s = std::chrono::high_resolution_clock::now();
auto duration_s = std::chrono::duration_cast<std::chrono::milliseconds>(end_time_s - start_time_s).count();
std::cout << "Sequential partitioning done in " << duration_s << " ms" << std::endl << std::endl;
}

void partitioning_p_test(GraphPtr& g, int requestedPartitions){
for(int i = 2; i<= 8; i++){
auto start_time_s = std::chrono::high_resolution_clock::now();
partitioning_p(g, requestedPartitions, i);
auto end_time_s = std::chrono::high_resolution_clock::now();
auto duration_s = std::chrono::duration_cast<std::chrono::milliseconds>(end_time_s - start_time_s).count();
std::cout << "Parallel partitioning with " << i << " threads done in " << duration_s << " ms" << std::endl;
}
}

int main() {

int requestedPartitions;
char command = 's';
std::string path;
char command;// = 's';
GraphPtr g = nullptr;

int numThreads;
Expand All @@ -19,62 +52,78 @@ int main() {
std::cout << "C - sequential vs parallel comparison " << std::endl;
std::cout << "E - exit program " << std::endl;
std::cin >> command;
std::cin.ignore();
command = (char) toupper(command);

std::cout << "Selected option: " << command << std::endl;
switch (command) {
case 'G' :
try {
if (g == nullptr) {
std::cout << "Enter graph path" << std::endl;
char tmp;
std::cin >> tmp;
getline(std::cin, path);
g = loadFromFile(path);
g = commandLoadFile();

} else {
bool option = false;
std::cout << "Graph already loaded, overwrite it? (true or false) " << std::endl;
char option;
std::cout << "Graph already loaded, overwrite it? (y/n) " << std::endl;
std:: cin >> option;
if (option) {
std::cout << "Enter graph path" << std::endl;
getline(std::cin, path);
g = loadFromFile(path);
std::cin.ignore();
option = (char) toupper(option);
switch(option){
case 'Y':
g = commandLoadFile();
break;
case 'N':
std::cout << "Graph not overwritten" << std::endl << std::endl;
break;
default:
std::cout << "Invalid option" << std::endl << std::endl;
break;
}
}
}
catch (std::runtime_error &e) {
catch (std::exception &e) {
std::cout << e.what() << std::endl << std::endl;
}
break;
case 'S':
if (g == nullptr) {
std::cout << "Please load graph first" << std::endl;
std::cout << "Please load graph first" << std::endl << std::endl;
break;
}
std::cout << "Running sequential partitioning - (Multilevel KL)" << std::endl;
std::cout << "How many partitions should be found in graph?" << std::endl;
std::cin >> requestedPartitions;
partitioning_s(g, requestedPartitions);
std::cout << "Partitioning done" << std::endl << std::endl;

break;
case 'P':
if (g == nullptr) {
std::cout << "Please load graph first" << std::endl;
break;
}
std::cout << "Running parallel partitioning - ()" << std::endl;
std::cout << "How many partitions should be found in graph?" << std::endl;
std::cin >> requestedPartitions;
std::cout << "How many threads should be employed?" << std::endl;
std::cin >> numThreads;
partitioning_p(g, requestedPartitions, numThreads);
std::cout << "Partitioning done" << std::endl << std::endl;

break;
case 'C':
if (g == nullptr) {
std::cout << "Please load graph first" << std::endl;
std::cout << "Please load graph first" << std::endl << std::endl;
break;
}
//get timing to run sequential
// get timing to run parallel
//compare
std::cout << "How many partitions should be found in graph?" << std::endl;
std::cin >> requestedPartitions;

std::cout << "Running sequential partitioning - (Multilevel KL)" << std::endl;
partitioning_s_test(g, requestedPartitions);

std::cout << "Running parallel partitioning - (Multilevel KL) - 2->8 threads" << std::endl;
partitioning_p_test(g, requestedPartitions);
std::cout << std::endl;
break;
case 'E':
std::cout << "Exiting program" << std::endl;
Expand Down
1 change: 0 additions & 1 deletion src/test/memory-tester.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "../partitioning.h"
#include <ctype.h>
#include <fstream>
#include <iostream>
#include <math.h>
Expand Down
4 changes: 2 additions & 2 deletions src/test/tester.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <iostream>
#include <fstream>
#include <math.h>
#include <cmath>
#include "../partitioning.h"
const int NUM_THREAD = std::thread::hardware_concurrency();
const unsigned int NUM_THREAD = std::thread::hardware_concurrency();

void calculatePartitionStats(const std::vector<int> &partition_size, unsigned long *min_partition, unsigned long *max_partition,
unsigned long *avg_partition, unsigned long *median_partition, unsigned long long* std_dev_partition){
Expand Down

0 comments on commit a4b46d9

Please sign in to comment.