Skip to content

Commit

Permalink
Added option to output colors to file
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-mp committed Jul 1, 2019
1 parent d86db11 commit 9c0de90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions perf_test/graph/KokkosGraph_color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void print_options(std::ostream &os, const char *app_name, unsigned int indent =
<< spaces << " --teamsize <N> Set the team size." << std::endl
<< spaces << " --vectorsize <N> Set the vector size." << std::endl
<< spaces << " --help Print out command line help." << std::endl
<< spaces << " --outputfile <FILE> Output the colors of the nodes to the file." << std::endl
<< spaces << " " << std::endl;
}

Expand Down Expand Up @@ -134,6 +135,9 @@ int parse_inputs (KokkosKernels::Experiment::Parameters &params, int argc, char
else if ( 0 == strcasecmp( argv[i] , "--verbose" ) ) {
params.verbose = 1;
}
else if ( 0 == strcasecmp( argv[i] , "--outputfile" ) || 0 == strcasecmp( argv[i] , "-o" ) ) {
params.coloring_output_file = argv[++i];
}
else if ( 0 == strcasecmp( argv[i] , "--algorithm" ) ) {
got_required_param_algorithm = true;
++i;
Expand Down Expand Up @@ -299,6 +303,9 @@ void run_experiment(
"Num Phases:" << kh.get_graph_coloring_handle()->get_num_phases() << std::endl;
std::cout << "\t"; KokkosKernels::Impl::print_1Dview(kh.get_graph_coloring_handle()->get_vertex_colors());

if( params.coloring_output_file != NULL ) {
KokkosKernels::Impl::print_to_file(kh.get_graph_coloring_handle()->get_vertex_colors(), params.coloring_output_file);
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/common/KokkosKernels_PrintUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "Kokkos_Core.hpp"
#include "Kokkos_Atomic.hpp"
#include "impl/Kokkos_Timer.hpp"
#include <fstream>

namespace KokkosKernels{

Expand Down Expand Up @@ -133,6 +134,27 @@ inline void kk_print_1Dview(idx_array_type view, bool print_all = false, size_t
}
}

/**
* \brief Stores the given view to a file.
* \param view: input view to store.
* \param file: the output file where the view is to be stored.
*/
template <typename idx_array_type>
inline void kk_print_to_file(idx_array_type view, char* file){

typedef typename idx_array_type::HostMirror host_type;
typedef typename idx_array_type::size_type idx;
host_type host_view = Kokkos::create_mirror_view (view);
Kokkos::deep_copy (host_view , view);
idx nr = host_view.extent(0);
std::ofstream out;
out.open(file);

for(idx i = 0; i < nr; ++i){
out << host_view(i) << "\n";
}
}

}
}

Expand Down
5 changes: 5 additions & 0 deletions src/common/KokkosKernels_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ void print_1Dview(idx_array_type view, bool print_all = false){
kk_print_1Dview(view, print_all);
}

template <typename idx_array_type>
void print_to_file(idx_array_type view, char* file){
kk_print_to_file(view, file);
}

template <typename lno_t, typename memory_space>
void print_1Dpointer(const lno_t *pview, size_t size, bool print_all = false){
typedef Kokkos::View<const lno_t *, memory_space, Kokkos::MemoryUnmanaged> um_array_type;
Expand Down

0 comments on commit 9c0de90

Please sign in to comment.