Skip to content

Commit edffaea

Browse files
committed
handling multiple domains
1 parent 778db6b commit edffaea

1 file changed

Lines changed: 86 additions & 18 deletions

File tree

src/libs/vtkh/filters/ContourTree.cpp

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,69 @@
1919

2020
namespace caugmented_ns = vtkm::worklet::contourtree_augmented;
2121

22+
#ifdef DEBUG
23+
void SaveToBDEM(const vtkm::cont::DataSet& ds,
24+
const std::string& fieldname,
25+
const std::string& filename)
26+
{
27+
std::cout << "Saving block to " << filename << std::endl;
28+
vtkm::Id3 blockSize;
29+
vtkm::Id3 globalSize;
30+
vtkm::Id3 pointIndexStart;
31+
vtkm::cont::CastAndCall(ds.GetCellSet(),
32+
vtkm::worklet::contourtree_augmented::GetLocalAndGlobalPointDimensions(),
33+
blockSize,
34+
globalSize,
35+
pointIndexStart);
36+
std::ofstream os(filename, std::ios::binary);
37+
os << "#GLOBAL_EXTENTS " << globalSize[1] << " " << globalSize[0];
38+
if (globalSize[2] > 1)
39+
{
40+
os << " " << globalSize[2];
41+
}
42+
os << std::endl;
43+
os << "#OFFSET " << pointIndexStart[1] << " " << pointIndexStart[0];
44+
if (globalSize[2] > 1)
45+
{
46+
os << " " << pointIndexStart[2];
47+
}
48+
os << std::endl;
49+
os << blockSize[1] << " " << blockSize[0];
50+
if (globalSize[2] > 1)
51+
{
52+
os << " " << blockSize[2];
53+
}
54+
os << std::endl;
55+
try
56+
{
57+
auto dataArray =
58+
ds.GetField(fieldname).GetData().AsArrayHandle<vtkm::cont::ArrayHandleBasic<vtkm::Float32>>();
59+
os.write(reinterpret_cast<const char*>(dataArray.GetReadPointer()),
60+
dataArray.GetNumberOfValues() * sizeof(vtkm::Float32));
61+
}
62+
catch (vtkm::cont::ErrorBadType& e)
63+
{
64+
std::cerr << "Error: Cannot get as ArrayHandleBasic<vtkm::Float32>: " << e.GetMessage()
65+
<< std::endl;
66+
}
67+
}
68+
69+
void SaveToBDEM(const vtkm::cont::PartitionedDataSet& pds,
70+
const std::string& fieldname,
71+
const std::string& basefilename,
72+
int rank,
73+
int blocksPerRank)
74+
{
75+
for (vtkm::Id i = 0; i < pds.GetNumberOfPartitions(); ++i)
76+
{
77+
std::string filename = basefilename + '_' + std::to_string(rank*blocksPerRank+i) + ".bdem";
78+
std::cout << "Saving partition " << i << " to " << filename << std::endl;
79+
SaveToBDEM(pds.GetPartition(i), fieldname, filename);
80+
}
81+
}
82+
#endif
83+
84+
#ifdef VTKH_PARALLEL
2285
static void ShiftLogicalOriginToZero(vtkm::cont::PartitionedDataSet& pds)
2386
{
2487
// Shift the logical origin (minimum of LocalPointIndexStart) to zero
@@ -120,7 +183,6 @@ static void ComputeGlobalPointSize(vtkm::cont::PartitionedDataSet& pds)
120183
}
121184
}
122185

123-
#ifdef VTKH_PARALLEL
124186
#include <mpi.h>
125187

126188
// This is from VTK-m diy mpi_cast.hpp. Need the make_DIY_MPI_Comm
@@ -442,8 +504,18 @@ void ContourTree::distributed_analysis(const vtkm::cont::PartitionedDataSet& res
442504

443505
void ContourTree::DoExecute()
444506
{
507+
{
508+
#ifdef VTKH_PARALLEL
509+
int mpi_rank = 0;
510+
511+
MPI_Comm mpi_comm = MPI_Comm_f2c(vtkh::GetMPICommHandle());
512+
vtkm::cont::EnvironmentTracker::SetCommunicator(vtkmdiy::mpi::communicator(vtkmdiy::mpi::make_DIY_MPI_Comm(mpi_comm)));
513+
514+
MPI_Comm_rank(mpi_comm, &mpi_rank);
515+
#endif
516+
}
517+
445518
vtkh::DataSet *old_input = this->m_input;
446-
const int before_num_domains = this->m_input->GetNumberOfDomains();
447519

448520
// make sure we have a node-centered field
449521
bool valid_field = false;
@@ -485,7 +557,6 @@ void ContourTree::DoExecute()
485557
this->m_output = new DataSet();
486558

487559
const int num_domains = this->m_input->GetNumberOfDomains();
488-
assert(num_domains == 1);
489560

490561
#ifndef VTKH_PARALLEL
491562
vtkm::cont::DataSet inDataSet;
@@ -506,11 +577,15 @@ void ContourTree::DoExecute()
506577

507578
vtkm::cont::PartitionedDataSet inDataSet;
508579

509-
vtkm::Id domain_id;
510-
vtkm::cont::DataSet dom;
580+
for (int i = 0; i < num_domains; ++i)
581+
{
582+
vtkm::Id domain_id;
583+
vtkm::cont::DataSet dom;
511584

512-
this->m_input->GetDomain(0, dom, domain_id);
513-
inDataSet.AppendPartition(dom);
585+
this->m_input->GetDomain(i, dom, domain_id);
586+
inDataSet.AppendPartition(dom);
587+
this->m_output->AddDomain(dom, domain_id);
588+
}
514589

515590
#ifdef DEBUG
516591
if( mpi_size != 1 )
@@ -533,12 +608,6 @@ void ContourTree::DoExecute()
533608

534609
//Convert the mesh of values into contour tree, pairs of vertex ids
535610
vtkm::filter::scalar_topology::ContourTreeAugmented filter(useMarchingCubes, computeRegularStructure);
536-
537-
#ifdef DEBUG
538-
std::cout << "--- BEGIN_SUMMARY inDataSet" << std::endl;
539-
inDataSet.PrintSummary( std::cout );
540-
std::cout << "--- END_SUMMARY inDataSet" << std::endl;
541-
#endif
542611
#else // VTKH_PARALLEL
543612
// TODO SET VTKM to do vtkm::cont::LogLovel::Info
544613
// vtkm::filter::scalar_topology::ContourTreeUniformDistributed filter(vtkm::cont::LogLevel::Info, vtkm::cont::LogLevel::Info);
@@ -556,15 +625,14 @@ void ContourTree::DoExecute()
556625
filterField = &filter;
557626
}
558627

559-
#ifdef DEBUG
560-
std::cout << "--- BEGIN_SUMMARY inDataSet:mpi_rank=" << mpi_rank << std::endl;
561-
inDataSet.PrintSummary( std::cout );
562-
std::cout << "--- END_SUMMARY inDataSet:mpi_rank=" << mpi_rank << std::endl;
563-
#endif
564628
#endif // VTKH_PARALLEL
565629

566630
filterField->SetActiveField(m_field_name);
567631

632+
#ifdef DEBUG
633+
SaveToBDEM(inDataSet, m_field_name, "debug-ascent", mpi_rank, num_domains);
634+
#endif
635+
568636
auto result = filterField->Execute(inDataSet);
569637

570638
m_iso_values.resize(m_levels);

0 commit comments

Comments
 (0)