diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d144ea55022784eb8a1155445b348054bba7d2..6fc6e1673371ff3e43d7d55ae2d4891d26babe7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ if(GIT_FOUND) message("git found: ${GIT_EXECUTABLE}") endif() +FIND_PACKAGE(MPI REQUIRED) + MESSAGE(STATUS "lib4neuro CMake starting...") MESSAGE(STATUS "Using CMake ${CMAKE_VERSION}") @@ -25,6 +27,7 @@ MESSAGE(STATUS "Using CMake ${CMAKE_VERSION}") # Compile for profiling with GProf # - binaries need to be run to create gmon.out file and # 'gprof' command is run subsequently! +#TODO create 'profiling' user parameter #ADD_COMPILE_OPTIONS(-pg) #ADD_LINK_OPTIONS(-pg) @@ -95,7 +98,7 @@ ENDIF() SET(CMAKE_CXX_STANDARD 17) SET(BOOST_TOOLSET "") IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost -parallel") SET(BOOST_TOOLSET --toolset=intel) ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /bigobj") @@ -153,6 +156,15 @@ ELSEIF("${DEPENDENCIES_LINK_TYPE}" STREQUAL "shared") SET(LIB_SUFFIX "so") ENDIF() +#-------------# +# Find OpenMP # +#-------------# +MESSAGE("Looking for OpenMP support...") +FIND_PACKAGE(OpenMP) +IF(OpenMP_FOUND) + ADD_COMPILE_OPTIONS(${OpenMP_CXX_FLAGS}) +ENDIF() + #-------------------------# # Find external libraries # #-------------------------# diff --git a/build_scripts/linux/linux_gcc_build_x64_release_local.sh b/build_scripts/linux/linux_gcc_build_x64_release_local.sh index 7154b57de7a084b3f2328b2cb62afe72f65719ae..bf9e623420796c7a72b5f37e410ab9c58d75e736 100755 --- a/build_scripts/linux/linux_gcc_build_x64_release_local.sh +++ b/build_scripts/linux/linux_gcc_build_x64_release_local.sh @@ -10,7 +10,7 @@ export LIB4NEURO_INCLUDE_DIR=${PWD}/../../include BUILD_EXAMPLES=yes # Should we build the unit-tests? (yes/no) -BUILD_TESTS=yes +BUILD_TESTS=no # Should we rebuild BOOST? (yes/no) #REBUILD_BOOST=yes @@ -20,6 +20,8 @@ BUILD_LIB=yes # C++ compiler CXX_COMPILER="g++" C_COMPILER="gcc" +CXX_COMPILER="mpicxx" +C_COMPILER="mpicc" #**********************DO NOT CHANGE BEYOND THIS LINE**************************************** if [ -z ${DEPENDENCIES_LINK_TYPE} ]; then DEPENDENCIES_LINK_TYPE=static; fi diff --git a/build_scripts/load_salomon_modules.inc b/build_scripts/load_salomon_modules.inc index 28b2350062acebaa91143238eb093c20f93d3e2a..dff490255165b979328ba6f54e185e88b6d7f4d6 100644 --- a/build_scripts/load_salomon_modules.inc +++ b/build_scripts/load_salomon_modules.inc @@ -4,6 +4,7 @@ ml GCCcore/9.1.0 ml Armadillo ml Boost ml OpenBLAS +ml OpenMPI/2.1.5-GCC-9.1.0-2.32 export GIT_EXEC=/apps/all/git/2.8.0/libexec/git-core/git diff --git a/include/4neuro.h b/include/4neuro.h index 09f1b997e26a83877b64a7cedb337f629e9640df..1dee0f40421e3300a90e029fcafe3e059c342ef4 100644 --- a/include/4neuro.h +++ b/include/4neuro.h @@ -1,8 +1,15 @@ + #ifndef INC_4NEURO_4NEURO_H #define INC_4NEURO_4NEURO_H //TODO make only public interface visible +#include "../src/constants.h" +#include "../src/message.h" +#include "../src/settings.h" +#include "../src/exceptions.h" +#include "../src/mpi_wrapper.h" + #include "../src/DataSet/DataSet.h" #include "../src/Network/NeuralNetwork.h" #include "../src/Network/NeuralNetworkSum.h" @@ -26,12 +33,14 @@ #include "../src/LearningMethods/GradientDescentSingleItem.h" #include "../src/LearningMethods/LearningSequence.h" #include "../src/LearningMethods/LevenbergMarquardt.h" +#include "../src/LearningMethods/LazyLearning.h" #include "../src/LearningMethods/RandomSolution.h" #include "../src/Reader/CSVReader.h" #include "../src/Reader/XYZReader.h" #include "../src/CrossValidator/CrossValidator.h" -#include "../src/constants.h" #include "../src/Coordinates/coordinates.h" +#include "../src/LearningMethods/NelderMead.h" +#include "../src/SymmetryFunction/ACSFParametersOptimizer.h" // Abbreviate lib4neuro namespace to l4n namespace l4n = lib4neuro; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9d0642ef2ebee2d745ad5676726eaf5573e915f..5602cd3fc8a562d8165b8a3f5cc59ef5c1312c9b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,7 @@ IF("${BUILD_LIB}" STREQUAL "yes") LearningMethods/GradientDescent.cpp LearningMethods/LevenbergMarquardt.cpp LearningMethods/GradientDescentBB.cpp + LearningMethods/LazyLearning.cpp DataSet/DataSet.cpp ErrorFunction/ErrorFunctions.cpp Solvers/DESolver.cpp @@ -119,6 +120,9 @@ IF("${BUILD_LIB}" STREQUAL "yes") Reader/XYZReader.cpp Reader/Reader.cpp Coordinates/coordinates.cpp + LearningMethods/NelderMead.cpp + SymmetryFunction/ACSFParametersOptimizer.cpp + mpi_wrapper.cpp ) # Detect Threading library @@ -144,6 +148,7 @@ IF("${BUILD_LIB}" STREQUAL "yes") ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORT} + ${OpenMP_CXX_LIBRARIES} ) TARGET_INCLUDE_DIRECTORIES( diff --git a/src/Network/NeuralNetwork.cpp b/src/Network/NeuralNetwork.cpp index 9a94bb54c0e91eefff4586d9f5e5199d1b649246..0ff6a44595e556c5c2f08f1781f4294ed4734af0 100644 --- a/src/Network/NeuralNetwork.cpp +++ b/src/Network/NeuralNetwork.cpp @@ -13,9 +13,12 @@ #include "NeuralNetworkSerialization.h" #include "exceptions.h" +#include "../mpi_wrapper.h" + + namespace lib4neuro { - NeuralNetwork::NeuralNetwork() { + NeuralNetwork::NeuralNetwork() { this->delete_weights = true; this->delete_biases = true; diff --git a/src/Network/NeuralNetwork.h b/src/Network/NeuralNetwork.h index f6c1b157a1c8605b17679e185df1a5b30c883194..303e5f67affdc7f57b298e6016e83602eebed172 100644 --- a/src/Network/NeuralNetwork.h +++ b/src/Network/NeuralNetwork.h @@ -494,6 +494,10 @@ namespace lib4neuro { //TODO WHY IS THIS HERE? LIB4NEURO_API void set_normalization_strategy_instance(NormalizationStrategy* ns); + LIB4NEURO_API size_t get_input_neurons_number(); + + LIB4NEURO_API size_t get_output_neurons_number(); + }; // class NeuralNetwork class FullyConnectedFFN : public NeuralNetwork { diff --git a/src/message.h b/src/message.h index ea134969c8184d2b16e49a07747602947f82b150..d292ebf52eb7e02a7abbe3fff14bdc132656fdbe 100644 --- a/src/message.h +++ b/src/message.h @@ -2,18 +2,20 @@ #ifndef PROJECT_MESSAGE_H #define PROJECT_MESSAGE_H +#include "mpi_wrapper.h" + #include <cassert> #include <iomanip> #define COL_WIDTH 20 #define R_ALIGN std::setw(COL_WIDTH) << std::right -#define COUT_INFO(inp) std::cout << std::flush << std::fixed << std::setprecision(12) << "INFO: " << inp << std::flush +#define COUT_INFO(inp) if(lib4neuro::mpi_rank == 0) { std::cout << std::flush << std::fixed << std::setprecision(12) << "INFO: " << inp << std::endl << std::flush; } #ifdef L4N_DEBUG -#define COUT_DEBUG(inp) assert(std::cerr << std::flush << std::fixed << std::setprecision(12) << "DEBUG: " << inp << std::flush) +#define COUT_DEBUG(inp) if(lib4neuro::mpi_rank == 0) { assert(std::cerr << std::flush << std::fixed << std::setprecision(12) << "DEBUG: " << inp << std::endl << std::flush); } -#define WRITE_TO_OFS_DEBUG(ofs, msg) { if(ofs && ofs->is_open())\ +#define WRITE_TO_OFS_DEBUG(ofs, msg) { if(ofs && ofs->is_open() && lib4neuro::mpi_rank == 0)\ *ofs << std::fixed << std::setprecision(12) << "DEBUG: " << msg;\ } #else diff --git a/src/mpi_wrapper.cpp b/src/mpi_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7bf1378d968b8ea021a35ecee9c867bc8213bdd --- /dev/null +++ b/src/mpi_wrapper.cpp @@ -0,0 +1,7 @@ +#include "mpi_wrapper.h" + +namespace lib4neuro{ + int mpi_rank = 0; + int mpi_nranks = 1; + MPI_Comm mpi_active_comm = MPI_COMM_WORLD; +} diff --git a/src/mpi_wrapper.h b/src/mpi_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..14f25d2fe0192902aabd0bc851796985487f022b --- /dev/null +++ b/src/mpi_wrapper.h @@ -0,0 +1,17 @@ + +#ifndef INC_4NEURO_MPIWRAPPER_H +#define INC_4NEURO_MPIWRAPPER_H + +#include <mpi.h> + +namespace lib4neuro{ + extern int mpi_rank; + extern int mpi_nranks; + extern MPI_Comm mpi_active_comm; +} + +#define MPI_INIT MPI_Init(nullptr, nullptr); MPI_Comm_size( lib4neuro::mpi_active_comm, &lib4neuro::mpi_nranks ); MPI_Comm_rank( lib4neuro::mpi_active_comm, &lib4neuro::mpi_rank ); +#define MPI_FINISH MPI_Finalize( ); + +#endif //INC_4NEURO_MPIWRAPPER_H + diff --git a/src/settings.h b/src/settings.h index c7c72710f841f030381f93281732e13bcd0140fa..f1b5f2a67a932a7a3649531f1fbf5c3af7f75e23 100644 --- a/src/settings.h +++ b/src/settings.h @@ -8,10 +8,6 @@ #ifndef INC_4NEURO_SETTINGS_H #define INC_4NEURO_SETTINGS_H -/** - * If defined, the NN feed-forward will print out whats happening - */ - #ifdef _WINDOWS #define LIB4NEURO_API __declspec(dllexport) #else