Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:khuck/xpress-apex into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Feb 9, 2023
2 parents 0b69993 + 5b5e134 commit a5003ab
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/apex/dependency_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ double Node::writeNodeCSV(std::stringstream& outfile, double total, int node_id)
outfile << ((parent == nullptr) ? 0 : parent->index) << ",";
outfile << depth << ",\"";
outfile << data->get_tree_name() << "\",";
// write out the inclusive
// write out the accumulated
double acc = (data == task_identifier::get_main_task_id() || getAccumulated() == 0.0) ?
total : getAccumulated();
// write the number of calls
Expand All @@ -350,6 +350,7 @@ double Node::writeNodeCSV(std::stringstream& outfile, double total, int node_id)
double mean = acc / ncalls;
outfile << std::setprecision(9);
outfile << acc << ",";
outfile << inclusive << ",";
outfile << getMinimum() << ",";
outfile << mean << ",";
outfile << getMaximum() << ",";
Expand Down Expand Up @@ -398,18 +399,18 @@ double Node::writeNodeCSV(std::stringstream& outfile, double total, int node_id)
// end the line
outfile << std::endl;

// sort the children by accumulated time
std::vector<std::pair<task_identifier, Node*> > sorted;
// sort the children by name to make tree merging easier (I hope)
std::vector<Node*> sorted;
for (auto& it : children) {
sorted.push_back(it);
sorted.push_back(it.second);
}
sort(sorted.begin(), sorted.end(), cmp);
sort(sorted.begin(), sorted.end(), Node::compareNodeByParentName);

// do all the children
double remainder = acc;
depth++;
for (auto c : sorted) {
double tmp = c.second->writeNodeCSV(outfile, total, node_id);
double tmp = c->writeNodeCSV(outfile, total, node_id);
remainder = remainder - tmp;
}
depth--;
Expand Down
13 changes: 12 additions & 1 deletion src/apex/dependency_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Node {
inline double& getSumSquares() { return prof.sum_squares; }
void addAccumulated(double value, double incl, bool is_resume, uint64_t thread_id);
size_t getIndex() { return index; };
std::string getName() { return data->get_name(); };
std::string getName() const { return data->get_name(); };
void writeNode(std::ofstream& outfile, double total);
double writeNodeASCII(std::ofstream& outfile, double total, size_t indent);
double writeNodeCSV(std::stringstream& outfile, double total, int node_id);
Expand All @@ -107,6 +107,17 @@ class Node {
static std::set<std::string>& getKnownMetrics() {
return known_metrics;
}
// required for using this class as a key in a map, vector, etc.
static bool compareNodeByParentName (const Node* lhs, const Node* rhs) {
if (lhs->parent < rhs->parent) {
return true;
}
if (lhs->getName().compare(lhs->getName()) < 0) {
return true;
}
return false;
}

};

} // dependency_tree
Expand Down
2 changes: 2 additions & 0 deletions src/apex/proc_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,9 +1020,11 @@ std::array<double,2> getAvailableMemory() {
}
fclose(f);
}
#ifdef APEX_WITH_HIP
if (global_rsmi_reader != nullptr) {
values[1] = global_rsmi_reader->getAvailableMemory();
}
#endif
return values;
}

Expand Down
30 changes: 20 additions & 10 deletions src/apex/profile_reducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* 8 values (up to) when PAPI enabled */
constexpr size_t num_fields{23};

#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
#include "mpi.h"
#endif

Expand All @@ -46,7 +47,8 @@ namespace apex {
std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
int commrank = 0;
int commsize = 1;
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
int mpi_initialized = 0;
MPI_CALL(MPI_Initialized( &mpi_initialized ));
if (mpi_initialized) {
Expand Down Expand Up @@ -94,7 +96,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
length[1] = length[1] + 1;

/* AllReduce all profile name counts */
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
if (mpi_initialized && commsize > 1) {
MPI_CALL(PMPI_Allreduce(&length, &max_length, 2,
MPI_UINT64_T, MPI_MAX, MPI_COMM_WORLD));
Expand All @@ -119,7 +122,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
strncpy(ptr, name.c_str(), max_length[1]);
ptr = ptr + max_length[1];
}
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
if (mpi_initialized && commsize > 1) {
MPI_CALL(PMPI_Allgather(sbuf, sbuf_length, MPI_CHAR,
rbuf, sbuf_length, MPI_CHAR, MPI_COMM_WORLD));
Expand Down Expand Up @@ -192,7 +196,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
}

/* Reduce the data */
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
if (mpi_initialized && commsize > 1) {
MPI_CALL(PMPI_Gather(s_pdata, sbuf_length, MPI_DOUBLE,
r_pdata, sbuf_length, MPI_DOUBLE, 0, MPI_COMM_WORLD));
Expand Down Expand Up @@ -256,7 +261,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
}

}
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
if (mpi_initialized && commsize > 1) {
MPI_CALL(PMPI_Barrier(MPI_COMM_WORLD));
}
Expand All @@ -267,7 +273,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
void reduce_profiles(std::stringstream& csv_output, std::string filename) {
int commrank = 0;
int commsize = 1;
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
int mpi_initialized = 0;
MPI_CALL(MPI_Initialized( &mpi_initialized ));
if (mpi_initialized) {
Expand All @@ -291,7 +298,8 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
size_t length{csv_output.str().size()};
size_t max_length{length};
// get the longest string from all ranks
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
if (mpi_initialized && commsize > 1) {
MPI_CALL(PMPI_Allreduce(&length, &max_length, 1,
MPI_UINT64_T, MPI_MAX, MPI_COMM_WORLD));
Expand All @@ -307,14 +315,16 @@ std::map<std::string, apex_profile*> reduce_profiles_for_screen() {
// allocate the memory to hold all output
char * rbuf = nullptr;
if (commrank == 0) {
#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
rbuf = (char*)calloc(max_length * commsize, sizeof(char));
#else
rbuf = sbuf;
#endif
}

#if !defined(HPX_HAVE_NETWORKING) && defined(APEX_HAVE_MPI)
#if defined(APEX_HAVE_MPI) || \
(defined(HPX_HAVE_NETWORKING) && defined(HPX_HAVE_PARCELPORT_MPI))
MPI_Gather(sbuf, max_length, MPI_CHAR, rbuf, max_length, MPI_CHAR, 0, MPI_COMM_WORLD);
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/apex/profiler_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,9 @@ std::unordered_set<profile*> free_profiles;
stringstream tree_stream;
if (node_id == 0) {
tree_stream << "\"process rank\",\"node index\",\"parent index\",\"depth\",";
tree_stream << "\"name\",\"calls\",\"threads\",\"total time(ns)\",";
tree_stream << "\"minimum time(ns)\",\"mean time(ns)\",\"maximum time(ns)\",";
tree_stream << "\"stddev time(ns)\"";
tree_stream << "\"name\",\"calls\",\"threads\",\"total time(s)\",\"inclusive time(s)\",";
tree_stream << "\"minimum time(s)\",\"mean time(s)\",\"maximum time(s)\",";
tree_stream << "\"stddev time(s)\"";
for (auto& x : dependency::Node::getKnownMetrics()) {
tree_stream << ",\"total " << x << "\"";
tree_stream << ",\"minimum " << x << "\"";
Expand Down

0 comments on commit a5003ab

Please sign in to comment.