From 010a2908cfd3ca74fcf9a8f598ab33cf3e0651bd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 23 Apr 2021 04:50:38 +0000 Subject: [PATCH] adding print::head utility function --- examples/color/color.cu | 9 +++--- examples/pr/pr.cu | 10 ++----- examples/sssp/sssp.cu | 15 ++-------- include/gunrock/applications/application.hxx | 1 + include/gunrock/util/print.hxx | 30 ++++++++++++++++++++ 5 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 include/gunrock/util/print.hxx diff --git a/examples/color/color.cu b/examples/color/color.cu index ad6dcd35..ab938096 100644 --- a/examples/color/color.cu +++ b/examples/color/color.cu @@ -48,16 +48,15 @@ void test_color(int num_arguments, char** argument_array) { // -- // Run problem - float elapsed = gunrock::color::run(G, colors.data().get()); + float gpu_elapsed = gunrock::color::run(G, colors.data().get()); // -- // Log - std::cout << "Colors (output) = "; - thrust::copy(colors.begin(), colors.end(), - std::ostream_iterator(std::cout, " ")); + std::cout << "colors[:40] = "; + gunrock::print::head(colors, 40); std::cout << std::endl; - std::cout << "color Elapsed Time: " << elapsed << " (ms)" << std::endl; + std::cout << "GPU Elapsed Time: " << gpu_elapsed << " (ms)" << std::endl; } int main(int argc, char** argv) { diff --git a/examples/pr/pr.cu b/examples/pr/pr.cu index beacbc7d..b2d63bc1 100644 --- a/examples/pr/pr.cu +++ b/examples/pr/pr.cu @@ -60,19 +60,13 @@ void test_sssp(int num_arguments, char** argument_array) { // -- // GPU Run - std::cout << "gunrock::pr::run -- starting" << std::endl; float gpu_elapsed = gunrock::pr::run(G, alpha, tol, p.data().get()); - std::cout << "gunrock::pr::run -- complete" << std::endl; // -- // Log + Validate - std::cout << "GPU p (output) = "; - thrust::copy(p.begin(), - (p.size() < 40) ? p.begin() + p.size() - : p.begin() + 40, - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; + std::cout << "GPU p[:40] = "; + gunrock::print::head(p, 40); std::cout << "GPU Elapsed Time : " << gpu_elapsed << " (ms)" << std::endl; } diff --git a/examples/sssp/sssp.cu b/examples/sssp/sssp.cu index 9961a6dd..728a4503 100644 --- a/examples/sssp/sssp.cu +++ b/examples/sssp/sssp.cu @@ -71,20 +71,11 @@ void test_sssp(int num_arguments, char** argument_array) { // -- // Log + Validate - std::cout << "GPU Distances (output) = "; - thrust::copy(distances.begin(), - (distances.size() < 40) ? distances.begin() + distances.size() - : distances.begin() + 40, - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; + std::cout << "GPU distances[:40] = "; + gunrock::print::head(distances, 40); std::cout << "CPU Distances (output) = "; - thrust::copy(h_distances.begin(), - (h_distances.size() < 40) - ? h_distances.begin() + h_distances.size() - : h_distances.begin() + 40, - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; + gunrock::print::head(h_distances, 40); std::cout << "GPU Elapsed Time : " << gpu_elapsed << " (ms)" << std::endl; std::cout << "CPU Elapsed Time : " << cpu_elapsed << " (ms)" << std::endl; diff --git a/include/gunrock/applications/application.hxx b/include/gunrock/applications/application.hxx index e04a1d46..07570b7b 100644 --- a/include/gunrock/applications/application.hxx +++ b/include/gunrock/applications/application.hxx @@ -19,6 +19,7 @@ // Utility includes #include +#include // Format includes #include diff --git a/include/gunrock/util/print.hxx b/include/gunrock/util/print.hxx new file mode 100644 index 00000000..6cc79c92 --- /dev/null +++ b/include/gunrock/util/print.hxx @@ -0,0 +1,30 @@ +/** + * @file print.hxx + * + * @brief + */ + +#pragma once + +namespace gunrock { + +/** + * @namespace print + * Print utilities. + */ +namespace print { + +// Print the first k elements of a `thrust` vector +template +void head(vec_t& x, int k) { + thrust::copy( + x.begin(), + (x.size() < k) ? x.begin() + x.size() : x.begin() + k, + std::ostream_iterator(std::cout, " ") + ); + std::cout << std::endl; +} + + +} // namespace print +} // namespace gunrock \ No newline at end of file