Skip to content

Commit

Permalink
addRanks vtkh filter
Browse files Browse the repository at this point in the history
(cherry picked from commit 0353a74)
  • Loading branch information
nicolemarsaglia authored and cyrush committed Aug 3, 2024
1 parent fce0b2a commit fa9bc6f
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ register_builtin()
AscentRuntime::register_filter_type<VTKHBounds>();
AscentRuntime::register_filter_type<VTKHUnionBounds>();
// transforms, the current crop expect vtk-h input data
//AscentRuntime::register_filter_type<VTKHAddDomains>("transforms","add_domain_ids");
AscentRuntime::register_filter_type<VTKHAddRanks>("transforms","add_mpi_ranks");
AscentRuntime::register_filter_type<VTKHClip>("transforms","clip");
AscentRuntime::register_filter_type<VTKHClipWithField>("transforms","clip_with_field");
AscentRuntime::register_filter_type<VTKHCleanGrid>("transforms","clean_grid");
Expand Down
108 changes: 108 additions & 0 deletions src/libs/ascent/runtimes/flow_filters/ascent_runtime_vtkh_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,114 @@ VTKHGhostStripper::execute()
}
}

//-----------------------------------------------------------------------------
VTKHAddRanks::VTKHAddRanks()
:Filter()
{
// empty
}

//-----------------------------------------------------------------------------
VTKHAddRanks::~VTKHAddRanks()
{
// empty
}

//-----------------------------------------------------------------------------
void
VTKHAddRanks::declare_interface(Node &i)
{
i["type_name"] = "vtkh_add_mpi_ranks";
i["port_names"].append() = "in";
i["output_port"] = "true";
}

//-----------------------------------------------------------------------------
bool
VTKHAddRanks::verify_params(const conduit::Node &params,
conduit::Node &info)
{
info.reset();

bool res = check_string("topology",params, info, false);
res = check_string("output",params, info, false);

std::vector<std::string> valid_paths;
valid_paths.push_back("output");
valid_paths.push_back("topology");
std::string surprises = surprise_check(valid_paths, params);

if(surprises != "")
{
res = false;
info["errors"].append() = surprises;
}

return res;
}

//-----------------------------------------------------------------------------
void
VTKHAddRanks::execute()
{

if(!input(0).check_type<DataObject>())
{
ASCENT_ERROR("VTKHAddRanks input must be a data object");
}

DataObject *data_object = input<DataObject>(0);
if(!data_object->is_valid())
{
set_output<DataObject>(data_object);
return;
}

int rank = 0;
#ifdef ASCENT_MPI_ENABLED
MPI_Comm mpi_comm = MPI_Comm_f2c(Workspace::default_mpi_comm());
MPI_Comm_rank(mpi_comm, &rank);
#endif

std::shared_ptr<VTKHCollection> collection = data_object->as_vtkh_collection();

std::string output_field = "mpi_rank";
if(params().has_child("output"))
{
output_field = params()["output"].as_string();
}

std::string topo_name = "";
if(params().has_child("topology"))
{
topo_name = params()["topology"].as_string();
}
else
{
bool throw_error = false;
topo_name = detail::resolve_topology(params(),
this->name(),
collection,
throw_error);
std::cerr << "topo_name: " << topo_name << std::endl;
if(topo_name == "")
{
// this creates a data object with an invalid source
set_output<DataObject>(new DataObject());
return;
}
}

vtkh::DataSet &data = collection->dataset_by_topology(topo_name);
VTKHCollection *new_coll = collection->copy_without_topology(topo_name);
data.AddConstantPointField(rank,output_field);
new_coll->add(data, topo_name);

// re wrap in data object
DataObject *res = new DataObject(new_coll);
set_output<DataObject>(res);
}

//-----------------------------------------------------------------------------
VTKHThreshold::VTKHThreshold()
:Filter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ class ASCENT_API VTKHGhostStripper: public ::flow::Filter
virtual void execute();
};

//-----------------------------------------------------------------------------
class ASCENT_API VTKHAddRanks : public ::flow::Filter
{
public:
VTKHAddRanks();
virtual ~VTKHAddRanks();

virtual void declare_interface(conduit::Node &i);
virtual bool verify_params(const conduit::Node &params,
conduit::Node &info);
virtual void execute();
};

//-----------------------------------------------------------------------------
class ASCENT_API VTKHAddDomains : public ::flow::Filter
{
public:
VTKHAddDomains();
virtual ~VTKHAddDomains();

virtual void declare_interface(conduit::Node &i);
virtual bool verify_params(const conduit::Node &params,
conduit::Node &info);
virtual void execute();
};



//-----------------------------------------------------------------------------
class ASCENT_API VTKHClip: public ::flow::Filter
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/tests/ascent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ set(MPI_TESTS t_ascent_mpi_smoke
t_ascent_mpi_slice
t_ascent_mpi_uniform_grid
t_ascent_mpi_vtk_file_extract
t_ascent_mpi_add_ranks
t_ascent_mpi_unique_ids)

# t_ascent_hola_mpi uses 8 mpi tasks, so its added manually
Expand Down
155 changes: 155 additions & 0 deletions src/tests/ascent/t_ascent_mpi_add_ranks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Copyright (c) Lawrence Livermore National Security, LLC and other Ascent
// Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
// other details. No copyright assignment is required to contribute to Ascent.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//-----------------------------------------------------------------------------
///
/// file: t_ascent_mpi_add_ranks.cpp
///
//-----------------------------------------------------------------------------


#include "gtest/gtest.h"

#include <ascent.hpp>

#include <iostream>
#include <math.h>
#include <mpi.h>

#include <conduit_blueprint.hpp>
#include <conduit_blueprint_mpi_mesh_examples.hpp>

#include "t_config.hpp"
#include "t_utils.hpp"




using namespace std;
using namespace conduit;
using namespace ascent;


int NUM_DOMAINS = 8;

//-----------------------------------------------------------------------------
TEST(ascent_mpi_add_mpi_ranks_2d, test_mpi_add_mpi_ranks_2d)
{
//
//Set Up MPI
//
int par_rank;
int par_size;
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Comm_rank(comm, &par_rank);
MPI_Comm_size(comm, &par_size);

Node n;
ascent::about(n);
// only run this test if ascent was built with vtkm support
if(n["runtimes/ascent/vtkm/status"].as_string() == "disabled")
{
ASCENT_INFO("Ascent vtkm support disabled, skipping test");
return;
}

//
// Create an example mesh.
//
Node data, verify_info;
conduit::blueprint::mpi::mesh::examples::spiral_round_robin(NUM_DOMAINS,data,comm);

EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
// data["state/cycle"] = 100;
// data.print();

ASCENT_INFO("Testing adding mpi ranks to conduit::blueprint spiral input\n");


string output_path = prepare_output_dir();
string output_file = conduit::utils::join_file_path(output_path,"tout_mpi_add_ranks");
string image_file = conduit::utils::join_file_path(output_path,"tout_mpi_add_ranks10");

// remove old images before rendering
if(par_rank == 0)
remove_test_image(output_file);

//
// Create the actions.
//

conduit::Node pipelines;
// pipeline 1
pipelines["pl1/f1/type"] = "add_mpi_ranks";
conduit::Node &params = pipelines["pl1/f1/params"];
params["topology"] = "topo";
params["output"] = "ranks";

conduit::Node scenes;
scenes["s1/plots/p1/type"] = "pseudocolor";
scenes["s1/plots/p1/field"] = "ranks";
scenes["s1/plots/p1/pipeline"] = "pl1";
scenes["s1/plots/p1/color_table/discrete"] = "true";

scenes["s1/image_prefix"] = image_file;

conduit::Node actions;
// add the pipeline
conduit::Node &add_pipelines = actions.append();
add_pipelines["action"] = "add_pipelines";
add_pipelines["pipelines"] = pipelines;
// add the scenes
conduit::Node &add_scenes= actions.append();
add_scenes["action"] = "add_scenes";
add_scenes["scenes"] = scenes;

// conduit::Node extracts;
//
// extracts["e1/type"] = "relay";
// extracts["e1/params/path"] = output_file;
// extracts["e1/params/protocol"] = "blueprint/mesh/hdf5";
// conduit::Node &add_ext= actions.append();
// add_ext["action"] = "add_extracts";
// add_ext["extracts"] = extracts;

//
// Run Ascent
//

Ascent ascent;

Node ascent_opts;
ascent_opts["runtime/type"] = "ascent";
ascent_opts["mpi_comm"] = MPI_Comm_c2f(comm);
ascent_opts["exceptions"] = "forward";
ascent.open(ascent_opts);
ascent.publish(data);
ascent.execute(actions);
ascent.close();

// check that we created an image
if(par_rank == 0)
{
EXPECT_TRUE(check_test_image(output_file));
std::string msg = "An example of adding mpi ranks to the data.";
ASCENT_ACTIONS_DUMP(actions,output_file,msg);
}
}

//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
int result = 0;

::testing::InitGoogleTest(&argc, argv);
MPI_Init(&argc, &argv);

result = RUN_ALL_TESTS();
MPI_Finalize();
return result;
}


0 comments on commit fa9bc6f

Please sign in to comment.