-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainSimpleParallel.cpp
128 lines (120 loc) · 4.42 KB
/
MainSimpleParallel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "simpleParallel/Graph.h"
#include "simpleParallel/ParallelKernelization.h"
#include <vector>
#include <memory>
#include "simpleParallel/ConnectednessTest.h"
#include "simpleParallel/ParallelB1.h"
#include <unistd.h>
//#include "simpleParallel/COO.h"
//#include "simpleParallel/CSR.h"
//#include "gpu/COO.cuh"
unsigned long long getTotalSystemMemory()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}
int main(int argc, char *argv[])
{
/* Num edges, N, N, random entries? */
std::cout << "Building G" << std::endl;
//Graph g("small.csv");
COO coordinateFormat;
// std::string filename = "small.csv";
// std::string filename = "25_nodes.csv";
// coordinateFormat.BuildCOOFromFile(filename);
// coordinateFormat.BuildTheExampleCOO();
coordinateFormat.BuildCycleCOO();
coordinateFormat.SetVertexCountFromEdges();
std::vector< std::vector<int> > vectorOfConnectedComponents;
ConnectednessTest ct(coordinateFormat, vectorOfConnectedComponents);
if (vectorOfConnectedComponents.size() > 1){
std::cout << "Graph isn't connected" << std::endl;
} else {
std::cout << "Graph is connected" << std::endl;
}
CSR csr(coordinateFormat);
Graph g(csr);
//int k = 15;
int k = 4;
ParallelKernelization sk(g, k);
sk.TestAValueOfK(k);
bool noSolutionExists = sk.EdgeCountKernel();
if(noSolutionExists){
std::cout << "|G'(E)| > k*k', no solution exists" << std::endl;
} else{
std::cout << "|G'(E)| <= k*k', a solution may exist" << std::endl;
}
//int treeSize = 200000;
int numberOfLevels = 5;
long long treeSize = ParallelB1::CalculateSpaceForDesiredNumberOfLevels(numberOfLevels);
long long expandedData = g.GetEdgesLeftToCover();
long long condensedData = g.GetVertexCount();
long long sizeOfSingleGraph = expandedData*2*sizeof(int) + 2*condensedData*sizeof(int);
long long totalMem = sizeOfSingleGraph * treeSize;
long long memAvail = getTotalSystemMemory();
std::cout << "You are about to allocate " << double(totalMem)/1024/1024/1024 << " GB" << std::endl;
std::cout << "Your system has " << double(memAvail)/1024/1024/1024 << " GB available" << std::endl;
do
{
std::cout << '\n' << "Press a key to continue...; ctrl-c to terminate";
} while (std::cin.get() != '\n');
std::vector< Graph > graphs(treeSize, Graph(g));
std::vector<int> mpt;
graphs[0].InitGPrime(g, mpt);
graphs[0].SetVerticesToIncludeInCover(g.GetVerticesThisGraphIncludedInTheCover());
//std::swap(graphs[0], gPrime);
std::vector<int> answer;
//ParallelB1::PopulateTree(treeSize, graphs, answer);
int result = ParallelB1::PopulateTreeParallelLevelWise(numberOfLevels, graphs, answer);
std::cout << std::endl;
if (result != -1){
ParallelB1::TraverseUpTree(result, graphs, answer);
std::cout << std::endl;
std::cout << "Found an answer" << std::endl;
for (auto & v: answer)
std::cout << v << " ";
std::cout << std::endl;
}
COO coordinateFormatTest;
coordinateFormatTest.BuildTheExampleCOO();
// coordinateFormatTest.BuildCOOFromFile(filename);
CSR csrTest(coordinateFormatTest);
Graph gTest(csrTest);
gTest.InitG(gTest, answer);
std::cout << "Edges remaining in original graph after removing answer : " << gTest.GetEdgesLeftToCover() << std::endl;
gTest.PrintEdgesRemaining();
/*
//Graph g(10);
//bool exists = pb1.IterateTreeStructure(&pb1, answer);
//if (exists){
// for (auto & v : answer)
// std::cout << v << " ";
// std::cout << std::endl;
//}
std::cout << "Building G" << std::endl;
Graph g("0.edges");
int k = 4;
std::cout << "Building PK" << std::endl;
ParallelKernelization sk(g, k);
int minK = 0;
int maxK = g.GetVertexCount();
for (int i = k; i < g.GetVertexCount(); ++i){
// If (noSolutionExists)
// If (Also clears and sets S if a sol'n could exist)
if (sk.TestAValueOfK(i))
continue;
else{
minK = i;
break;
}
}
std::cout << "Found min K : " << minK << std::endl;
std::vector<int> answer;
int kCovSize = binarySearch(answer,
minK,
maxK,
sk,
&g);
*/
}