Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KokkosGraph: output colors assigned during graph coloring #444

Closed
rohit-mp opened this issue Jul 1, 2019 · 5 comments
Closed

KokkosGraph: output colors assigned during graph coloring #444

rohit-mp opened this issue Jul 1, 2019 · 5 comments

Comments

@rohit-mp
Copy link
Contributor

rohit-mp commented Jul 1, 2019

Currently, KokkosGraph coloring programs provide no option to output the colors assigned by it during its execution. It would be nice to have an option to output the colors to a file for later reference.

I tinkered with the source code a bit and got the feature running. So if it's fine, I'd like to create a PR for the same.

@srajama1
Copy link
Contributor

srajama1 commented Jul 1, 2019

@rohit-mp We will be happy to accept PRs for this. Just put me and @william76 on that PR, we can look at coloring related things.

@william76
Copy link
Contributor

@rohit-mp @srajama1

There is an interface in the distance-2 graph coloring handle to get the colors:
KokkosGraph::GraphColorDistance2Handle::get_vertex_colors() returns the graph colors into a view:

color_view_type get_vertex_colors() const { return this->vertex_colors; }

I did put in a function in the handle as well to dump out the coloring into a graphviz file. You can find that routine here:

/**
* Print / write out the graph in a GraphVIZ format.
*
* - Nodes colored with 1-5 will be filled in with some colors.
* - Nodes colored > 5 will be unfilled (i.e., white background).
* - Nodes colored with 0 (i.e., uncolored) will be filled in with red
* and will have a dashed border line. Uncolored nodes indicate a failed
* coloring.
*
* @param[in] os use std::cout for output to STDOUT stream, or a ofstream object
* (i.e., `std::ofstream os("G.dot", std::ofstream::out);`) to write
* to a file.
*/
template<typename kokkos_view_type, typename rowmap_type, typename entries_type>
void dump_graphviz(std::ostream& os,
const size_t num_verts,
rowmap_type& rowmap,
entries_type& entries,
kokkos_view_type& colors) const
{

It does more in there than you might want but it might be useful as a guide. An example of the graphviz writer being used lives in the distance-2 graph coloring perf test... if the graph has fewer than 1500 nodes, a .dot file will be output by the test application:

// Loop over # of experiments to run
for(int i = 0; i < repeat; ++i)
{
graph_compute_distance2_color(&kh, crsGraph.numRows(), crsGraph.numCols(), crsGraph.row_map, crsGraph.entries, crsGraph.row_map, crsGraph.entries);
total_colors += kh.get_distance2_graph_coloring_handle()->get_num_colors();
total_phases += kh.get_distance2_graph_coloring_handle()->get_num_phases();
std::cout << "Total Time: " << kh.get_distance2_graph_coloring_handle()->get_overall_coloring_time() << std::endl
<< "Num colors: " << kh.get_distance2_graph_coloring_handle()->get_num_colors() << std::endl
<< "Num Phases: " << kh.get_distance2_graph_coloring_handle()->get_num_phases() << std::endl;
std::cout << "\t";
KokkosKernels::Impl::print_1Dview(kh.get_distance2_graph_coloring_handle()->get_vertex_colors());
std::cout << std::endl;
// If verbose mode is on and there the graph has fewer than 1500 verts, dump a GraphVIZ DOT file.
if(verbose && repeat==i+1 && crsGraph.numRows() < 1500)
{
auto colors = kh.get_distance2_graph_coloring_handle()->get_vertex_colors();
std::ofstream os("G.dot", std::ofstream::out);
kh.get_distance2_graph_coloring_handle()->dump_graphviz(os, crsGraph.numRows(), crsGraph.row_map, crsGraph.entries, colors);
}

It should be pretty easy to get the node to color mapping out by having a look at what the dump_graphviz() function is doing... it could be copied and modified pretty easily into something that just dumps out a CSV file containing the node/color pairs.

Hopefully this information is helpful...

@rohit-mp
Copy link
Contributor Author

rohit-mp commented Jul 2, 2019

@william76

Thanks for the information! What I've done now is kinda similar. I've used the same get_vertex_colors() interface to get a view and printed it out except that the function I've created lies in src/common/KokkosKernels_PrintUtils.hpp

I've also added another option to possible argument --outputfile or -o since KokkoksKernels::Experiment::Parameters already had the option of a coloring_file_output but dump_graphviz uses the verbose argument.

namespace KokkosKernels{
namespace Experiment{
struct Parameters{
int algorithm;
int accumulator;
int repeat;
int chunk_size;
int multi_color_scale;
int shmemsize;
int team_size;
int use_dynamic_scheduling;
int verbose;
int spgemm_step;
int vector_size;
int check_output;
int mkl_sort_option;
int mkl_keep_output;
int calculate_read_write_cost;
char *coloring_input_file;
char *coloring_output_file;

Could you have a look at the PR and let me know if it's fine or if I should change it to be similar to dump_graphviz and not involve PrintUtils since the function might not be useful for all programs and doesn't make much sense to keep it in the common folder.

@srajama1
Copy link
Contributor

@rohit-mp : We do not close the issue until we merge changes into master as that is what most users to see. Whoever does the master merge will close it at that time. Let us leave it open till then.

@srajama1 srajama1 reopened this Jul 10, 2019
@rohit-mp
Copy link
Contributor Author

Ah sorry, my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants