Skip to content
Snippets Groups Projects
Commit 962b4cae authored by Alexander Peyser's avatar Alexander Peyser
Browse files

Add profile-only-zero flag for mpi profiling

parent d3533cfd
No related branches found
No related tags found
No related merge requests found
......@@ -134,7 +134,10 @@ cl_options read_options(int argc, char** argv, bool allow_write) {
true, // Overwrite outputfile if exists
"./", // output path
"spikes", // file name
"gdf" // file extension
"gdf", // file extension
// Turn on/off profiling output for all ranks
false
};
cl_options options;
......@@ -191,6 +194,9 @@ cl_options read_options(int argc, char** argv, bool allow_write) {
TCLAP::SwitchArg spike_output_arg(
"f","spike_file_output","save spikes to file", cmd, false);
TCLAP::SwitchArg profile_only_zero_arg(
"z", "profile-only-zero", "Only output profile information for rank 0", cmd, false);
cmd.reorder_arguments();
cmd.parse(argc, argv);
......@@ -230,6 +236,8 @@ cl_options read_options(int argc, char** argv, bool allow_write) {
update_option(options.file_extension, fopts, "file_extension");
}
update_option(options.profile_only_zero, fopts, "profile_only_zero");
}
catch (std::exception& e) {
throw model_description_error(
......@@ -255,6 +263,7 @@ cl_options read_options(int argc, char** argv, bool allow_write) {
update_option(options.trace_prefix, trace_prefix_arg);
update_option(options.trace_max_gid, trace_max_gid_arg);
update_option(options.spike_file_output, spike_output_arg);
update_option(options.profile_only_zero, profile_only_zero_arg);
if (options.all_to_all && options.ring) {
throw usage_error("can specify at most one of --ring and --all-to-all");
......
......@@ -35,6 +35,9 @@ struct cl_options {
std::string output_path;
std::string file_name;
std::string file_extension;
// Turn on/off profiling output for all ranks
bool profile_only_zero;
};
class usage_error: public std::runtime_error {
......
......@@ -141,7 +141,7 @@ int main(int argc, char** argv) {
// output profile and diagnostic feedback
auto const num_steps = options.tfinal / options.dt;
util::profiler_output(0.001, m.num_cells()*num_steps);
util::profiler_output(0.001, m.num_cells()*num_steps, options.profile_only_zero);
std::cout << "there were " << m.num_spikes() << " spikes\n";
// save traces
......
......@@ -349,7 +349,7 @@ void profilers_restart() {
}
}
void profiler_output(double threshold, std::size_t num_local_work_items) {
void profiler_output(double threshold, std::size_t num_local_work_items, bool profile_only_zero) {
profilers_stop();
// Find the earliest start time and latest stop time over all profilers
......@@ -385,6 +385,7 @@ void profiler_output(double threshold, std::size_t num_local_work_items) {
auto ncomms = communication::global_policy::size();
auto comm_rank = communication::global_policy::id();
bool print = comm_rank==0 ? true : false;
bool output_this_rank = (comm_rank == 0) || ! profile_only_zero;
// calculate the throughput in terms of work items per second
auto local_throughput = num_local_work_items / wall_time;
......@@ -433,9 +434,11 @@ void profiler_output(double threshold, std::size_t num_local_work_items) {
as_json["rank"] = comm_rank;
as_json["regions"] = p.as_json();
auto fname = std::string("profile_" + std::to_string(comm_rank));
std::ofstream fid(fname);
fid << std::setw(1) << as_json;
if (output_this_rank) {
auto fname = std::string("profile_" + std::to_string(comm_rank));
std::ofstream fid(fname);
fid << std::setw(1) << as_json;
}
}
#else
......@@ -445,7 +448,7 @@ void profiler_enter(const char*) {}
void profiler_leave() {}
void profiler_leave(int) {}
void profilers_stop() {}
void profiler_output(double threshold, std::size_t num_local_work_items) {}
void profiler_output(double threshold, std::size_t num_local_work_items, bool profile_only_zero) {}
void profilers_restart() {};
#endif
......
......@@ -245,7 +245,7 @@ void profilers_stop();
void profilers_restart();
/// print the collated profiler to std::cout
void profiler_output(double threshold, std::size_t num_local_work_items);
void profiler_output(double threshold, std::size_t num_local_work_items, bool profile_only_zero);
} // namespace util
} // namespace mc
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment