Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Add print::head utility function #55

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions examples/color/color.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<weight_t>(std::cout, " "));
std::cout << "colors[:40] = ";
gunrock::print::head<weight_t>(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) {
Expand Down
10 changes: 2 additions & 8 deletions examples/pr/pr.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<weight_t>(std::cout, " "));
std::cout << std::endl;
std::cout << "GPU p[:40] = ";
gunrock::print::head<weight_t>(p, 40);
std::cout << "GPU Elapsed Time : " << gpu_elapsed << " (ms)" << std::endl;
}

Expand Down
15 changes: 3 additions & 12 deletions examples/sssp/sssp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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<weight_t>(std::cout, " "));
std::cout << std::endl;
std::cout << "GPU distances[:40] = ";
gunrock::print::head<weight_t>(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<weight_t>(std::cout, " "));
std::cout << std::endl;
gunrock::print::head<weight_t>(h_distances, 40);

std::cout << "GPU Elapsed Time : " << gpu_elapsed << " (ms)" << std::endl;
std::cout << "CPU Elapsed Time : " << cpu_elapsed << " (ms)" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions include/gunrock/applications/application.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// Utility includes
#include <gunrock/util/math.hxx>
#include <gunrock/util/print.hxx>

// Format includes
#include <gunrock/formats/formats.hxx>
Expand Down
30 changes: 30 additions & 0 deletions include/gunrock/util/print.hxx
Original file line number Diff line number Diff line change
@@ -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 <typename val_t, typename vec_t>
void head(vec_t& x, int k) {
thrust::copy(
x.begin(),
(x.size() < k) ? x.begin() + x.size() : x.begin() + k,
std::ostream_iterator<val_t>(std::cout, " ")
);
std::cout << std::endl;
}


} // namespace print
} // namespace gunrock