Skip to content
Snippets Groups Projects
Commit 37fffe51 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

First attempt in reviving the mpi test executable

parent 689a3579
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ add_custom_target(fullcheck COMMAND ${CMAKE_CTEST_COMMAND}) # => 'make check' is ...@@ -25,7 +25,7 @@ add_custom_target(fullcheck COMMAND ${CMAKE_CTEST_COMMAND}) # => 'make check' is
include(VERSION.cmake) include(VERSION.cmake)
# --- Declare project-wide user flags, and set default values --- # declare project-wide user flags, and set default values
option(BORNAGAIN_PYTHON "Build with python support" ON) option(BORNAGAIN_PYTHON "Build with python support" ON)
option(BORNAGAIN_USE_PYTHON3 "Build against python 3.x instead of 2.7" ON) option(BORNAGAIN_USE_PYTHON3 "Build against python 3.x instead of 2.7" ON)
option(BORNAGAIN_GENERATE_BINDINGS "Generate python bindings during build (requires swig)" OFF) option(BORNAGAIN_GENERATE_BINDINGS "Generate python bindings during build (requires swig)" OFF)
...@@ -53,7 +53,7 @@ if(AUTOGENERATE) ...@@ -53,7 +53,7 @@ if(AUTOGENERATE)
set(BORNAGAIN_GENERATE_BINDINGS ON) set(BORNAGAIN_GENERATE_BINDINGS ON)
endif() endif()
#--- Include CMake macros and functions --- # include CMake macros and functions
include(GetFilenameComponent) # overwrite CMake command include(GetFilenameComponent) # overwrite CMake command
include(SearchInstalledSoftware) include(SearchInstalledSoftware)
include(ThirdPartyLibUtilities) include(ThirdPartyLibUtilities)
...@@ -80,7 +80,7 @@ if(BORNAGAIN_COVERAGE) ...@@ -80,7 +80,7 @@ if(BORNAGAIN_COVERAGE)
include(SetupCoverage) include(SetupCoverage)
endif() endif()
#--- Recurse into the given subdirectories --- # recurse into the given subdirectories
if(BORNAGAIN_USERMANUAL) if(BORNAGAIN_USERMANUAL)
add_subdirectory(Doc/UserManual) add_subdirectory(Doc/UserManual)
endif() endif()
...@@ -98,10 +98,15 @@ if(BORNAGAIN_GUI) ...@@ -98,10 +98,15 @@ if(BORNAGAIN_GUI)
add_subdirectory(GUI) add_subdirectory(GUI)
endif() endif()
# build OpenMPI test executable
if(BORNAGAIN_OPENMPI)
add_subdirectory(dev-tools/openmpi/mpitest)
endif()
add_subdirectory(Tests/UnitTests) add_subdirectory(Tests/UnitTests)
add_subdirectory(Tests/Functional) # functional tests (ctest) add_subdirectory(Tests/Functional) # functional tests (ctest)
add_subdirectory(cmake/bornagain) # trick to print an after-install message add_subdirectory(cmake/bornagain) # trick to print an after-install message
#--- Make package targets --- # make package targets
include(BornAgainCPack) include(BornAgainCPack)
# Finds BornAgain instalation # Finds BornAgain installation
# It defines: # It defines:
# BORNAGAIN_INCLUDE_DIR PATH to the include directory # BORNAGAIN_INCLUDE_DIR PATH to the include directory
# BORNAGAIN_LIBRARIES BornAgain libraries # BORNAGAIN_LIBRARIES BornAgain libraries
......
project(batest)
add_executable(batest batest.cpp)
# path to the cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
# Find libraries
message(STATUS "Configuring with OpenMPI support")
find_package(MPI REQUIRED)
# --- Eigen3 ---
#find_package(Eigen3 3.1.0 REQUIRED)
set(EIGEN3_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../../../ThirdParty/eigen3)
# --- 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}
${MPI_INCLUDE_PATH}
)
target_link_libraries(batest
${Boost_LIBRARIES}
${BORNAGAIN_LIBRARIES}
${ROOT_LIBRARIES}
${MPI_LIBRARIES}
)
#include <iostream>
#include "SimulationFactory.h"
#include "IntensityDataFunctions.h"
#include <mpi.h>
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
std::cout << "Hello World" << std::endl;
SimulationFactory sim_registry;
Simulation *simulation = sim_registry.createItem("isgisaxs01");
simulation->runOMPISimulation();
// check
int world_size(0), world_rank(0);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
if(world_rank ==0) {
OutputData<double> *result = simulation->getOutputData()->clone();
simulation->runSimulation();
OutputData<double> *reference = simulation->getOutputData()->clone();
double diff = OutputDataFunctions::GetDifference(*result,*reference);
std::cout << " Difference:" << diff << std::endl;
}
MPI_Finalize();
return 0;
}
# 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()
# - 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)
# - 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()
...@@ -16,5 +16,3 @@ find_package(MPI REQUIRED) ...@@ -16,5 +16,3 @@ find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH}) include_directories(${MPI_INCLUDE_PATH})
target_link_libraries(helloworld ${MPI_LIBRARIES}) target_link_libraries(helloworld ${MPI_LIBRARIES})
#include <mpi.h> #include <mpi.h>
#include <cstdio>
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Initialize the MPI environment // Initialize the MPI environment
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
// Get the number of processes // Get the number of processes
int world_size; int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size); MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process // Get the rank of the process
int world_rank; int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &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);
// Finalize the MPI environment.
MPI_Finalize();
}
// 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);
// Finalize the MPI environment.
MPI_Finalize();
}
set(executable_name MPITest)
add_executable(${executable_name} mpitest.cpp)
# Find libraries
message(STATUS "Configuring with OpenMPI support")
find_package(MPI REQUIRED)
set(CMAKE_C_COMPILER mpicc)
set(CMAKE_CXX_COMPILER mpic++)
# BornAgain
target_link_libraries(${executable_name} ${BornAgainCore_LIBRARY})
include_directories(
${EIGEN3_INCLUDE_DIR}
${BornAgainCore_INCLUDE_DIRS}
${MPI_INCLUDE_PATH}
)
target_link_libraries(${executable_name}
${BornAgainCore_LIBRARY}
${MPI_LIBRARIES}
)
#include <iostream>
#include "MultiLayer.h"
#include "SampleBuilderFactory.h"
#include "SimulationFactory.h"
#include "IntensityDataFunctions.h"
#include <mpi.h>
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);
int world_size(0), world_rank(0);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
std::cout << "MPI world size: " << world_size << std::endl;
std::cout << "MPI world rank: " << world_rank << std::endl;
std::cout << std::endl;
SimulationFactory sim_factory;
Simulation *p_simulation = sim_factory.createItem("BasicGISAS");
SampleBuilderFactory sample_factory;
const std::unique_ptr<MultiLayer> P_sample(
sample_factory.createSample("CylindersInDWBABuilder"));
p_simulation->setSample(*P_sample);
std::cout << "Running a MPI simulation..." << std::endl;
p_simulation->runOMPISimulation();
if(world_rank ==0) {
auto result = p_simulation->result();
std::cout << "Running normal simulation..." << std::endl;
p_simulation->runSimulation();
auto reference = p_simulation->result();
double diff = IntensityDataFunctions::RelativeDifference(result, reference);
std::cout << "Difference: " << diff << std::endl;
}
MPI_Finalize();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment