Skip to content

Commit

Permalink
adds mpi ranks fields (#1349)
Browse files Browse the repository at this point in the history
* addRanks vtkh filter

(cherry picked from commit 0353a74)

* add ranks filter

(cherry picked from commit dd72250)

* add domains

* fix and add baselines

* fix default output name for domains ids

* add docs

* change ranks from 8 to 4 to differ domain id example

* Update Pipelines.rst

capitalization

* Update Pipelines.rst

match field on image

---------

Co-authored-by: Nicole Marsaglia <[email protected]>
  • Loading branch information
cyrush and nicolemarsaglia authored Aug 20, 2024
1 parent 9d8fcf7 commit db26d23
Show file tree
Hide file tree
Showing 14 changed files with 623 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
- Added support for `pyramid` and `wedge` elements.
- Added a `topologies` option to the relay extract. This allows you to select which topologies are saved. This option can be used with the existing `fields` option, the result is the union of the selected topologies and fields.
- Added `near_plane` and `far_plane` to the camera details provided in Ascent::info()
- Added `add_mpi_ranks` and `add_domain_ids` filters for adding rank and domain fields to a mesh

### Fixed
- Resolved a few cases where MPI_COMM_WORLD was used instead instead of the selected MPI communicator.
Expand Down
47 changes: 47 additions & 0 deletions src/docs/sphinx/Actions/Pipelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,53 @@ The output field of the MIR Filter will be the name of the material set and can
params["iterations"] = 8; //default: 0
params["max_error"] = 0.00001; //default: 0.00001

Add MPI Ranks as Field Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ascent provides a filter to add MPI rank information to a mesh.
If the input data has multiple topolgies, the user must specify which topology to add the new field to.
The user also has the option of specifying the output name for the new field.

.. code-block:: c++

conduit::Node pipelines;
// pipeline 1
pipelines["pl1/f1/type"] = "add_mpi_ranks";
//params optional
conduit::Node &params = pipelines["pl1/f1/params"];
params["output"] = "ranks";//default: "mpi_ranks"
params["topology"] = "topo"; //required if data has multiple topologies

.. _addmpiranks:

.. figure:: ../images/add_mpi_ranks.png
:scale: 50 %
:align: center

An example of creating a pseudocolor plot of MPI ranks.

Add Domain IDs as Field Data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ascent provides a filter to add domain ID information to a mesh.
If the input data has multiple topolgies, the user must specify which topology to add the new field to.
The user also has the option of specifying the output name for the new field.

.. code-block:: c++

conduit::Node pipelines;
// pipeline 1
pipelines["pl1/f1/type"] = "add_domain_ids";
//params optional
conduit::Node &params = pipelines["pl1/f1/params"];
params["output"] = "domain_ids";//default: "domain_ids"
params["topology"] = "topo"; //required if data has multiple topologies

.. _adddomainids:

.. figure:: ../images/add_domain_ids.png
:scale: 50 %
:align: center

An example of creating a pseudocolor plot of domain IDs.

Partitioning
~~~~~~~~~~~~
Expand Down
Binary file added src/docs/sphinx/images/add_domain_ids.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/docs/sphinx/images/add_mpi_ranks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,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
213 changes: 213 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,219 @@ 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);
}

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

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

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

//-----------------------------------------------------------------------------
bool
VTKHAddDomains::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
VTKHAddDomains::execute()
{

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

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

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

std::string output_field = "domain_ids";
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;
}
}

VTKHCollection *new_coll = collection->copy_without_topology(topo_name);

vtkh::DataSet &data = collection->dataset_by_topology(topo_name);
data.AddDomainIdField(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,35 @@ 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
16 changes: 16 additions & 0 deletions src/libs/vtkh/DataSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,22 @@ DataSet::AddLinearPointField(const vtkm::Float32 value, const std::string fieldn
}
}

void
DataSet::AddDomainIdField(const std::string fieldname)
{
const size_t size = m_domain_ids.size();

for(size_t i = 0; i < size; ++i)
{
vtkm::Id domain_id = m_domain_ids[i];
vtkm::Id num_points = m_domains[i].GetCoordinateSystem().GetData().GetNumberOfValues();
vtkm::cont::ArrayHandle<vtkm::Float32> array;
detail::MemSet(array, (vtkm::Float32)domain_id, num_points);
vtkm::cont::Field field(fieldname, vtkm::cont::Field::Association::Points, array);
m_domains[i].AddField(field);
}
}

bool
DataSet::FieldExists(const std::string &field_name) const
{
Expand Down
1 change: 1 addition & 0 deletions src/libs/vtkh/DataSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class VTKH_API DataSet
// add a scalar field to this data set with a constant value
void AddConstantPointField(const vtkm::Float32 value, const std::string fieldname);
void AddLinearPointField(const vtkm::Float32 value, const std::string fieldname);
void AddDomainIdField(const std::string fieldname);

bool HasDomainId(const vtkm::Id &domain_id) const;
/*! \brief IsStructured returns true if all domains, globally,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/tests/ascent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ set(BASIC_TESTS t_ascent_smoke
t_ascent_triggers
t_ascent_blueprint_reductions
t_ascent_sampling
t_ascent_uniform_grid
t_ascent_mir
t_ascent_uniform_grid
t_ascent_mir
t_ascent_hola)

set(DEVICE_TESTS t_ascent_execution_policies
Expand Down Expand Up @@ -100,6 +100,8 @@ 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_add_domain_ids
t_ascent_mpi_unique_ids)

# t_ascent_hola_mpi uses 8 mpi tasks, so its added manually
Expand Down
Loading

0 comments on commit db26d23

Please sign in to comment.