Skip to content

Commit

Permalink
#78: fix phase looping in render.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly authored and lifflander committed Jun 25, 2024
1 parent 0dbcec4 commit d60fcad
Showing 1 changed file with 90 additions and 25 deletions.
115 changes: 90 additions & 25 deletions src/vt-tv/render/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ Render::Render(Info in_info)
this->info_.setSelectedPhase(selected_phase_);

// Normalize communication edges
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if ( selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase ) {
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
this->info_.normalizeEdges(selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
this->info_.normalizeEdges(phase);
}
}
Expand Down Expand Up @@ -136,10 +137,6 @@ Render::Render(
, save_pngs_(in_save_pngs)
, selected_phase_(in_selected_phase)
{
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
n_phases_ = std::max(selected_phase_ + 1, n_phases_);
}

// initialize number of ranks
n_ranks_ = info_.getNumRanks();

Expand All @@ -153,12 +150,11 @@ Render::Render(
this->info_.setSelectedPhase(selected_phase_);

// Normalize communication edges
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
this->info_.normalizeEdges(phase);
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
this->info_.normalizeEdges(selected_phase_);
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
this->info_.normalizeEdges(phase);
}
}

Expand Down Expand Up @@ -194,11 +190,28 @@ std::variant<std::pair<double, double>, std::set<std::variant<double,int>>> Rend
std::set<std::variant<double,int>> oq_all;

// Iterate over all ranks
for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
auto const& objects = this->info_.getPhaseObjects(selected_phase_);
for (auto const& [obj_id, obj_work] : objects) {
// Update maximum object qoi
oq = info_.getObjectQoi(obj_id, selected_phase_, this->object_qoi_);
if (!continuous_object_qoi_) {
// Allow for integer categorical QOI (i.e. rank_id)
if (oq == static_cast<int>(oq)) {
oq_all.insert(static_cast<int>(oq));
} else {
oq_all.insert(oq);
}
if(oq_all.size() > 20) {
oq_all.clear();
continuous_object_qoi_ = true;
}
}
if (oq > oq_max) oq_max = oq;
if (oq < oq_min) oq_min = oq;
}
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
auto const& objects = this->info_.getPhaseObjects(phase);
for (auto const& [obj_id, obj_work] : objects) {
// Update maximum object qoi
Expand Down Expand Up @@ -928,8 +941,12 @@ void Render::renderPNG(
// Add field data text information to render
// Create text
std::stringstream ss;
ss << "Phase: " << phase << "/" << (this->n_phases_ - 1) << "\n"
<< "Load Imbalance: " << std::fixed << std::setprecision(2) << this->info_.getImbalance(phase);
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
ss << "Phase: " << phase << "\n";
} else {
ss << "Phase: " << phase << "/" << (this->n_phases_ - 1) << "\n";
}
ss << "Load Imbalance: " << std::fixed << std::setprecision(2) << this->info_.getImbalance(phase);
// Setup text actor
vtkSmartPointer<vtkTextActor> text_actor = vtkSmartPointer<vtkTextActor>::New();
text_actor->SetInput(ss.str().c_str());
Expand Down Expand Up @@ -983,11 +1000,59 @@ void Render::generate(uint64_t font_size, uint64_t win_size) {

fmt::print("selected phase={}\n", selected_phase_);

for(PhaseType phase = 0; phase < this->n_phases_; phase++) {
if (
selected_phase_ == std::numeric_limits<PhaseType>::max() or
selected_phase_ == phase
) {
if (selected_phase_ != std::numeric_limits<PhaseType>::max()) {
vtkNew<vtkPolyData> object_mesh = this->createObjectMesh_(selected_phase_);
vtkNew<vtkPolyData> rank_mesh = this->createRankMesh_(selected_phase_);

if (save_meshes_){
fmt::print("== Writing object mesh for phase {}\n", selected_phase_);
vtkNew<vtkXMLPolyDataWriter> writer;
std::string object_mesh_filename = output_dir_ + output_file_stem_ + "_object_mesh_" + std::to_string(selected_phase_) + ".vtp";
writer->SetFileName(object_mesh_filename.c_str());
writer->SetInputData(object_mesh);
writer->Write();

fmt::print("== Writing rank mesh for phase {}\n", selected_phase_);
vtkNew<vtkXMLPolyDataWriter> writer2;
std::string rank_mesh_filneame = output_dir_ + output_file_stem_ + "_rank_mesh_" + std::to_string(selected_phase_) + ".vtp";
writer2->SetFileName(rank_mesh_filneame.c_str());
writer2->SetInputData(rank_mesh);
writer2->Write();
}

if (save_pngs_){
fmt::print("== Rendering visualization PNG for phase {}\n", selected_phase_);

std::pair<double, double> obj_qoi_range;
try {
obj_qoi_range = std::get<std::pair<double, double>>(this->object_qoi_range_);
}
catch(const std::exception& e) {
std::cerr << e.what() << '\n';
obj_qoi_range = {0, 1};
}

uint64_t window_size = win_size;
uint64_t edge_width = 0.03 * window_size / *std::max_element(this->grid_size_.begin(), this->grid_size_.end());
double glyph_factor = 0.8 * this->grid_resolution_ / (
(this->max_o_per_dim_ + 1)
* std::sqrt(object_load_max_));
fmt::print(" Image size: {}x{}px\n", win_size, win_size);
fmt::print(" Font size: {}pt\n", font_size);
this->renderPNG(
selected_phase_,
rank_mesh,
object_mesh,
edge_width,
glyph_factor,
window_size,
font_size,
output_dir_,
output_file_stem_
);
}
} else {
for (PhaseType phase = 0; phase < this->n_phases_; phase++) {
vtkNew<vtkPolyData> object_mesh = this->createObjectMesh_(phase);
vtkNew<vtkPolyData> rank_mesh = this->createRankMesh_(phase);

Expand Down

0 comments on commit d60fcad

Please sign in to comment.