Skip to content

Commit

Permalink
DEBUG: Changes to allow easier debugging of the FindNeighborHoods filter
Browse files Browse the repository at this point in the history
Possible Parallel Issues. This branch will pass the commented out test if
the test files are produced.

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Sep 21, 2023
1 parent f5e4925 commit 9b3b2ca
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "complex/Utilities/ParallelDataAlgorithm.hpp"

#include <cmath>

Check warning on line 8 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:8:-#include <cmath>

Check failure on line 8 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
#include <chrono>

Check warning on line 10 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:9:+#include <cmath>
using namespace complex;

Expand Down Expand Up @@ -34,10 +35,24 @@ class FindNeighborhoodsImpl
{
start = 1;
}
for(size_t i = start; i < end; i++)
int32 progInt = 0.0f;
auto startTime = std::chrono::steady_clock::now();

for(size_t featureIdx = start; featureIdx < end; featureIdx++)
{
progInt = static_cast<float>(featureIdx) / static_cast<float>(m_TotalFeatures) * 100.0f;
auto now = std::chrono::steady_clock::now();
// Only send updates every 1 second
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - startTime).count() > 1000)
{
std::string message = fmt::format("Finding Neighborhood for FeatureId:{}", featureIdx);
//m_MessageHandler(complex::IFilter::ProgressMessage{complex::IFilter::Message::Type::Info, message, progInt});

Check warning on line 49 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:49:- //m_MessageHandler(complex::IFilter::ProgressMessage{complex::IFilter::Message::Type::Info, message, progInt}); src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:50:- std::cout << message<< "\n"; src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:49:+ // m_MessageHandler(complex::IFilter::ProgressMessage{complex::IFilter::Message::Type::Info, message, progInt}); src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp:50:+ std::cout << message << "\n";

Check failure on line 49 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
std::cout << message<< "\n";

Check failure on line 50 in src/Plugins/ComplexCore/src/ComplexCore/Filters/Algorithms/FindNeighborhoods.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
startTime = std::chrono::steady_clock::now();
}

incCount++;
if(incCount == increment || i == end - 1)
if(incCount == increment || featureIdx == end - 1)
{
incCount = 0;
m_Filter->updateProgress(increment, m_TotalFeatures);
Expand All @@ -46,12 +61,12 @@ class FindNeighborhoodsImpl
{
break;
}
bin1x = m_Bins[3 * i];
bin1y = m_Bins[3 * i + 1];
bin1z = m_Bins[3 * i + 2];
criticalDistance1 = m_CriticalDistance[i];
bin1x = m_Bins[3 * featureIdx];
bin1y = m_Bins[3 * featureIdx + 1];
bin1z = m_Bins[3 * featureIdx + 2];
criticalDistance1 = m_CriticalDistance[featureIdx];

for(size_t j = i + 1; j < m_TotalFeatures; j++)
for(size_t j = featureIdx + 1; j < m_TotalFeatures; j++)
{
bin2x = m_Bins[3 * j];
bin2y = m_Bins[3 * j + 1];
Expand All @@ -64,12 +79,12 @@ class FindNeighborhoodsImpl

if(dBinX < criticalDistance1 && dBinY < criticalDistance1 && dBinZ < criticalDistance1)
{
m_Filter->updateNeighborHood(i, j);
m_Filter->updateNeighborHood(featureIdx, j);
}

if(dBinX < criticalDistance2 && dBinY < criticalDistance2 && dBinZ < criticalDistance2)
{
m_Filter->updateNeighborHood(j, i);
m_Filter->updateNeighborHood(j, featureIdx);
}
}
}
Expand Down Expand Up @@ -185,7 +200,7 @@ Result<> FindNeighborhoods::operator()()

ParallelDataAlgorithm parallelAlgorithm;
parallelAlgorithm.setRange(Range(0, totalFeatures));
parallelAlgorithm.setParallelizationEnabled(false);
parallelAlgorithm.setParallelizationEnabled(m_InputValues->ParallelExecution);
parallelAlgorithm.execute(FindNeighborhoodsImpl(this, totalFeatures, centroids, bins, criticalDistance));

// Output Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct COMPLEXCORE_EXPORT FindNeighborhoodsInputValues
DataPath NeighborhoodsArrayName;
DataPath NeighborhoodListArrayName;
DataPath InputImageGeometry;
bool ParallelExecution;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "complex/Parameters/DataObjectNameParameter.hpp"

Check warning on line 10 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp:10:+#include "complex/Parameters/BoolParameter.hpp"
#include "complex/Parameters/GeometrySelectionParameter.hpp"
#include "complex/Parameters/NumberParameter.hpp"
#include "complex/Parameters/BoolParameter.hpp"

Check warning on line 13 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp:13:-#include "complex/Parameters/BoolParameter.hpp"

using namespace complex;

Expand Down Expand Up @@ -53,6 +54,9 @@ Parameters FindNeighborhoodsFilter::parameters() const
// Create the parameter descriptors that are needed for this filter
params.insertSeparator(Parameters::Separator{"Input Parameters"});

params.insertLinkableParameter(std::make_unique<BoolParameter>(k_Parallel_Key, "Parallel Execution", "Runs the filter using multiple cores where possible", false));

Check failure on line 57 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]


Check warning on line 59 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp:59:-
params.insert(std::make_unique<Float32Parameter>(k_MultiplesOfAverage_Key, "Multiples of Average Diameter", "Defines the search radius to use when looking for 'neighboring' Features", 1.0F));

params.insert(std::make_unique<GeometrySelectionParameter>(k_SelectedImageGeometry_Key, "Selected Image Geometry", "The target geometry", DataPath({"Data Container"}),
Expand Down Expand Up @@ -140,7 +144,7 @@ Result<> FindNeighborhoodsFilter::executeImpl(DataStructure& dataStructure, cons
const std::atomic_bool& shouldCancel) const
{
FindNeighborhoodsInputValues inputValues;

inputValues.ParallelExecution = filterArgs.value<bool>(k_Parallel_Key);

Check warning on line 147 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp:147:- inputValues.ParallelExecution = filterArgs.value<bool>(k_Parallel_Key); src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp:146:+ inputValues.ParallelExecution = filterArgs.value<bool>(k_Parallel_Key);

Check failure on line 147 in src/Plugins/ComplexCore/src/ComplexCore/Filters/FindNeighborhoodsFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
inputValues.MultiplesOfAverage = filterArgs.value<float32>(k_MultiplesOfAverage_Key);
inputValues.EquivalentDiametersArrayPath = filterArgs.value<DataPath>(k_EquivalentDiametersArrayPath_Key);
inputValues.FeaturePhasesArrayPath = filterArgs.value<DataPath>(k_FeaturePhasesArrayPath_Key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class COMPLEXCORE_EXPORT FindNeighborhoodsFilter : public IFilter
static inline constexpr StringLiteral k_NeighborhoodsArrayName_Key = "neighborhoods_array_name";
static inline constexpr StringLiteral k_NeighborhoodListArrayName_Key = "neighborhood_list_array_name";
static inline constexpr StringLiteral k_SelectedImageGeometry_Key = "selected_image_geometry_path";
static inline constexpr StringLiteral k_Parallel_Key = "parallel_execution";

/**
* @brief Returns the name of the filter.
Expand Down
31 changes: 31 additions & 0 deletions src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,34 @@ TEST_CASE("ComplexCore::FindNeighborhoods", "[ComplexCore][FindNeighborhoods]")
WriteTestDataStructure(dataStructure, fs::path(fmt::format("{}/find_neighborhoods.dream3d", unit_test::k_BinaryTestOutputDir)));
#endif
}

//
//TEST_CASE("ComplexCore::FindNeighborhoods Debug", "[ComplexCore][FindNeighborhoods]")

Check warning on line 79 in src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp:79:-//TEST_CASE("ComplexCore::FindNeighborhoods Debug", "[ComplexCore][FindNeighborhoods]") src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp:79:+// TEST_CASE("ComplexCore::FindNeighborhoods Debug", "[ComplexCore][FindNeighborhoods]")

Check failure on line 79 in src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
//{
//
// // Read the Small IN100 Data set
// auto baseDataFilePath = fs::path(fmt::format("/tmp/7_after.dream3d"));
// DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath);
//
// // Compare the k_Neighborhoods output array with those precalculated from the file
// {
// const DataPath exemplarPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/Neighborhoods").value();
// const DataPath parallelPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/Neighborhoods Parallel").value();
// UnitTest::CompareArrays<int32>(dataStructure.getDataAs<IDataArray>(exemplarPath), dataStructure.getDataAs<IDataArray>(parallelPath));
// }
//
// // Compare the k_NeighborhoodList output neighborlist with those precalculated from the file
// {
// const DataPath exemplarPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/NeighborhoodList").value();
// const DataPath parallelPath = DataPath::FromString("ImageDataContainerNX/CellFeatureData/NeighborhoodList Parallel").value();
//
// UnitTest::CompareNeighborLists<int32>(dataStructure.getDataAs<NeighborList<int32>>(exemplarPath), dataStructure.getDataAs<NeighborList<int32>>(parallelPath));
// }
//
//// Write the DataStructure out to the file system
//#ifdef COMPLEX_WRITE_TEST_OUTPUT
// WriteTestDataStructure(dataStructure, fs::path(fmt::format("{}/find_neighborhoods.dream3d", unit_test::k_BinaryTestOutputDir)));
//#endif
//}

Check failure on line 105 in src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]

Check warning on line 106 in src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

[clang-format] reported by reviewdog 🐶 Raw Output: src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp:106:- src/Plugins/ComplexCore/test/FindNeighborhoodsTest.cpp:107:-

0 comments on commit 9b3b2ca

Please sign in to comment.