-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
104 lines (94 loc) · 2.81 KB
/
main.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
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
#include <iostream>
#include <chrono>
#include "coloring.hpp"
using namespace std;
#ifdef __cplusplus
extern"C" {
#endif
#include "graphio.h"
#include "graph.h"
#ifdef __cplusplus
}
#endif
char gfile[2048];
ofstream myfiles;
void usage() {
printf("./coloring <filename> -t=THREADS\n");
exit(0);
}
/*
You can ignore the ewgths and vwghts. They are there as the read function expects those values
row_ptr and col_ind are the CRS entities. nov is the Number of Vertices
*/
/* ====== THE ALGORITHM ========
The algorithm implemented in this project follows the methodologies proposed by Deveci et al.
" Parallel Graph Coloring for Manycore Architectures
*/
void Store_Result(int result,string s)
{
if(strcmp(gfile,"af_shell10.mtx")==0)
{
myfiles.open("af_shell10.txt",std::ios::app);
myfiles<<result<<" "<<s<<"\n";
myfiles.close();
}
else if(strcmp(gfile,"bone010.mtx")==0)
{
myfiles.open("bone010.txt",std::ios::app);
myfiles<<result<<" "<<s<<"\n";
myfiles.close();
}
else if(strcmp(gfile,"coPapersDBLP.mtx")==0)
{
myfiles.open("coPapersDBLP.txt",std::ios::app);
myfiles<<result<<" "<<s<<"\n";
myfiles.close();
}
if(strcmp(gfile,"nlpkkt120.mtx")==0)
{
myfiles.open("nlpkkt120.txt",std::ios::app);
myfiles<<result<<" "<<s<<"\n";
myfiles.close();
}
}
int main(int argc, char *argv[])
{
string values=argv[2];
etype *row_ptr;
vtype *col_ind;
ewtype *ewghts;
vwtype *vwghts;
vtype nov;
int matrix[4][32];
std::chrono::high_resolution_clock::time_point begin, end, initial = std::chrono::high_resolution_clock::now();
if (argc < 2)
usage();
const char* fname = argv[1];
strcpy(gfile, fname);
begin = std::chrono::high_resolution_clock::now();
if (read_graph(gfile, &row_ptr, &col_ind, &ewghts, &vwghts, &nov, 0) == -1) {
printf("error in graph read\n");
exit(1);
}
end = std::chrono::high_resolution_clock::now();
cout << "Graph file read [" << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << " ms]"
<<endl<< "Starting graph coloring procedure" << endl;
GraphColoring coloring(row_ptr, col_ind, nov);
begin = std::chrono::high_resolution_clock::now();
coloring.perform_coloring();
end = std::chrono::high_resolution_clock::now();
cout << "Coloring finished [" << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << " ms]" << std::endl
<< "Starting accuracy computation procedure" << std::endl;
double accuracy = coloring.accuracy()*100;
end = std::chrono::high_resolution_clock::now();
int result= std::chrono::duration_cast<std::chrono::milliseconds>(end - initial).count();
cout<< "Coloring accuracy: " << accuracy << "%" <<endl << "Total time: "<< result << " ms" <<endl;
Store_Result(result,values);
cout <<endl;
return 0;
}