diff --git a/CMakeLists.txt b/CMakeLists.txt index 595cebeb246d53cde0b4c490bee6fc5987b0d752..472376f25753fce4d8805ab1571a336a88273860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ option(BORNAGAIN_GUI "Build a graphical user interface" OFF) option(BORNAGAIN_MAN "Build a user manual" OFF) option(BUILD_DEBIAN "Build a debian package" OFF) option(ROOT_SUPPORT "Build with dependencies from ROOT" ON) +option(OPENMPI_SUPPORT "Build with OpenMPI support" ON) # --- Path for additional cmake modules --- diff --git a/Core/Algorithms/inc/OMPISimulation.h b/Core/Algorithms/inc/OMPISimulation.h new file mode 100644 index 0000000000000000000000000000000000000000..2744997c614bcf3a0284cae94b0c3956dc24d537 --- /dev/null +++ b/Core/Algorithms/inc/OMPISimulation.h @@ -0,0 +1,19 @@ +#ifndef OMPISIMULATION_H +#define OMPISIMULATION_H + + +class Simulation; + +class OMPISimulation +{ +public: + + void runSimulation(const Simulation *simulation); + +private: + Simulation *m_simulation; +}; + + +#endif + diff --git a/Core/Algorithms/inc/Simulation.h b/Core/Algorithms/inc/Simulation.h index 1d4dfebf9f72a5ccddea9a74579bd36b313198f8..8ccef37e919c25a24908a9b16995fff382d1431b 100644 --- a/Core/Algorithms/inc/Simulation.h +++ b/Core/Algorithms/inc/Simulation.h @@ -51,8 +51,8 @@ public: //! Run a simulation, possibly averaged over parameter distributions void runSimulation(); - //! Returns intensity for a single detector element - void runSimulationElement(size_t index); + //! runs OpenMPI simulation + void runOMPISimulation(); //! Normalize the detector counts void normalize(); diff --git a/Core/Algorithms/src/OMPISimulation.cpp b/Core/Algorithms/src/OMPISimulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c93da315e0263d09f78582571b7c25d147719b33 --- /dev/null +++ b/Core/Algorithms/src/OMPISimulation.cpp @@ -0,0 +1,65 @@ +#include "OMPISimulation.h" +#include "Simulation.h" +#include "OutputData.h" +#include <mpi.h> + + +void OMPISimulation::runSimulation(const Simulation *simulation) +{ + + //MPI_Init(&argc, &argv); + MPI_Init(0, 0); + + MPI_Status st; + + int world_size; + MPI_Comm_size(MPI_COMM_WORLD, &world_size); + + // Get the rank of the process + int world_rank; + MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + + // Get the name of the processor + char processor_name[MPI_MAX_PROCESSOR_NAME]; + int name_len; + MPI_Get_processor_name(processor_name, &name_len); + + // Print off a hello world message + printf("Hello world from processor %s, rank %d" + " out of %d processors\n", + processor_name, world_rank, world_size); + + if(world_rank != 0) { + std::cout << "XXX not a 0" << std::endl; + Simulation *sim = simulation->clone(); + ThreadInfo threadInfo; + threadInfo.n_batches = world_size - 1; + threadInfo.current_batch = world_rank - 1; + std::cout << " xxx preparing to run " << threadInfo.n_batches << " " << threadInfo.current_batch << std::endl; + sim->setThreadInfo(threadInfo); + sim->runSimulation(); + + //std::vector<double> raw = sim->getOutputData()->getRawDataVector(); + std::vector<double> raw; + raw.resize(1000000); + std::cout << " xxx " << threadInfo.n_batches << " " << threadInfo.current_batch << " ... sending" << std::endl; + MPI_Send(&raw[0], raw.size(), MPI_DOUBLE, 0, 0, MPI_COMM_WORLD); + + } + if(world_rank==0) { + std::cout << " preparing to receive" << std::endl; +// std::vector<double> raw = simulation->getOutputData()->getRawDataVector(); + std::vector<double> raw; + raw.resize(1000000); + for(int i=1; i<world_size; ++i) { + std::cout << " ... receiving " << i << std::endl; + MPI_Recv(&raw[0], raw.size(), MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &st); + } + + } + + + // Finalize the MPI environment. + MPI_Finalize(); + +} diff --git a/Core/Algorithms/src/Simulation.cpp b/Core/Algorithms/src/Simulation.cpp index 86b6014d5b2c935c0120b53a803281b5c69d6b24..46811ba17eb2a01015203efbd3c04f6e8b6c69ac 100644 --- a/Core/Algorithms/src/Simulation.cpp +++ b/Core/Algorithms/src/Simulation.cpp @@ -22,6 +22,7 @@ #include "OutputDataFunctions.h" #include "BornAgainNamespace.h" #include "ProgressHandlerDWBA.h" +#include "OMPISimulation.h" #include "Macros.h" GCC_DIAG_OFF(strict-aliasing); @@ -169,27 +170,13 @@ void Simulation::runSimulation() } -void Simulation::runSimulationElement(size_t index) +void Simulation::runOMPISimulation() { - (void)index; // to suppress unused-variable warning - - prepareSimulation(); - if( !mp_sample) - throw NullPointerException( - "Simulation::runSimulation() -> Error! No sample set."); - m_intensity_map.setAllTo(0); - m_polarization_output.setAllTo(Eigen::Matrix2d::Zero()); - - DWBASimulation *p_dwba_simulation = mp_sample->createDWBASimulation(); - if (!p_dwba_simulation) - throw NullPointerException("Simulation::runSimulation() -> " - "No dwba simulation"); - p_dwba_simulation->init(*this); - p_dwba_simulation->run(); - m_intensity_map += p_dwba_simulation->getDWBAIntensity(); - delete p_dwba_simulation; + OMPISimulation ompi; + ompi.runSimulation(this); } + void Simulation::normalize() { if (!m_is_normalized) { diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 2f132cfbd8c1287422eee9b8aa3708b382beee4e..0db4e1651ae00bca329cb92971d270947ae54a30 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -76,6 +76,12 @@ target_link_libraries( ${FFTW_LIBRARY} ${GSL_LIBRARIES} ) + +if(OPENMPI_SUPPORT) + include_directories(${MPI_INCLUDE_PATH}) + target_link_libraries(${library_name} ${MPI_LIBRARIES}) +endif() + if(BORNAGAIN_PYTHON) include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR}) target_link_libraries(${library_name} ${PYTHON_LIBRARIES}) @@ -117,6 +123,7 @@ file(GLOB include_files "Geometry/inc/*.h" "Samples/inc/*.h" "Tools/inc/*.h" + "StandardSamples/*.h" ) install (FILES ${include_files} DESTINATION ${destination_include} COMPONENT Headers) diff --git a/Core/PythonAPI/src/PythonModule.cpp b/Core/PythonAPI/src/PythonModule.cpp index 32bee63c28b60ed77954174a2f39fc2d29aa1cc2..f2398a0e15bc89c8433f20ffc46b29d4809ee69f 100644 --- a/Core/PythonAPI/src/PythonModule.cpp +++ b/Core/PythonAPI/src/PythonModule.cpp @@ -10,130 +10,130 @@ GCC_DIAG_ON(missing-field-initializers) #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define PY_ARRAY_UNIQUE_SYMBOL BORNAGAIN_PYTHONAPI_ARRAY #include "numpy/arrayobject.h" -#include "ParticleBuilder.pypp.h" -#include "FormFactorFullSpheroid.pypp.h" -#include "DistributionGate.pypp.h" -#include "SimpleSelectionRule.pypp.h" -#include "RealParameterWrapper.pypp.h" -#include "vdouble1d_t.pypp.h" -#include "SimulationParameters.pypp.h" -#include "Transform3D.pypp.h" -#include "ThreadInfo.pypp.h" -#include "InterferenceFunction2DLattice.pypp.h" -#include "LayerInterface.pypp.h" -#include "ILayout.pypp.h" -#include "FormFactorCone6.pypp.h" -#include "FormFactorTetrahedron.pypp.h" -#include "FTDistribution1DCosine.pypp.h" -#include "FTDistribution1DTriangle.pypp.h" -#include "FormFactorWeighted.pypp.h" +#include "IFTDistribution2D.pypp.h" +#include "IntensityDataHelper.pypp.h" +#include "Detector.pypp.h" +#include "FormFactorRipple2.pypp.h" #include "DistributionGaussian.pypp.h" -#include "IDetectorResolution.pypp.h" +#include "LatticeBasis.pypp.h" +#include "FTDistribution2DCone.pypp.h" +#include "ParticleCoreShell.pypp.h" +#include "Beam.pypp.h" +#include "ParticleLayout.pypp.h" +#include "Lattice.pypp.h" #include "FormFactorCylinder.pypp.h" -#include "Crystal.pypp.h" -#include "FTDistribution1DCauchy.pypp.h" -#include "IFormFactorBorn.pypp.h" -#include "FormFactorEllipsoidalCylinder.pypp.h" -#include "InterferenceFunctionNone.pypp.h" -#include "FTDistribution2DGate.pypp.h" -#include "vector_kvector_t.pypp.h" +#include "ICloneable.pypp.h" #include "FormFactorTruncatedSpheroid.pypp.h" -#include "Particle.pypp.h" -#include "FTDistribution2DCauchy.pypp.h" -#include "FormFactorCrystal.pypp.h" -#include "vector_longinteger_t.pypp.h" -#include "FTDistribution1DGauss.pypp.h" +#include "FTDistribution1DCosine.pypp.h" +#include "StochasticSampledParameter.pypp.h" +#include "HomogeneousMaterial.pypp.h" +#include "FormFactorCone6.pypp.h" +#include "vector_integer_t.pypp.h" +#include "AxisDouble.pypp.h" +#include "FormFactorInfLongRipple2.pypp.h" +#include "IAxis.pypp.h" +#include "FormFactorTetrahedron.pypp.h" +#include "InterferenceFunction1DLattice.pypp.h" +#include "Layer.pypp.h" +#include "ThreadInfo.pypp.h" +#include "IFormFactor.pypp.h" +#include "IObservable.pypp.h" #include "FTDistribution1DGate.pypp.h" +#include "RealParameterWrapper.pypp.h" +#include "FormFactorInfLongBox.pypp.h" +#include "ResolutionFunction2DSimple.pypp.h" +#include "SimulationParameters.pypp.h" +#include "FormFactorSphereUniformRadius.pypp.h" +#include "AxisBin.pypp.h" +#include "FormFactorGauss.pypp.h" +#include "FormFactorFullSpheroid.pypp.h" #include "FormFactorAnisoPyramid.pypp.h" +#include "PythonInterface_global_variables.pypp.h" +#include "FTDistribution1DTriangle.pypp.h" +#include "ISampleBuilder.pypp.h" +#include "StochasticParameter_t.pypp.h" +#include "StochasticDoubleGaussian.pypp.h" +#include "FormFactorPrism6.pypp.h" +#include "InterferenceFunction2DLattice.pypp.h" +#include "FormFactorPyramid.pypp.h" +#include "FormFactorBox.pypp.h" +#include "DistributionCosine.pypp.h" +#include "IResolutionFunction2D.pypp.h" +#include "IFormFactorBorn.pypp.h" #include "MultiLayer.pypp.h" -#include "IFormFactor.pypp.h" -#include "kvector_t.pypp.h" -#include "FormFactorSphereUniformRadius.pypp.h" -#include "OffSpecSimulation.pypp.h" -#include "FormFactorRipple1.pypp.h" -#include "InterferenceFunction1DParaCrystal.pypp.h" -#include "Simulation.pypp.h" -#include "IObservable.pypp.h" -#include "FormFactorLorentz.pypp.h" -#include "ISelectionRule.pypp.h" -#include "FormFactorRipple2.pypp.h" -#include "StochasticDoubleGate.pypp.h" -#include "LayerRoughness.pypp.h" -#include "Bin1DCVector.pypp.h" -#include "FormFactorSphereGaussianRadius.pypp.h" +#include "DistributionLorentz.pypp.h" +#include "FTDistribution2DCauchy.pypp.h" +#include "FTDistribution2DVoigt.pypp.h" +#include "ICompositeSample.pypp.h" +#include "cvector_t.pypp.h" #include "ParameterPool.pypp.h" +#include "Particle.pypp.h" +#include "FormFactorCone.pypp.h" #include "FormFactorPrism3.pypp.h" -#include "StochasticDoubleGaussian.pypp.h" +#include "InterferenceFunction2DParaCrystal.pypp.h" +#include "vdouble1d_t.pypp.h" +#include "FormFactorEllipsoidalCylinder.pypp.h" +#include "MesoCrystal.pypp.h" +#include "FormFactorDecoratorDebyeWaller.pypp.h" +#include "vector_IFormFactorPtr_t.pypp.h" +#include "ILayout.pypp.h" #include "IMaterial.pypp.h" -#include "FTDistribution1DVoigt.pypp.h" -#include "ResolutionFunction2DSimple.pypp.h" -#include "AxisDouble.pypp.h" -#include "FormFactorPrism6.pypp.h" -#include "IClusteredParticles.pypp.h" -#include "DistributionCosine.pypp.h" +#include "IFormFactorDecorator.pypp.h" +#include "Instrument.pypp.h" +#include "IDetectorResolution.pypp.h" #include "FormFactorHemiEllipsoid.pypp.h" -#include "IAxis.pypp.h" -#include "vector_integer_t.pypp.h" -#include "Layer.pypp.h" -#include "FormFactorPyramid.pypp.h" -#include "StochasticSampledParameter.pypp.h" -#include "FTDistribution2DCone.pypp.h" -#include "IFTDistribution1D.pypp.h" -#include "DistributionLorentz.pypp.h" #include "IDistribution1D.pypp.h" -#include "PositionParticleInfo.pypp.h" +#include "ISelectionRule.pypp.h" #include "HomogeneousMagneticMaterial.pypp.h" -#include "FormFactorCuboctahedron.pypp.h" -#include "cvector_t.pypp.h" -#include "OutputDataIOFactory.pypp.h" -#include "PythonInterface_free_functions.pypp.h" -#include "FormFactorSphereLogNormalRadius.pypp.h" +#include "Bin1D.pypp.h" +#include "ParticleInfo.pypp.h" +#include "vector_longinteger_t.pypp.h" +#include "DistributionLogNormal.pypp.h" #include "FormFactorInfLongRipple1.pypp.h" -#include "IResolutionFunction2D.pypp.h" -#include "vector_IFormFactorPtr_t.pypp.h" +#include "LayerInterface.pypp.h" +#include "FTDistribution2DGate.pypp.h" #include "FormFactorFullSphere.pypp.h" -#include "ParticleLayout.pypp.h" -#include "StochasticParameter_t.pypp.h" -#include "FormFactorBox.pypp.h" +#include "Transform3D.pypp.h" +#include "OffSpecSimulation.pypp.h" +#include "FTDistribution2DGauss.pypp.h" +#include "FormFactorRipple1.pypp.h" +#include "PositionParticleInfo.pypp.h" +#include "LayerRoughness.pypp.h" +#include "FormFactorCrystal.pypp.h" +#include "FormFactorSphereLogNormalRadius.pypp.h" +#include "IntensityData.pypp.h" +#include "FormFactorTruncatedSphere.pypp.h" #include "IParameterized.pypp.h" -#include "Lattice2DIFParameters.pypp.h" -#include "IFormFactorDecorator.pypp.h" -#include "InterferenceFunction1DLattice.pypp.h" -#include "ISample.pypp.h" -#include "ISampleBuilder.pypp.h" -#include "PythonInterface_global_variables.pypp.h" -#include "Beam.pypp.h" -#include "HomogeneousMaterial.pypp.h" -#include "ICloneable.pypp.h" -#include "ParticleCoreShell.pypp.h" -#include "FormFactorDecoratorDebyeWaller.pypp.h" -#include "MesoCrystal.pypp.h" +#include "Bin1DCVector.pypp.h" +#include "DistributionGate.pypp.h" +#include "StochasticDoubleGate.pypp.h" +#include "IClusteredParticles.pypp.h" +#include "FormFactorWeighted.pypp.h" +#include "IInterferenceFunction.pypp.h" +#include "SimpleSelectionRule.pypp.h" +#include "FormFactorLorentz.pypp.h" +#include "OutputDataIOFactory.pypp.h" +#include "FTDistribution1DCauchy.pypp.h" +#include "vector_kvector_t.pypp.h" +#include "InterferenceFunction1DParaCrystal.pypp.h" +#include "InterferenceFunctionNone.pypp.h" +#include "Crystal.pypp.h" +#include "FormFactorCuboctahedron.pypp.h" +#include "PythonInterface_free_functions.pypp.h" #include "Lattice1DIFParameters.pypp.h" +#include "FTDistribution1DGauss.pypp.h" +#include "kvector_t.pypp.h" +#include "FTDistribution1DVoigt.pypp.h" +#include "Simulation.pypp.h" +#include "ISample.pypp.h" #include "IObserver.pypp.h" -#include "IntensityData.pypp.h" -#include "Lattice.pypp.h" -#include "IInterferenceFunction.pypp.h" -#include "ParticleInfo.pypp.h" -#include "Instrument.pypp.h" -#include "FormFactorInfLongBox.pypp.h" -#include "IntensityDataHelper.pypp.h" -#include "FormFactorCone.pypp.h" -#include "FTDistribution2DGauss.pypp.h" -#include "FormFactorTruncatedSphere.pypp.h" -#include "FTDistribution2DVoigt.pypp.h" -#include "FormFactorGauss.pypp.h" -#include "InterferenceFunction2DParaCrystal.pypp.h" -#include "Detector.pypp.h" -#include "FormFactorInfLongRipple2.pypp.h" -#include "LatticeBasis.pypp.h" -#include "ICompositeSample.pypp.h" -#include "Bin1D.pypp.h" -#include "AxisBin.pypp.h" -#include "DistributionLogNormal.pypp.h" -#include "IFTDistribution2D.pypp.h" -#include "__call_policies.pypp.hpp" +#include "ParticleBuilder.pypp.h" +#include "FormFactorSphereGaussianRadius.pypp.h" +#include "Lattice2DIFParameters.pypp.h" +#include "IFTDistribution1D.pypp.h" #include "__convenience.pypp.hpp" #include "__call_policies.pypp.hpp" +#include "__call_policies.pypp.hpp" #include "__convenience.pypp.hpp" #include "PythonListConverter.h" diff --git a/Core/PythonAPI/src/Simulation.pypp.cpp b/Core/PythonAPI/src/Simulation.pypp.cpp index a702cf52c55f8ba6ebf4d8a1c91c3452e40cb4f7..a1c90d4c1b946baf31dc51eb4ee349207975ab78 100644 --- a/Core/PythonAPI/src/Simulation.pypp.cpp +++ b/Core/PythonAPI/src/Simulation.pypp.cpp @@ -235,23 +235,22 @@ void register_Simulation_class(){ , prepareSimulation_function_type( &::Simulation::prepareSimulation ) ); } - { //::Simulation::runSimulation + { //::Simulation::runOMPISimulation - typedef void ( ::Simulation::*runSimulation_function_type )( ) ; + typedef void ( ::Simulation::*runOMPISimulation_function_type )( ) ; Simulation_exposer.def( - "runSimulation" - , runSimulation_function_type( &::Simulation::runSimulation ) ); + "runOMPISimulation" + , runOMPISimulation_function_type( &::Simulation::runOMPISimulation ) ); } - { //::Simulation::runSimulationElement + { //::Simulation::runSimulation - typedef void ( ::Simulation::*runSimulationElement_function_type )( ::std::size_t ) ; + typedef void ( ::Simulation::*runSimulation_function_type )( ) ; Simulation_exposer.def( - "runSimulationElement" - , runSimulationElement_function_type( &::Simulation::runSimulationElement ) - , ( bp::arg("index") ) ); + "runSimulation" + , runSimulation_function_type( &::Simulation::runSimulation ) ); } { //::Simulation::setBeamIntensity diff --git a/Fit/PythonAPI/src/PythonModule.cpp b/Fit/PythonAPI/src/PythonModule.cpp index ef8312b19c0e5f34a1dd036a15ac8689fdb68a4c..ccbb33819c4bd84c95187372fe57c3b771eb71d7 100644 --- a/Fit/PythonAPI/src/PythonModule.cpp +++ b/Fit/PythonAPI/src/PythonModule.cpp @@ -5,38 +5,38 @@ GCC_DIAG_OFF(missing-field-initializers) #include "boost/python.hpp" GCC_DIAG_ON(unused-parameter) GCC_DIAG_ON(missing-field-initializers) -#include "IntensityFunctionSqrt.pypp.h" +#include "FitStrategyFixParameters.pypp.h" +#include "AttFitting.pypp.h" +#include "FitSuiteObjects.pypp.h" +#include "ISquaredFunction.pypp.h" #include "MinimizerFactory.pypp.h" -#include "IMinimizer.pypp.h" -#include "vector_string_t.pypp.h" -#include "SquaredFunctionSystematicError.pypp.h" +#include "IntensityScaleAndShiftNormalizer.pypp.h" #include "IntensityNormalizer.pypp.h" +#include "SquaredFunctionMeanSquaredError.pypp.h" +#include "vector_string_t.pypp.h" +#include "MinimizerOptions.pypp.h" +#include "IntensityFunctionSqrt.pypp.h" +#include "IFitStrategy.pypp.h" #include "IIntensityFunction.pypp.h" -#include "INamed.pypp.h" -#include "IntensityFunctionLog.pypp.h" -#include "FitSuiteParameters.pypp.h" -#include "AttFitting.pypp.h" #include "FitParameter.pypp.h" -#include "IntensityScaleAndShiftNormalizer.pypp.h" -#include "IChiSquaredModule.pypp.h" -#include "FitStrategyAdjustMinimizer.pypp.h" -#include "IFitStrategy.pypp.h" -#include "FitStrategyFixParameters.pypp.h" -#include "SquaredFunctionGaussianError.pypp.h" -#include "IIntensityNormalizer.pypp.h" -#include "FitSuite.pypp.h" +#include "FitObject.pypp.h" +#include "IMinimizer.pypp.h" +#include "INamed.pypp.h" +#include "FitStrategyReleaseParameters.pypp.h" #include "FitStrategyAdjustParameters.pypp.h" -#include "ChiSquaredModule.pypp.h" -#include "MinimizerOptions.pypp.h" +#include "IntensityFunctionLog.pypp.h" #include "SquaredFunctionDefault.pypp.h" -#include "SquaredFunctionMeanSquaredError.pypp.h" -#include "ISquaredFunction.pypp.h" +#include "ChiSquaredModule.pypp.h" +#include "FitStrategyAdjustMinimizer.pypp.h" #include "FitStrategyDefault.pypp.h" +#include "FitSuite.pypp.h" +#include "IIntensityNormalizer.pypp.h" #include "AttLimits.pypp.h" -#include "FitObject.pypp.h" -#include "FitSuiteObjects.pypp.h" +#include "IChiSquaredModule.pypp.h" #include "SquaredFunctionSimError.pypp.h" -#include "FitStrategyReleaseParameters.pypp.h" +#include "FitSuiteParameters.pypp.h" +#include "SquaredFunctionSystematicError.pypp.h" +#include "SquaredFunctionGaussianError.pypp.h" BOOST_PYTHON_MODULE(libBornAgainFit){ boost::python::docstring_options doc_options(true, true, false); diff --git a/Tests/UnitTests/TestCore/CMakeLists.txt b/Tests/UnitTests/TestCore/CMakeLists.txt index ef28e040c3499202c547a54af6ad569a7948ccc6..85c9c53740ca53c79b3f983af0b739a912d876fc 100644 --- a/Tests/UnitTests/TestCore/CMakeLists.txt +++ b/Tests/UnitTests/TestCore/CMakeLists.txt @@ -24,6 +24,12 @@ target_link_libraries(TestCore ${GSL_LIBRARIES} ) +if(OPENMPI_SUPPORT) + include_directories(${MPI_INCLUDE_PATH}) + target_link_libraries(TestCore ${MPI_LIBRARIES}) +endif() + + # to build executable right in lib directory to not to have problems with finding libBornAgainCore.dll under Windows set_property(TARGET TestCore PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/Tests/UnitTests/TestFit/CMakeLists.txt b/Tests/UnitTests/TestFit/CMakeLists.txt index 778c5c1dacb97a5ff1bdecb43227246b787bc5ca..b02bc246d95c9623b411a98a189a5e5e0a595bff 100644 --- a/Tests/UnitTests/TestFit/CMakeLists.txt +++ b/Tests/UnitTests/TestFit/CMakeLists.txt @@ -27,6 +27,12 @@ target_link_libraries(TestFit ${Boost_LIBRARIES} ) +if(OPENMPI_SUPPORT) + include_directories(${MPI_INCLUDE_PATH}) + target_link_libraries(TestFit ${MPI_LIBRARIES}) +endif() + + # to build executable right in lib directory to not to have problems with finding libBornAgainCore.dll under Windows set_property(TARGET TestFit PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake index f29a7f4647ca2e610a80da4f3615fdb50fbedbcc..e118d7cdb1c4c77601bccb07e4d6b934637054af 100644 --- a/cmake/modules/SearchInstalledSoftware.cmake +++ b/cmake/modules/SearchInstalledSoftware.cmake @@ -1,5 +1,11 @@ # Search for installed software required by BornAgain +if(OPENMPI_SUPPORT) + message(STATUS "Configuring with OpenMPI support") + find_package(MPI REQUIRED) +endif() + + # --- Eigen3 --- find_package(Eigen3 3.1.0) if(NOT EIGEN3_FOUND) @@ -93,6 +99,7 @@ if(BORNAGAIN_PYTHON OR BORNAGAIN_GUI) endif() + # --- ROOT --- if(ROOT_SUPPORT) find_package(ROOT) diff --git a/dev-tools/openmpi/batest/CMakeLists.txt b/dev-tools/openmpi/batest/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f08c398f8740a96f2023e454f26570751a81d0d --- /dev/null +++ b/dev-tools/openmpi/batest/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.8) + +project(batest) + +add_executable(batest batest.cpp) + +# path to the cmake modules +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules) + +# Find libraries + +# --- Eigen3 --- +find_package(Eigen3 3.1.0 REQUIRED) + +# --- BOOST --- +set(boost_libraries_required date_time chrono program_options iostreams system filesystem regex thread) +find_package(Boost 1.48.0 COMPONENTS ${boost_libraries_required} REQUIRED) +message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") +message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") +message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}") + +# --- BornAgain --- +find_package(BornAgain REQUIRED) + +#-----ROOT------------ +find_package(ROOT REQUIRED) + +include_directories( + ${Boost_INCLUDE_DIRS} + ${EIGEN3_INCLUDE_DIR} + ${ROOT_INCLUDE_DIR} + ${BORNAGAIN_INCLUDE_DIR} +) + +target_link_libraries(batest + ${Boost_LIBRARIES} + ${BORNAGAIN_LIBRARIES} + ${ROOT_LIBRARIES} +) diff --git a/dev-tools/openmpi/batest/batest.cpp b/dev-tools/openmpi/batest/batest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8278ecc421e24527a418599f5bc5c023aaeff10 --- /dev/null +++ b/dev-tools/openmpi/batest/batest.cpp @@ -0,0 +1,15 @@ +#include <iostream> +#include "SimulationRegistry.h" + +int main() +{ + + std::cout << "Hello World" << std::endl; + + SimulationRegistry sim_registry; + Simulation *simulation = sim_registry.createSimulation("isgisaxs01"); + + simulation->runOMPISimulation(); + + return 0; +} \ No newline at end of file diff --git a/dev-tools/openmpi/batest/modules/FindBornAgain.cmake b/dev-tools/openmpi/batest/modules/FindBornAgain.cmake new file mode 100644 index 0000000000000000000000000000000000000000..f761cbd62311608c05bb045e98604a4c05d39b06 --- /dev/null +++ b/dev-tools/openmpi/batest/modules/FindBornAgain.cmake @@ -0,0 +1,44 @@ +# Finds BornAgain instalation +# It defines: +# BORNAGAIN_INCLUDE_DIR PATH to the include directory +# BORNAGAIN_LIBRARIES BornAgain libraries + +set(BORNAGAINSYS $ENV{BORNAGAINSYS}) + +if(BORNAGAINSYS) + set(BORNAGAIN_LIBRARY_DIR ${BORNAGAINSYS}/lib) + set(BORNAGAIN_INCLUDE_DIR ${BORNAGAINSYS}/include/BornAgain) +endif() + +find_library (BORNAGAIN_CORE BornAgainCore + PATHS ${BORNAGAIN_LIBRARY_DIR} + HINTS ${BORNAGAIN_LIBRARY_DIR} +) + +find_library (BORNAGAIN_FIT BornAgainFit + PATHS ${BORNAGAIN_LIBRARY_DIR} + HINTS ${BORNAGAIN_LIBRARY_DIR} +) +set(BORNAGAIN_LIBRARIES ${BORNAGAIN_CORE} ${BORNAGAIN_FIT}) + +find_path(BORNAGAIN_INCLUDE_DIR BAVersion.h + PATHS /usr/include /usr/local/include /opt/local/include ${BORNAGAIN_INCLUDE_DIR} + PATH_SUFFIXES BornAgain + HINTS ${BORNAGAIN_INCLUDE_DIR} +) + +# 32-bits systems require special Eigen options +execute_process(COMMAND uname -m OUTPUT_VARIABLE SYSCTL_OUTPUT) +if(NOT ${SYSCTL_OUTPUT} MATCHES x86_64) + add_definitions(-DEIGEN_DONT_ALIGN_STATICALLY=1) +endif() + +message(STATUS "BORNAGAIN_LIBRARIES ${BORNAGAIN_LIBRARIES}") +message(STATUS "BORNAGAIN_INCLUDE_DIR ${BORNAGAIN_INCLUDE_DIR}") +mark_as_advanced(BORNAGAIN_LIBRARIES BORNAGAIN_INCLUDE_DIR) + +if(NOT BORNAGAIN_LIBRARIES OR NOT BORNAGAIN_INCLUDE_DIR) + if(BornAgain_FIND_REQUIRED) + message( FATAL_ERROR "FindBornAgain: can't find BornAgain header or library" ) + endif() +endif() diff --git a/dev-tools/openmpi/batest/modules/FindEigen3.cmake b/dev-tools/openmpi/batest/modules/FindEigen3.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9c546a05d859b18c49554d7ee7221cc486b7760e --- /dev/null +++ b/dev-tools/openmpi/batest/modules/FindEigen3.cmake @@ -0,0 +1,81 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> +# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr> +# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_check_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) + if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK FALSE) + else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + set(EIGEN3_VERSION_OK TRUE) + endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) + + if(NOT EIGEN3_VERSION_OK) + + message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " + "but at least version ${Eigen3_FIND_VERSION} is required") + endif(NOT EIGEN3_VERSION_OK) +endmacro(_eigen3_check_version) + +if (EIGEN3_INCLUDE_DIR) + + # in cache already + _eigen3_check_version() + set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) + +else (EIGEN3_INCLUDE_DIR) + + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + PATHS + ${CMAKE_INSTALL_PREFIX}/include + ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES eigen3 eigen + ) + + if(EIGEN3_INCLUDE_DIR) + _eigen3_check_version() + endif(EIGEN3_INCLUDE_DIR) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) + + mark_as_advanced(EIGEN3_INCLUDE_DIR) + +endif(EIGEN3_INCLUDE_DIR) + diff --git a/dev-tools/openmpi/batest/modules/FindROOT.cmake b/dev-tools/openmpi/batest/modules/FindROOT.cmake new file mode 100644 index 0000000000000000000000000000000000000000..415b3c7bc5c879745e796755b3123e82e484573b --- /dev/null +++ b/dev-tools/openmpi/batest/modules/FindROOT.cmake @@ -0,0 +1,170 @@ +# - Finds ROOT instalation +# This module sets up ROOT information +# It defines: +# ROOT_FOUND If the ROOT is found +# ROOT_INCLUDE_DIR PATH to the include directory +# ROOT_LIBRARIES Most common libraries +# ROOT_LIBRARY_DIR PATH to the library directory + + +find_program(ROOT_CONFIG_EXECUTABLE root-config + PATHS $ENV{ROOTSYS}/bin) + +if(NOT ROOT_CONFIG_EXECUTABLE) + set(ROOT_FOUND FALSE) +else() + set(ROOT_FOUND TRUE) + + if(WIN32) + STRING(REGEX REPLACE "\\\\" "/" ROOTSYS $ENV{ROOTSYS} ) # Convert C:\root\ to C:/root/ + set(ROOT_INCLUDE_DIR ${ROOTSYS}/include) + set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib) + #set(ROOT_LIBRARIES -LIBPATH:${ROOT_LIBRARY_DIR} libGpad.lib libHist.lib libGraf.lib libGraf3d.lib libTree.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libRIO.lib libNet.lib libThread.lib libCore.lib libCint.lib) + set(ROOT_LIBRARIES -LIBPATH:${ROOT_LIBRARY_DIR} libGui.lib libGpad.lib libHist.lib libGraf.lib libGraf3d.lib libTree.lib libRint.lib libPostscript.lib libMatrix.lib libMathCore.lib libRIO.lib libNet.lib libThread.lib libCore.lib libCint.lib) + else() + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix + OUTPUT_VARIABLE ROOTSYS + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --version + OUTPUT_VARIABLE ROOT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir + OUTPUT_VARIABLE ROOT_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND ${ROOT_CONFIG_EXECUTABLE} --glibs + OUTPUT_VARIABLE ROOT_LIBRARIES + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib) + + # Make variables changeble to the advanced user + mark_as_advanced(ROOT_CONFIG_EXECUTABLE) + + if(NOT ROOT_FIND_QUIETLY) + message(STATUS "Found ROOT ${ROOT_VERSION} in ${ROOTSYS}") + endif() + endif() +endif() + + +#include(CMakeMacroParseArguments) +find_program(ROOTCINT_EXECUTABLE rootcint PATHS $ENV{ROOTSYS}/bin) +find_program(GENREFLEX_EXECUTABLE genreflex PATHS $ENV{ROOTSYS}/bin) +find_package(GCCXML) + +#---------------------------------------------------------------------------- +# function ROOT_GENERATE_DICTIONARY( dictionary +# header1 header2 ... +# LINKDEF linkdef1 ... +# OPTIONS opt1...) +function(ROOT_GENERATE_DICTIONARY dictionary) + CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN}) + #---Get the list of header files------------------------- + set(headerfiles) + foreach(fp ${ARG_UNPARSED_ARGUMENTS}) + file(GLOB files ${fp}) + if(files) + foreach(f ${files}) + if(NOT f MATCHES LinkDef) + set(headerfiles ${headerfiles} ${f}) + endif() + endforeach() + else() + set(headerfiles ${headerfiles} ${fp}) + endif() + endforeach() + #---Get the list of include directories------------------ + get_directory_property(incdirs INCLUDE_DIRECTORIES) + set(includedirs) + foreach( d ${incdirs}) + if(NOT ${d} STREQUAL "/usr/include") + set(includedirs ${includedirs} -I${d}) + endif() + endforeach() + #---Get LinkDef.h file------------------------------------ + set(linkdefs) + foreach( f ${ARG_LINKDEF}) + if( IS_ABSOLUTE ${f}) + set(linkdefs ${linkdefs} ${f}) + else() + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f}) + set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f}) + else() + set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/${f}) + endif() + endif() + endforeach() + #---call rootcint------------------------------------------ + add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h + COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx + -c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} + DEPENDS ${headerfiles} ${linkdefs}) +endfunction() + +#---------------------------------------------------------------------------- +# function REFLEX_GENERATE_DICTIONARY(dictionary +# header1 header2 ... +# SELECTION selectionfile ... +# OPTIONS opt1...) +function(REFLEX_GENERATE_DICTIONARY dictionary) + CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN}) + #---Get the list of header files------------------------- + set(headerfiles) + foreach(fp ${ARG_UNPARSED_ARGUMENTS}) + file(GLOB files ${fp}) + if(files) + foreach(f ${files}) + set(headerfiles ${headerfiles} ${f}) + endforeach() + else() + set(headerfiles ${headerfiles} ${fp}) + endif() + endforeach() + #---Get Selection file------------------------------------ + if(IS_ABSOLUTE ${ARG_SELECTION}) + set(selectionfile ${ARG_SELECTION}) + else() + set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION}) + endif() + #---Get the list of include directories------------------ + get_directory_property(incdirs INCLUDE_DIRECTORIES) + set(includedirs) + foreach( d ${incdirs}) + set(includedirs ${includedirs} -I${d}) + endforeach() + #---Get preprocessor definitions-------------------------- + get_directory_property(defs COMPILE_DEFINITIONS) + foreach( d ${defs}) + set(definitions ${definitions} -D${d}) + endforeach() + #---Nanes and others--------------------------------------- + set(gensrcdict ${dictionary}.cpp) + if(MSVC) + set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"") + else() + #set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'") + set(gccxmlopts) + endif() + #set(rootmapname ${dictionary}Dict.rootmap) + #set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict) + #---Check GCCXML and get path----------------------------- + if(GCCXML) + get_filename_component(gccxmlpath ${GCCXML} PATH) + else() + message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable") + endif() + #---Actual command---------------------------------------- + add_custom_command(OUTPUT ${gensrcdict} ${rootmapname} + COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile} + --gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions} + DEPENDS ${headerfiles} ${selectionfile}) +endfunction() +