/[escript]/trunk/cusplibrary/performance/graph/breadth_first_search.cu
ViewVC logotype

Contents of /trunk/cusplibrary/performance/graph/breadth_first_search.cu

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (6 years, 4 months ago) by caltinay
File size: 1625 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 #include <cusp/csr_matrix.h>
2 #include <cusp/print.h>
3
4 #include <cusp/gallery/poisson.h>
5 #include <cusp/graph/breadth_first_search.h>
6 #include <cusp/io/matrix_market.h>
7
8 #include "../timer.h"
9
10 template<typename MemorySpace, typename MatrixType>
11 void BFS(const MatrixType& G)
12 {
13 typedef typename MatrixType::index_type IndexType;
14 typedef cusp::csr_matrix<IndexType,IndexType,MemorySpace> GraphType;
15
16 GraphType G_bfs(G);
17 IndexType source = 0;
18 cusp::array1d<IndexType,MemorySpace> labels(G.num_rows);
19
20 timer t;
21 cusp::graph::breadth_first_search<false>(G_bfs, source, labels);
22 std::cout << "BFS time : " << t.milliseconds_elapsed() << " (ms)." << 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 = 1024;
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 BFS<cusp::device_memory>(A);
54
55 std::cout << " Host ";
56 BFS<cusp::host_memory>(A);
57
58 return EXIT_SUCCESS;
59 }
60

  ViewVC Help
Powered by ViewVC 1.1.26