#include #include #include struct pair_hash { template size_t operator ()(const std::pair& pair) const { auto h1 = std::hash()(pair.first); auto h2 = std::hash()(pair.second); return h1^h2; } }; struct Graph { struct Node { int v, g; }; struct Edge { int u, v; }; int num_nodes; int num_edges; int num_gpus; std::vector edges; std::vector nodes; Graph(const std::string& path) : num_gpus {static_cast(tf::cuda_get_num_devices())} { std::ifstream ifs(path); if(!ifs) throw std::runtime_error("failed to open the file"); ifs >> num_nodes >> num_edges; nodes.resize(num_nodes); for(int i=0; i> nodes[i].g; } for(int i=0; i> e.u >> e.v; edges.push_back(e); } } Graph(int V, int E, int cuda_ratio) : num_nodes {V}, num_edges {E}, num_gpus {static_cast(tf::cuda_get_num_devices())} { std::unordered_set, pair_hash> set; num_edges = std::min(num_edges, (num_nodes)*(num_nodes-1)/2); for(int j=0; j p; p.first = rand() % num_nodes; p.second = rand() % num_nodes; while(set.find(p) != set.end() || p.first >= p.second) { p.first = rand() % num_nodes; p.second = rand() % num_nodes; if(p.first >= p.second) { std::swap(p.first, p.second); } }; set.insert(p); } for (auto& pair : set) { Edge e; e.u = pair.first; e.v = pair.second; edges.push_back(e); } set.clear(); } void dump(std::ostream& os) { os << num_nodes << ' ' << num_edges << '\n'; for(const auto& v : nodes) { os << v.g << '\n'; } for(const auto& e : edges) { os << e.u << ' ' << e.v << '\n'; } } size_t size() const { return nodes.size() + edges.size(); } }; // saxpy kernel template __global__ void add(T* x, T* y, T* z, int n) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < n) { z[i] = x[i] + y[i]; } } inline int N = 1024; std::chrono::microseconds measure_time_taskflow(const Graph&, unsigned, unsigned); std::chrono::microseconds measure_time_tbb(const Graph&, unsigned, unsigned); std::chrono::microseconds measure_time_omp(const Graph&, unsigned, unsigned);