-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting.cu
122 lines (100 loc) · 2.59 KB
/
testing.cu
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
#include <algorithm>
#include <fstream>
#include <cmath>
#include <string>
extern "C" {
#include "mm_io/mm_io.h"
}
#include <sloan/common.h>
#include <sloan/timer.h>
#include <sloan/sloan.h>
#include <thrust/host_vector.h>
typedef typename thrust::host_vector<int> IntVector;
typedef typename thrust::host_vector<double> DoubleVector;
enum TestColor {
COLOR_NO = 0,
COLOR_RED,
COLOR_GREEN
};
// -----------------------------------------------------------------------------
class OutputItem
{
public:
OutputItem(std::ostream &o) : m_o(o), m_additional_item_count(19) {}
int m_additional_item_count;
template <typename T>
void operator() (T item, TestColor c = COLOR_NO)
{
m_o << "<td style=\"border-style: inset;\">\n";
switch (c)
{
case COLOR_RED:
m_o << "<p> <FONT COLOR=\"Red\">" << item << " </FONT> </p>\n";
break;
case COLOR_GREEN:
m_o << "<p> <FONT COLOR=\"Green\">" << item << " </FONT> </p>\n";
break;
default:
m_o << "<p> " << item << " </p>\n";
break;
}
m_o << "</td>\n";
}
private:
std::ostream &m_o;
};
int main(int argc, char **argv)
{
if (argc < 2) {
std::cerr << "Usage:\n driver input_file" << std::endl;
return 1;
}
// Read matrix from file (COO format)
MM_typecode matcode;
int M, N, nnz;
int* row_i;
int* col_j;
double* vals;
int err = mm_read_mtx_crd(argv[1], &M, &N, &nnz, &row_i, &col_j, &vals, &matcode);
if (err != 0) {
std::cerr << "error: " << err << std::endl;
return 1;
}
// Switch to 0-based indices
for (int i = 0; i < nnz; i++) {
row_i[i]--;
col_j[i]--;
}
// Convert to CSR format and load into thrust vectors.
IntVector row_offsets(N + 1);
IntVector column_indices(nnz);
DoubleVector values(nnz);
sloan::coo2csr(M, N, nnz, row_i, col_j, vals, row_offsets, column_indices, values);
// Run the RCM algorithm
sloan::Sloan algo(row_offsets, column_indices, values);
OutputItem outputItem(std::cout);
std::cout << "<tr valing=top>" << std::endl;
{
std::string fileMat(argv[1]);
int i;
for (i = fileMat.size()-1; i>=0 && fileMat[i] != '/' && fileMat[i] != '\\'; i--);
i++;
fileMat = fileMat.substr(i);
size_t j = fileMat.rfind(".mtx");
if (j != std::string::npos)
outputItem( fileMat.substr(0, j));
else
outputItem( fileMat);
}
outputItem(N);
outputItem(nnz);
sloan::CPUTimer cpu_timer;
cpu_timer.Start();
algo.execute();
cpu_timer.Stop();
outputItem(algo.getOriginalRMSWf());
outputItem(algo.getRMSWf());
outputItem(cpu_timer.getElapsed());
std::cout << "</tr>" << std::endl;
return 0;
}