diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp index a426be07ab4bfe3a43cc53c56418ef7f9daa196d..e3818119a735561a052a86a28b9a9e37ed48c8e9 100644 --- a/include/pass_mpi_collective.hpp +++ b/include/pass_mpi_collective.hpp @@ -30,6 +30,7 @@ struct bb_data std::set<basic_block> dom_front; std::set<basic_block> post_dom_front; int mark; // for graph parkour + int collective_rank; }; struct edge_data @@ -71,13 +72,18 @@ public: void label_dom_front(function *fun); void free_dom_data(); - //parkour de graph + // parkour de graph void reset_bb_mark(function *fun); void alloc_edge_aux(function *fun); void free_edge_aux(function *fun); void mark_edge(function *fun); void mark_edge(basic_block bb, int mark); + // rank definition + void rank_collective(function *fun); + int rank_collective(basic_block bb, + mpi_collective_code mpi_code, int rank); + private: // MPI function / collectives detections bool __is_mpi_func(gimple *stmt); diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp index 46e0383a3bff70679ef625c6c1b71f49662ac90d..979a6db14e5a4e49c7876d28ab307cb579ace6fa 100644 --- a/src/pass_mpi_collective.cpp +++ b/src/pass_mpi_collective.cpp @@ -66,6 +66,8 @@ unsigned int pass_mpi_collective::execute(function *fun) mark_edge(fun); reset_bb_mark(fun); + rank_collective(fun); + cfgviz_dump(fun, "_split"); free_dom_data(); @@ -98,7 +100,8 @@ void pass_mpi_collective::print_tree(function *fun) { printf("\t\t\tStatement is a MPI function call (%s)\n", fndecl_name(gimple_call_fndecl(stmt))); - if (__is_mpi_collec(stmt) != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) + if (__is_mpi_collec(stmt) + != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) { printf("\t\t\t\tStatement is a MPI collective (%s)\n", fndecl_name(gimple_call_fndecl(stmt))); @@ -131,15 +134,13 @@ mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt) size_t i; const char *callee_name; - i = 0; callee_name = fndecl_name(gimple_call_fndecl(stmt)); - while (i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) + for (i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i) { if (strcmp(mpi_collective_name[i], callee_name) == 0) { return (enum mpi_collective_code) i; } - ++i; } return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; } @@ -169,7 +170,7 @@ void pass_mpi_collective::split_blocks(function *fun) nb_collective = 0; stmt = NULL; split = false; - for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi) && ! split; gsi_next(&gsi)) + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi) && !split; gsi_next(&gsi)) { prev_stmt = stmt; stmt = gsi_stmt(gsi); @@ -419,16 +420,60 @@ void pass_mpi_collective::mark_edge(basic_block bb, int mark) { ((edge_data *) e->aux)->loop = true; } + if (((bb_data *) bb_dest->aux)->mark == 0) + { + mark_edge(bb_dest, mark + 1); + } } +} - FOR_EACH_EDGE(e, ei, bb->succs) +void pass_mpi_collective::rank_collective(function *fun) +{ + size_t i; + int next_rank = 1; + + for (i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i) { - bb_dest = e->dest; - if (((bb_data *) bb_dest->aux)->mark == 0) + next_rank = rank_collective(EXIT_BLOCK_PTR_FOR_FN(fun), + (enum mpi_collective_code) i, next_rank); + reset_bb_mark(fun); + } +} + +int pass_mpi_collective::rank_collective(basic_block bb, + mpi_collective_code mpi_code, int rank) +{ + edge e; + edge_iterator ei; + int next_rank; + + next_rank = rank; + FOR_EACH_EDGE(e, ei, bb->preds) + { + if (((edge_data *) e->aux)->loop) { - mark_edge(bb_dest, mark + 1); + continue; + } + if (((bb_data *) e->src->aux)->mark) + { + //printf("caching from %d to %d\n", e->src->index, bb->index); + next_rank = std::max(next_rank, + ((bb_data *) e->src->aux)->mark); + } + else + { + //printf("going from %d to %d\n", e->src->index, bb->index); + next_rank = std::max(next_rank, + rank_collective(e->src, mpi_code, rank)); } } + if (((bb_data *) bb->aux)->mpi_code == mpi_code) + { + ((bb_data *) bb->aux)->collective_rank = next_rank; + next_rank++; + } + ((bb_data *) bb->aux)->mark = next_rank; + return next_rank; } //============================ GRAPHVIZ ===================================== @@ -471,8 +516,8 @@ void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out) fprintf(out, "%d [label=\"BB %d", bb->index, bb->index); if (data->mpi_code != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) { - - fprintf(out, "|%s", mpi_collective_name[data->mpi_code]); + fprintf(out, "|%s (%d) ", mpi_collective_name[data->mpi_code], + data->collective_rank); } if (! data->dom.empty())