Commit 826feb4f authored by Yaroslav Gevorkov's avatar Yaroslav Gevorkov
Browse files

added openmp for multi seed refinement

parent c22fe6fb
...@@ -13,6 +13,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) ...@@ -13,6 +13,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif() endif()
find_package(Eigen3 3.3.4 NO_MODULE) find_package(Eigen3 3.3.4 NO_MODULE)
find_package(OpenMP)
include_directories(include) include_directories(include)
...@@ -41,12 +42,16 @@ set(SOURCES_test src/main.cpp ...@@ -41,12 +42,16 @@ set(SOURCES_test src/main.cpp
src/tests.cpp src/tests.cpp
) )
if(PINKINDEXER_BUILD_EXECUTABLE) if(PINKINDEXER_BUILD_EXECUTABLE)
add_executable(pinkIndexer ${SOURCES} ${SOURCES_test}) add_executable(pinkIndexer ${SOURCES} ${SOURCES_test})
else(PINKINDEXER_BUILD_EXECUTABLE) else(PINKINDEXER_BUILD_EXECUTABLE)
add_library(pinkIndexer SHARED ${SOURCES}) add_library(pinkIndexer SHARED ${SOURCES})
endif(PINKINDEXER_BUILD_EXECUTABLE) endif(PINKINDEXER_BUILD_EXECUTABLE)
if(OpenMP_CXX_FOUND)
target_link_libraries(pinkIndexer PUBLIC OpenMP::OpenMP_CXX)
endif(OpenMP_CXX_FOUND)
if(EIGEN3_FOUND) if(EIGEN3_FOUND)
target_link_libraries (pinkIndexer PUBLIC Eigen3::Eigen) target_link_libraries (pinkIndexer PUBLIC Eigen3::Eigen)
else() else()
......
...@@ -63,7 +63,6 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -63,7 +63,6 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
Matrix3f bestBasis = bestRotation * sampleLattice.getBasis(); Matrix3f bestBasis = bestRotation * sampleLattice.getBasis();
indexedLattice = Lattice(bestBasis); indexedLattice = Lattice(bestBasis);
// indexedLattice.minimize();
switch (refinementType) switch (refinementType)
{ {
...@@ -91,37 +90,48 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen: ...@@ -91,37 +90,48 @@ int PinkIndexer::indexPattern(Lattice& indexedLattice, Eigen::Array<bool, Eigen:
break; break;
case RefinementType::firstFixedThenVariableLatticeParametersMultiSeed: case RefinementType::firstFixedThenVariableLatticeParametersMultiSeed:
{ {
Lattice bestLattice = indexedLattice; #define REFINEMENT_TRIES 250
int maxFittedNodesCount = refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms); int fittedNodesCount[REFINEMENT_TRIES];
Lattice fittedLattices[REFINEMENT_TRIES];
float maxRelativeDeviation = 0.01; float maxRelativeDeviation = 0.012;
Array<float, 1, 3> columnDeviationNorms = indexedLattice.getBasis().colwise().norm() * maxRelativeDeviation; Array<float, 1, 3> columnDeviationNorms = indexedLattice.getBasis().colwise().norm() * maxRelativeDeviation;
for (uint32_t i = 0; i < 16; ++i) #pragma omp parallel for
for (int i = 0; i < REFINEMENT_TRIES; ++i)
{ {
Matrix3f currentBasis = indexedLattice.getBasis() + (Array33f::Random().rowwise() * columnDeviationNorms ).matrix(); Refinement refinement(finalRefinementTolerance);
Lattice currentLattice(currentBasis);
Matrix3f currentBasis = indexedLattice.getBasis() + (Array33f::Random().rowwise() * columnDeviationNorms).matrix();
fittedLattices[i] = Lattice(currentBasis);
refinement.setTolerance(min(finalRefinementTolerance * 2.5, 0.12)); refinement.setTolerance(min(finalRefinementTolerance * 2.5, 0.12));
refinement.refineFixedLattice(currentLattice, ucsDirections, ucsBorderNorms); refinement.refineFixedLattice(fittedLattices[i], ucsDirections, ucsBorderNorms);
refinement.setTolerance(min(finalRefinementTolerance * 1.8, 0.10)); refinement.setTolerance(min(finalRefinementTolerance * 1.8, 0.10));
refinement.refineVariableLattice(currentLattice, ucsDirections, ucsBorderNorms); refinement.refineVariableLattice(fittedLattices[i], ucsDirections, ucsBorderNorms);
refinement.setTolerance(finalRefinementTolerance); refinement.setTolerance(finalRefinementTolerance);
refinement.refineVariableLattice(currentLattice, ucsDirections, ucsBorderNorms); refinement.refineVariableLattice(fittedLattices[i], ucsDirections, ucsBorderNorms);
fittedNodesCount[i] = refinement.getFittedPeaks(fittedLattices[i], fittedPeaks, ucsDirections, ucsBorderNorms);
}
int fittedNodesCount = refinement.getFittedPeaks(currentLattice, fittedPeaks, ucsDirections, ucsBorderNorms); Lattice bestLattice = indexedLattice;
if (fittedNodesCount > maxFittedNodesCount) int maxFittedNodesCount = refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms);
for (int i = 0; i < REFINEMENT_TRIES; ++i)
{
if (fittedNodesCount[i] > maxFittedNodesCount)
{ {
maxFittedNodesCount = fittedNodesCount; maxFittedNodesCount = fittedNodesCount[i];
bestLattice = currentLattice; indexedLattice = fittedLattices[i];
} }
} }
indexedLattice = bestLattice;
} }
break; break;
default: default:
break; break;
} }
indexedLattice.minimize();
return refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms); return refinement.getFittedPeaks(indexedLattice, fittedPeaks, ucsDirections, ucsBorderNorms);
// int fittedPeaksCount = refinement.getFittedPeaksCount(indexedLattice, ucsDirections, ucsBorderNorms); // int fittedPeaksCount = refinement.getFittedPeaksCount(indexedLattice, ucsDirections, ucsBorderNorms);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment