1 |
#include <cusp/csr_matrix.h> |
2 |
#include <cusp/print.h> |
3 |
|
4 |
#include <cusp/gallery/poisson.h> |
5 |
#include <cusp/graph/connected_components.h> |
6 |
#include <cusp/io/matrix_market.h> |
7 |
|
8 |
#include "../timer.h" |
9 |
|
10 |
template<typename MemorySpace, typename MatrixType> |
11 |
void CC(const MatrixType& G) |
12 |
{ |
13 |
typedef typename MatrixType::index_type IndexType; |
14 |
typedef cusp::csr_matrix<IndexType,IndexType,MemorySpace> GraphType; |
15 |
|
16 |
GraphType G_cc(G); |
17 |
cusp::array1d<IndexType,MemorySpace> components(G.num_rows); |
18 |
|
19 |
timer t; |
20 |
size_t num_components = cusp::graph::connected_components(G_cc, components); |
21 |
std::cout << "CC time : " << t.milliseconds_elapsed() << " (ms)." << std::endl; |
22 |
std::cout << "Number of components : " << num_components << std::endl; |
23 |
} |
24 |
|
25 |
int main(int argc, char*argv[]) |
26 |
{ |
27 |
srand(time(NULL)); |
28 |
|
29 |
typedef int IndexType; |
30 |
typedef float ValueType; |
31 |
typedef cusp::host_memory MemorySpace; |
32 |
|
33 |
cusp::csr_matrix<IndexType, ValueType, MemorySpace> A; |
34 |
size_t size = 512; |
35 |
|
36 |
if (argc == 1) |
37 |
{ |
38 |
// no input file was specified, generate an example |
39 |
std::cout << "Generated matrix (poisson5pt) "; |
40 |
cusp::gallery::poisson5pt(A, size, size); |
41 |
} |
42 |
else if (argc == 2) |
43 |
{ |
44 |
// an input file was specified, read it from disk |
45 |
cusp::io::read_matrix_market_file(A, argv[1]); |
46 |
std::cout << "Read matrix (" << argv[1] << ") "; |
47 |
} |
48 |
|
49 |
std::cout << "with shape (" << A.num_rows << "," << A.num_cols << ") and " |
50 |
<< A.num_entries << " entries" << "\n\n"; |
51 |
|
52 |
std::cout << " Device "; |
53 |
CC<cusp::device_memory>(A); |
54 |
|
55 |
std::cout << " Host "; |
56 |
CC<cusp::host_memory>(A); |
57 |
|
58 |
return EXIT_SUCCESS; |
59 |
} |
60 |
|