diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ba44e88c --- /dev/null +++ b/.gitignore @@ -0,0 +1,688 @@ +# Created by https://www.toptal.com/developers/gitignore/api/clion,intellij,eclipse,sublimetext,cmake,c++,c,cuda,codeblocks,opencv,jetbrains,python,pycharm +# Edit at https://www.toptal.com/developers/gitignore?templates=clion,intellij,eclipse,sublimetext,cmake,c++,c,cuda,codeblocks,opencv,jetbrains,python,pycharm + +# synthetic data for testing +tests/cpp-tests/data-generators/concrete/synthetic_ds +synthetic_ds/ + +# intallation directory +installdir/ + +# R files +.Rhistory +.RData +.RDataTmp +..Rcheck +src/symbols.rds + +# tar.gz files +*.tar.gz + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### CodeBlocks ### +# specific to CodeBlocks IDE +*.layout +*.depend +# generated directories +bin/ +obj/ + +### CUDA ### +*.i +*.ii +*.gpu +*.ptx +*.cubin +*.fatbin + +### Eclipse ### +.metadata +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream + +### JetBrains ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### JetBrains Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream + +### OpenCV ### +#OpenCV for Mac and Linux +#build and release folders +*/CMakeFiles +*/CMakeCache.txt +*/Makefile +*/cmake_install.cmake +.DS_Store + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ +docs/html/ +docs/latex/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +# Sesimic Toolbox Results Specifics +*.trace +*.segy +*.sgy +*.png +*.bin +data/*.segy +data/*.sgy +data/ +.idea/ +*.tar.bz2 +boost**/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..0353252f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,40 @@ +# Changelog + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.1.0](https://github.com/ecrc/ExaGeoStatCPP/releases/tag/1.1.0) - 2024-04-25 +### Added +- Implemented a new changelog. +- Introduced a benchmarking script. +- .gitignore file. +- More examples. +- Add tests for all src files. +- Rcpp support. + +### Fixed +- Resolved issues with MPI installation. +- Fixed the printing of configuration summaries with MPI. +- Automated the process of adding a new kernel. +- Improved packaging of software with CPack. +- Addressed installation issues. +- Fixed bivariate and trivariate kernels functionality. +- Corrected time-space kernel issues. + +### Changed +- Updated the installation process for dependencies. +- Modified the calculation of P for all kernels. +- Adjusted CMake variables. +- Revised the process of finding BLASPP and Catch2 libraries. +- Updated doxygen documentation. +- Split the synthetic generator functions into BitHelper class and Locations generator class. +- Created a Bassel Function helper for kernels. +- Cleaned the code base for better readability. + +### Removed +- Eliminated The non-stationary kernel support. +- Removed FindOpenMP.cmake, FindLAPACKPP.cmake, and FindCuSOLVER.cmake. + +## [1.0.0](https://github.com/ecrc/ExaGeoStatCPP/releases/tag/1.0.0) - 2023-11-12 +### Added +- Integrated all features present in [ExaGeoStat C version](https://github.com/ecrc/exageostat). diff --git a/CMakeLists.txt b/CMakeLists.txt index 6740d8a5..18ce5b92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,10 +8,10 @@ # The project is a parallel high performance unified framework for geographical statistics on manycore systems. # The file sets up variables and finds dependencies required for the project. # It also provides options to enable building tests, building examples, building documentation, and enabling a packaging system for distribution. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah -# @date 2023-01-30 +# @date 2024-02-04 # Set the minimum CMake version required to 3.20 cmake_minimum_required(VERSION 3.20 FATAL_ERROR) @@ -20,16 +20,26 @@ cmake_policy(SET CMP0048 NEW) # Set project options option(USE_CUDA "Use Cuda, if available" false) option(USE_MPI "Use MPI, if available" false) -option(EXAGEOSTAT_BUILD_TESTS "Option to enable building tests" ON) -option(EXAGEOSTAT_BUILD_EXAMPLES "Option to enable building examples" ON) -option(EXAGEOSTAT_BUILD_DOCS "Build documentation in docs directory" ON) -option(EXAGEOSTAT_PACKAGE "Enable a packaging system for distribution" OFF) +option(BUILD_TESTS "Option to enable building tests" OFF) +option(BUILD_HEAVY_TESTS "Option to enable building heavy tests, This may take a lot of time" OFF) +option(BUILD_EXAMPLES "Option to enable building examples" ON) +option(BUILD_DOCS "Build documentation in docs directory" ON) +option(USE_R "Enable the use of R and Rcpp in the project" OFF) +option(CREATE_PACKAGE "Enable a packaging system for distribution" OFF) # Cmake Module Paths set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") +if (${BUILD_SHARED_LIBS}) + set(BLA_STATIC OFF) +else () + set(BLA_STATIC ON) +endif () + # Select toolchain based on whether CUDA is enabled or not if (USE_CUDA) + message("") + message("---------------------------------------- CUDA") # Enable CUDA and include CudaToolchain add_definitions(-DUSE_CUDA=TRUE) enable_language(CUDA) @@ -44,21 +54,19 @@ else () endif () # Project Name and Version -project(exageostatcpp VERSION 1.0.0 DESCRIPTION "ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems.") +project(ExaGeoStatCPP VERSION 1.0.0 DESCRIPTION "ExaGeoStatCPP is a parallel high performance unified framework for geostatistics on manycore systems.") # Show the current version of CMake. message(STATUS "CMAKE VERSION: ${CMAKE_VERSION}") # Enable C++ language enable_language(CXX) - +# Get the current path of the project. add_compile_definitions(PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}/") +# Set kernels path. +add_definitions(-DKERNELS_PATH="${PROJECT_SOURCE_DIR}/inst/include/kernels/concrete/") -add_definitions( - -DLOG_PATH="${PROJECT_SOURCE_DIR}/synthetic_ds/" - -DKERNELS_PATH="${PROJECT_SOURCE_DIR}/inst/include/kernels/concrete/" -) - -# Add all dependencies for ExaGeoStat PP +# ExaGeoStatCPP depends on CUDA +# ------------------------------- if (USE_CUDA) message("-- Build CUDA Support") else () @@ -67,73 +75,74 @@ else () unset(BLA_VENDOR) endif () -# EXAGEOSTAT depends on a MPI +# ExaGeoStatCPP depends on MPI # ------------------------------- if (USE_MPI) + message("") + message("---------------------------------------- MPI") # Enable MPI and include MPI add_definitions(-DUSE_MPI=TRUE) message(STATUS "Trying to find MPI") find_package(MPI REQUIRED) + include_directories(${MPI_INCLUDE_PATH}) + list(APPEND LIBS ${MPI_LIBRARIES}) list(APPEND STARPU_COMPONENT_LIST "MPI") endif () -# EXAGEOSTAT depends on LAPACKE +# ExaGeoStatCPP depends on LAPACKE #----------------------------- +message("") +message("---------------------------------------- LAPACKE") find_package(LAPACKE) list(APPEND LIBS ${LAPACKE_LIBRARIES}) link_directories(${LAPACKE_LIBRARY_DIRS_DEP}) include_directories(${LAPACKE_INCLUDE_DIRS}) -# Check if no path is set for installation -if (NOT EXAGEOSTAT_INSTALL_PREFIX) - message(FATAL_ERROR "Installation path not set! Please use -DEXAGEOSTAT_INSTALL_PREFIX=path/to/install or use ./config.sh") -endif () -# Print installation path of Exageostat. -message(STATUS "Installation path : ${EXAGEOSTAT_INSTALL_PREFIX}") +# Add all dependencies for ExaGeoStatCPP +#----------------------------- + +# Print installation path of ExaGeoStatCPP. +message(STATUS "Installation path : ${CMAKE_INSTALL_PREFIX}") -# EXAGEOSTAT depends on a Hwloc +# ExaGeoStatCPP depends on HWLoc # ------------------------------- include(ImportHwloc) list(APPEND STARPU_COMPONENT_LIST "HWLOC") - string(REPLACE ";" " " STARPU_COMPONENT_STRING "${STARPU_COMPONENT_LIST}") -# EXAGEOSTAT depends on a runtime +# ExaGeoStatCPP depends on StarPU runtime # ------------------------------- include(ImportStarPu) -# EXAGEOSTAT depends on a GSL +# ExaGeoStatCPP depends on GSL # ------------------------------- include(ImportGSL) -# EXAGEOSTAT depends on a NLOPT +# ExaGeoStatCPP depends on NLOPT # ------------------------------- include(ImportNLOPT) -# EXAGEOSTAT depends on HiCMA +# ExaGeoStatCPP depends on HiCMA # ------------------------------- -if (EXAGEOSTAT_USE_HICMA) - add_definitions(-DEXAGEOSTAT_USE_HICMA=TRUE) - message(STATUS "Add Hcore, Dependency needed for HiCMA") - include(ImportHcore) - message(STATUS "Add StarsH, Dependency needed for HiCMA") +if (USE_HICMA) + add_definitions(-DUSE_HICMA=TRUE) + include(ImportHCore) include(ImportStarsH) include(ImportHiCMA) endif () -# EXAGEOSTAT depends on CHAMELEON +# ExaGeoStatCPP depends on Chameleon # ------------------------------- include(ImportChameleon) -# EXAGEOSTAT depends on a LAPACK/BLASPP +# ExaGeoStatCPP depends on LAPACK/BLASPP # ------------------------------- -include(ImportBlasPP) +include(ImportBLASPP) include(ImportLapack) -# EXAGEOSTAT DOCUMENTATIONS -if (EXAGEOSTAT_BUILD_DOCS) +# ExaGeoStatCPP Documentation +if (BUILD_DOCS) find_package(Doxygen) - if (DOXYGEN_FOUND) add_subdirectory("docs") else () @@ -141,12 +150,25 @@ if (EXAGEOSTAT_BUILD_DOCS) endif () endif () -# Include directories for Exageostat-cpp +# Include directories for ExaGeoStatCPP include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inst/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/prerequisites) set(MY_LOGGER_PATH ${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(-DMY_LOGGER_PATH="${CMAKE_CURRENT_SOURCE_DIR}") +if (USE_R) + message("") + message("---------------------------------------- Rcpp") + # Find R and Rcpp using FindR Module + find_package(R REQUIRED) + if (${R_FOUND}) + message(STATUS "Using R technology") + list(APPEND LIBS R) + add_definitions(-DUSING_R) + endif () +endif () + + # Add src Directory to expose added libraries add_subdirectory(src) @@ -158,14 +180,8 @@ target_link_libraries(${PROJECT_NAME}_INTERFACE INTERFACE ${PROJECT_NAME}) # Add linker options to the target target_link_options(${PROJECT_NAME}_INTERFACE INTERFACE "SHELL:-Wl,--whole-archive $ -Wl,--no-whole-archive") -# Install headers -install(TARGETS exageostatcpp - DESTINATION lib/ - PUBLIC_HEADER DESTINATION include/ - ) - # Add tests if enabled -if (${EXAGEOSTAT_BUILD_TESTS}) +if (${BUILD_TESTS}) message(STATUS "Building Tests") include(ImportCatch2) include(Catch) @@ -174,55 +190,85 @@ if (${EXAGEOSTAT_BUILD_TESTS}) enable_testing() endif () +# Add heavy tests if enabled +if (${BUILD_HEAVY_TESTS}) + message(STATUS "Building Heavy Tests") + include(ImportCatch2) + include(Catch) + include(CTest) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/heavy-tests) + enable_testing() + message(STATUS "Building heavy tests will enable examples too") + set(BUILD_EXAMPLES ON) +endif () -if (EXAGEOSTAT_BUILD_EXAMPLES) - message(STATUS "Building Examples is Enabled") +# Add examples if enabled +if (BUILD_EXAMPLES) + message(STATUS "Building Examples is Enabled") add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples) endif () -# Installation actions -install(DIRECTORY include/${PROJECT_NAME} DESTINATION include) +# ExaGeoStatCPP Dependence export messages for users +# ------------------------------- +message(" \n \t ** Configurations of ExaGeoStatCPP and installation of dependence is done successfully ** ") +message("\t - Export the following line to avoid re-install dependencies each time. -") +message("\t ----------------------------------------------------------------------------------------------------------------------------------- ") +message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/CHAMELEON/lib/pkgconfig:$PKG_CONFIG_PATH") +message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/STARPU/lib/pkgconfig:$PKG_CONFIG_PATH") +message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/HWLOC/lib/pkgconfig:$PKG_CONFIG_PATH") +message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/GSL/lib/pkgconfig:$PKG_CONFIG_PATH") +message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/NLOPT/lib/pkgconfig:${CMAKE_INSTALL_PREFIX}/NLOPT/lib64/pkgconfig:$PKG_CONFIG_PATH") +if(USE_HICMA) + message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/STARSH/lib/pkgconfig:$PKG_CONFIG_PATH") + message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/HCORE/lib/pkgconfig:$PKG_CONFIG_PATH") + message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/HICMA/lib/pkgconfig:$PKG_CONFIG_PATH") +endif() +message("\t ----------------------------------------------------------------------------------------------------------------------------------- \n") + +# Installation of ExaGeoStatCPP +install(DIRECTORY inst/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/include) + ## Install cmake find package. include(CMakePackageConfigHelpers) -write_basic_package_version_file("${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY ExactVersion) +write_basic_package_version_file("${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY ExactVersion) install( FILES - "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION lib/cmake/${PROJECT_NAME} + "${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/cmake/${PROJECT_NAME} ) configure_file(${PROJECT_NAME}Config.cmake.in - ${PROJECT_NAME}Config.cmake @ONLY) + ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/${PROJECT_NAME}Config.cmake @ONLY) install( FILES - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION lib/cmake/${PROJECT_NAME} + "${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/${PROJECT_NAME}Config.cmake" + DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/cmake/${PROJECT_NAME} ) install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - DESTINATION lib/cmake/${PROJECT_NAME}/Modules + DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/Modules ) ## Generate pkg-config file configure_file(package.pc.in - lib/pkgconfig/${PROJECT_NAME}.pc @ONLY) + ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/pkgconfig/${PROJECT_NAME}.pc @ONLY) install( FILES - "${PROJECT_BINARY_DIR}/lib/pkgconfig/${PROJECT_NAME}.pc" - DESTINATION lib/pkgconfig/ + "${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/pkgconfig/${PROJECT_NAME}.pc" + DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/pkgconfig/ ) -if (EXAGEOSTAT_PACKAGE) +if (CREATE_PACKAGE) ################## # Release source # ################## set(CPACK_SOURCE_GENERATOR "TGZ") set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md) - set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems. Its abbreviation stands for 'Exascale Geostatistics'.") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ExaGeoStatCPP is a parallel high performance unified framework for geostatistics on manycore systems. Its abbreviation stands for 'Exascale Geostatistics'.") set(CPACK_PACKAGE_VERSION "${${PROJECT_NAME}_VERSION}") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") @@ -230,16 +276,11 @@ if (EXAGEOSTAT_PACKAGE) set(CPACK_PACKAGE_CONTACT "sameh.abdulah@kaust.edu.sa") set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md) set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) - set(CPACK_SOURCE_IGNORE_FILES "bin;.git;.gitmodules;Jenkinsfile") + set(CPACK_SOURCE_IGNORE_FILES "bin;.git;Jenkinsfile") include(CPack) -endif () -message(" \n \t ** Configurations of ExaGeoStat and installation of dependence is done successfully ** ") -message("\t Export the following line to avoid re-install dependencies each time, This line assume that you haven't changed the installation path. ") -message("\t If not, Please change the following paths with your installation path. \n") -message("\t ------------------------------------------------------------------------------------------------------------------------------- ") -message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/CHAMELEON/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/GSL/lib/pkgconfig:$PKG_CONFIG_PATH") -message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/HCORE/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/HICMA/lib/pkgconfig:$PKG_CONFIG_PATH") -message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/HWLOC/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/NLOPT/lib64/pkgconfig:$PKG_CONFIG_PATH") -message("\t export PKG_CONFIG_PATH=${EXAGEOSTAT_INSTALL_PREFIX}/STARPU/lib/pkgconfig:${EXAGEOSTAT_INSTALL_PREFIX}/STARSH/lib/pkgconfig:$PKG_CONFIG_PATH") -message("\t ------------------------------------------------------------------------------------------------------------------------------- \n") + message("\t - Export the following line if you want to use ExaGeoStatCPP in another software. -") + message("\t ----------------------------------------------------------------------------------------------------------------------------------------------------- ") + message("\t export PKG_CONFIG_PATH=${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/pkgconfig:$PKG_CONFIG_PATH") + message("\t ----------------------------------------------------------------------------------------------------------------------------------------------------- ") +endif () \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8b28557..f1cacec5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,6 +7,7 @@ Contributing to ExaGeoStatCPP - [Developing new features](#developing-new-features) - [Developing bug fixes](#developing-bug-fixes) - [Creating pull requests](#creating-pull-requests) +- [Adding new Kernel](#adding-new-kernel) - [Tests](#tests) Synopsis @@ -260,10 +261,12 @@ To add a new kernel, you need to follow these steps. 1. Place your kernel header file in the inst/include/kernels/concrete directory. The file name should match the kernel's name. For instance, if your header file is named UnivariateMaternStationary.hpp, it can be invoked using either univariate_matern_stationary or UnivariateMaternStationary. The naming linkage is handled automatically, so there's no additional setup required on your part. -2. Derive from the base class located in kernel.hpp and implement the necessary functions. +2. Derive from the base class located in Kernel.hpp and implement the necessary functions. 3. Ensure your kernel includes all the requisite functions that adhere to the established naming conventions found in other kernels. This will allow for proper support and integration of your new kernel. +4. Test your kernel, create a test file for your kernel in tests/cpp-tests/kernels/concrete The file name should match the kernel's name. Also, The naming linkage is handled automatically, so there's no additional setup required on your part. + After finalizing your feature and confirming that your tests run successfully, you are ready to push your branch to GitHub and submit a pull request. diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100755 index 00000000..47ca856f --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,24 @@ +Package: ExaGeoStatCPP +Type: Package +Title: R Package demonstrates the R/C++ Interface for Exascale GeoStatistics software (ExaGeoStat) +Version: 1.1.0 +Date: 2024-01-14 +Author: Mahmoud ElKarargy [aut, cph], Sameh Abdulah [cre, cph], KAUST King Abdullah University of Science and Technology [fnd, cph], Brightskies [cph] +Maintainer: Sameh Abdulah +Description: An R-Interface for the ExaGeoStatCPP software: a parallel high performance unified framework for geostatistics on manycore systems. Its abbreviation stands for Exascale Geostatistics. The framework aims at optimizing the likelihood function for a given spatial data to provide an efficient way to predict missing observations. The framework targets many-core systems: clusters of CPUs and GPUs. +License: GPL (>= 3) +Imports: assertthat (>= 0.2.1), MASS, methods, Rcpp (>= 1.0.9) +Depends: R (>= 3.5.0), assertthat (>= 0.2.1) +RoxygenNote: 7.2.3 +SystemRequirements: C++ (>= 11), CMake (>= 3.2), LAPACKE +NeedsCompilation: yes +OS_type: unix +Authors@R: c( + person("Mahmoud", "ElKarargy", role=c("aut", "cph"), email="mahmoud.elkarargy@brightskiesinc.com"), + person("Sameh", "Abdulah", role=c("cre","cph"), email="sameh.abdulah@kaust.edu.sa"), + person("KAUST", "King Abdullah University of Science and Technology", role=c("fnd","cph")), + person("Brightskies", role=c("cph")) + ) +URL: https://github.com/ecrc/ExaGeoStatCPP +BugReports: https://github.com/ecrc/ExaGeoStatCPP/issues +Encoding: UTF-8 \ No newline at end of file diff --git a/ExaGeoStatCPPConfig.cmake.in b/ExaGeoStatCPPConfig.cmake.in new file mode 100644 index 00000000..410e4c61 --- /dev/null +++ b/ExaGeoStatCPPConfig.cmake.in @@ -0,0 +1,142 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file ExaGeoStatCPPConfig.cmake.in +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-01-30 + + +# relocatable package +@PACKAGE_INIT@ + +# defined since 2.8.3 +if (CMAKE_VERSION VERSION_LESS 2.8.3) + get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) +endif () + +include("${CMAKE_CURRENT_LIST_DIR}/lib/cmake/ExaGeoStatCPPCoreConfig.cmake") +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +if (_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif () + + +# Cmake Module Paths +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${CMAKE_CURRENT_LIST_DIR}/Modules/cmake) + +set(ENV{PKG_CONFIG_PATH} "${_IMPORT_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") +include_directories(${_IMPORT_PREFIX}/include) +link_directories(${_IMPORT_PREFIX}/lib) +set(BLA_PREFER_PKGCONFIG "ON") + +set(EXAGEOSTATCPP_LIBRARIES ExaGeoStatCPP) +set(EXAGEOSTATCPP_LIBRARY_DIRS "${_IMPORT_PREFIX}/lib") +set(EXAGEOSTATCPP_INCLUDE_DIRS "${_IMPORT_PREFIX}/include") + +set(USE_CUDA "@USE_CUDA@") + +# Select toolchain based on whether CUDA is enabled or not +if (USE_CUDA) + # Enable CUDA and include CudaToolchain + add_definitions(-DUSE_CUDA=TRUE) + enable_language(CUDA) + include(toolchains/CudaToolchain) + # Set BLA_VENDOR to NVHPC for CUDA-enabled builds + set(BLA_VENDOR NVHPC) + list(APPEND STARPU_COMPONENT_LIST "CUDA") +else () + message("-- Build x86 Support") + # Include GccToolchain for non-CUDA builds - Gcc + include(toolchains/GccToolchain) +endif () + +add_definitions( + -DLOG_PATH="${PROJECT_SOURCE_DIR}/synthetic_ds/" + -DKERNELS_PATH="${PROJECT_SOURCE_DIR}/inst/include/kernels/concrete/" +) + + +# EXAGEOSTAT depends on a MPI +# ------------------------------- +if (USE_MPI) + # Enable MPI and include MPI + add_definitions(-DUSE_MPI=TRUE) + message(STATUS "Trying to find MPI") + find_package(MPI REQUIRED) + include_directories(${MPI_INCLUDE_PATH}) + list(APPEND LIBS ${MPI_LIBRARIES}) + list(APPEND STARPU_COMPONENT_LIST "MPI") +endif () + +# EXAGEOSTAT depends on LAPACKE +#----------------------------- +find_package(LAPACKE) +list(APPEND LIBS ${LAPACKE_LIBRARIES}) +link_directories(${LAPACKE_LIBRARY_DIRS_DEP}) +include_directories(${LAPACKE_INCLUDE_DIRS}) + + +# EXAGEOSTAT depends on a Hwloc +# ------------------------------- +include(ImportHwloc) +list(APPEND STARPU_COMPONENT_LIST "HWLOC") + +string(REPLACE ";" " " STARPU_COMPONENT_STRING "${STARPU_COMPONENT_LIST}") + +# EXAGEOSTAT depends on a runtime +# ------------------------------- +include(ImportStarPu) + +# EXAGEOSTAT depends on a GSL +# ------------------------------- +include(ImportGSL) + +# EXAGEOSTAT depends on a NLOPT +# ------------------------------- +include(ImportNLOPT) + + +# EXAGEOSTAT depends on HiCMA +# ------------------------------- +if (USE_HICMA) + add_definitions(-DUSE_HICMA=TRUE) + message(STATUS "Add Hcore, Dependency needed for HiCMA") + include(ImportHCore) + message(STATUS "Add StarsH, Dependency needed for HiCMA") + include(ImportStarsH) + include(ImportHiCMA) +endif () + +# EXAGEOSTAT depends on CHAMELEON +# ------------------------------- +include(ImportChameleon) + +# EXAGEOSTAT depends on a LAPACK/BLASPP +# ------------------------------- +include(ImportBLASPP) +include(ImportLapack) + +# Add all dependencies for ExaGeoStatCPP +if (USE_CUDA) + message("-- Build CUDA Support") +else () + message("-- Build x86 Support") + set(gpu_backend CACHE STRING "none" FORCE) + unset(BLA_VENDOR) +endif () + +find_package_handle_standard_args(ExaGeoStatCPP + NAME_MISMATCHED + REQUIRED_VARS EXAGEOSTATCPP_INCLUDE_DIRS EXAGEOSTATCPP_LIBRARY_DIRS EXAGEOSTATCPP_LIBRARIES + VERSION_VAR EXAGEOSTATCPP_VERSION + ) + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) +if (CMAKE_VERSION VERSION_LESS 2.8.3) + set(CMAKE_CURRENT_LIST_DIR) +endif () diff --git a/Jenkinsfile b/Jenkinsfile index 297d51c2..bd84a4de 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,14 +20,14 @@ pipeline { module purge module load gcc/10.2.0 module load cmake/3.21.2 + module load doxygen/1.8.20 #################################################### # BLAS/LAPACK #################################################### module load mkl/2020.0.166 #################################################### - set -x - ./config.sh -t -e + ./configure -t -e ./clean_build.sh ''' } @@ -43,6 +43,7 @@ pipeline { module purge module load gcc/10.2.0 module load cmake/3.21.2 + module load doxygen/1.8.20 #################################################### # BLAS/LAPACK #################################################### @@ -61,14 +62,14 @@ pipeline { module purge module load gcc/10.2.0 module load cmake/3.21.2 + module load doxygen/1.8.20 #################################################### # BLAS/LAPACK #################################################### module load mkl/2020.0.166 #################################################### - set -x - ./config.sh -t -e -H + ./configure -t -e -H ./clean_build.sh ''' } @@ -84,11 +85,11 @@ pipeline { module purge module load gcc/10.2.0 module load cmake/3.21.2 + module load doxygen/1.8.20 #################################################### # BLAS/LAPACK #################################################### module load mkl/2020.0.166 - module load gsl/2.6-gcc-10.2.0 cd bin/ ctest --no-compress-output --verbose ''' @@ -101,12 +102,14 @@ pipeline { module purge module load gcc/10.2.0 module load cmake/3.21.2 + module load doxygen/1.8.20 #################################################### # BLAS/LAPACK #################################################### module load mkl/2020.0.166 - module load gsl/2.6-gcc-10.2.0 - ./config.sh -t -e + #################################################### + + ./configure -e ./clean_build.sh cd bin make docs diff --git a/LICENSE b/LICENSE index 0808c82b..bcfd34e7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2017-2023, King Abdullah University of Science and Technology +Copyright (c) 2017-2024, King Abdullah University of Science and Technology All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 00000000..7f899c19 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +useDynLib(ExaGeoStatCPP, .registration=TRUE) +exportPattern("^[[:alpha:]]+") +import(methods, Rcpp) \ No newline at end of file diff --git a/R/ExaGeoStatCPP.R b/R/ExaGeoStatCPP.R new file mode 100755 index 00000000..c2ac7275 --- /dev/null +++ b/R/ExaGeoStatCPP.R @@ -0,0 +1 @@ +loadModule("ExaGeoStatCPP", TRUE) diff --git a/README.md b/README.md index b66daad7..66a29c8f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -What is ExaGeoStat? -================ +# ExaGeoStat The **Exascale GeoStatistics** project (ExaGeoStat) is a parallel high-performance unified framework for computational geostatistics on many-core systems. The project aims to optimize the likelihood function for a given spatial data to @@ -9,19 +8,19 @@ from commodity x86 to GPU accelerator-based shared and distributed-memory system tackle computationally challenging scientific problems at large-scale while abstracting the hardware complexity through state-of-the-art high-performance linear algebra software libraries. - -What is ExaGeoStatCPP? -==================== +### ExaGeoStatCPP ExaGeoStatCPP is a C++ API for ExaGeoStat that aims to offer a user-friendly and efficient API for C++ developers, essentially maintaining traditional practices and embracing contemporary C++ elements like namespaces, templates, and exceptions to enhance functionality. +### ExaGeoStatR : R Interface of ExaGeoStat +R is a powerful and versatile tool for scientific computing, offering a wide range of statistical and graphical +techniques, strong community support, and the flexibility to integrate with other programming languages. +Its open-source nature and extensive package ecosystem make it an invaluable resource for researchers and data scientists. +Therefore, we decided to create ExaGeoStatR: An interface for functionalities provided by ExaGeoStatCPP to make use of R's various benefits. -Vision of ExaGeoStat/ExaGeoStatCPP -================= - +### Vision of ExaGeoStat/ExaGeoStatCPP The ExaGeoStat/ExaGeoStatCPP project is a collaboration between the KAUST Spatial Statistics group and the Extreme Computing Research -Center (ECRC). Its contribution lies not in a new algorithm nor a new dataset, -but in demonstrating the routine use of the larger datasets becoming available to geospatial +Center (ECRC). Lies not in a new algorithm nor a new dataset, but in demonstrating the routine use of the larger datasets becoming available to geospatial statisticians, thanks to the implementation of state-of-the-art statistical algorithms on High Performance Computing (HPC) hardware. @@ -54,108 +53,93 @@ This low-rank matrix approximation permits the exploitation of the data sparsity numerical accuracy. This further expands practical problem sizes for statisticians with modest computational resources. +## Installation -Current Version of ExaGeoStatCPP: 1.0.0 -====================== -Operations: - -1. (Data Generation): Generating large geospatial synthetic datasets using dense, Diagonal Super-Tile (DST) and Tile Low-Rank (TLR) approximation techniques. -2. (Data Modeling): Modeling large geospatial datasets on dense, Diagonal Super-Tile (DST) and Tile Low-Rank (TLR) approximation techniques through the Maximum likelihood Estimation (MLE) operation. -3. (Data Prediction): Predicting missing measurements on given locations using dense, Diagonal Super-Tile (DST), and Tile Low-Rank (TLR) approximation techniques. -4. (MLOE/MMOM): Computing the Mean Loss of Efficiency (MLOE), Mean Misspecification of the Mean Square Error (MMOM), and Root mean square MOM (RMOM) to describe the prediction performance over the whole observation region. -5. (Fisher Information Matrix (FIM)): Quantifying the information content that a variable x carries about a parameter $\theta$ within a Gaussian distribution. - -Supported Covariance Functions: -====================== - -1. Univariate Matérn (Gaussian/Stationary) -2. Univariate Matérn with Nugget (Gaussian/Stationary) -3. Flexible Bivariate Matérn (Gaussian/Stationary) -4. Parsimonious Bivariate Matérn (Gaussian/Stationary) -5. Parsimonious trivariate Matérn (Gaussian/Stationary) -6. Univariate Space/Time Matérn (Gaussian/Stationary) -7. Bivariate Space/Time Matérn (Gaussian/Stationary) -8. Tukey g-and-h Univariate Matérn (non-Gaussian/Stationary) -9. Tukey g-and-h Univariate Power Exponential (non-Gaussian/Stationary) - -Programming models: - -1. MPI -2. Task-based programming models - -External libraries: - -1. NLOPT [https://nlopt.readthedocs.io/en/latest/](https://nlopt.readthedocs.io/en/latest/) -2. GSL [https://www.gnu.org/software/gsl/](https://www.gnu.org/software/gsl/) -3. HWLOC [https://www.open-mpi.org/projects/hwloc/](https://www.open-mpi.org/projects/hwloc/) -4. StarPU dynamic runtime system [https://starpu.gitlabpages.inria.fr/](https://starpu.gitlabpages.inria.fr/) -5. HCORE [https://github.com/ecrc/hcore](https://github.com/ecrc/hcore) -6. HiCMA [https://github.com/ecrc/hicma](https://github.com/ecrc/hicma) -7. Stars-H [https://github.com/ecrc/stars-h](https://github.com/ecrc/stars-h) -8. Chameleon [https://gitlab.inria.fr/solverstack/chameleon](https://gitlab.inria.fr/solverstack/chameleon) - -Project Hierarchy --------------------- - -* **```cmake```** A directory contains essential CMake modules that facilitate the importation and location of required dependencies. -* **```docs```** A directory contains all the necessary documents. -* **```examples```** A directory contains a comprehensive collection of demo code that illustrates the framework's application and demonstrates its features and capabilities. -* **```inst```** A directory contains all the system's header files, mirroring the structure of the src directory. -* **```prerequisites```** A directory contains all the necessary prerequisites for the project and default scripts for their installation. -* **```src```** A directory contains all the source files. -* **```tests```** A directory contains all the test files and follows the same structure as the src folder. -* **```clean_build.sh```** A script is designed to compile the software tests once all dependencies are installed, and it is set to build everything by default. -* **```CMakeLists.txt```** The top-level CMake file to configure the build system. -* **```config.sh```** A Script used to generate the building system inside a 'bin' directory. - -Installation -============ - -Installation requires at least **CMake of version 3.2**. to build ExaGeoStatCPP, -please follow these instructions: - -1. Get from git repository +> Note: Installation requires at least **CMake of version 3.2**. to build ExaGeoStatCPP. - git clone git@github.com:ecrc/exageostatcpp +### C++ source code installation +To install the `ExaGeoStat` project locally, run the following commands in your terminal: - or +1. Clone the project from the remote gitHub repository into your local machine using the following command + ```bash + git clone https://github.com/ecrc/ExaGeoStatCPP.git + ``` - git clone https://github.com/ecrc/exageostatcpp +2. Change your current directory by getting into the `ExaGeoStatCPP` project directory + ```bash + cd ExaGeoStatCPP + ``` -2. Go into the ExaGeoStatCPP folder +3. Run `configure` script with the flag `-h` for help, to know the supported options and their corresponding flags. + ```bash + ./configure -h + ``` - cd exageostatcpp +4. Run `clean_build.sh` script with the flag `-h` for help, to know the needed arguments to run with your specific options. + ```bash + ./clean_build.sh -h + ``` -3. Run help of config.sh to know the needed arguments to run with your specific options. - - ./config.sh --h - or check user manual. - -4. Run help of clean_build.sh to know the needed arguments to run with your specific options. - - ./clean_build.sh -h - -10. Export the installation paths of the dependencies, e.g., - - export PKG_CONFIG_PATH=$PWD/installdir/_deps/DEPENDENCY_NAME/lib/pkgconfig:$PKG_CONFIG_PATH - - to your .bashrc file. +5. Export the installation paths of the dependencies to your `.bashrc` file, e.g. + ```bash + export PKG_CONFIG_PATH=$PWD/installdir/_deps/DEPENDENCY_NAME/lib/pkgconfig:$PKG_CONFIG_PATH + ``` Now, you can use the pkg-config executable to collect compiler and linker flags for -EXAGEOSTATCPP. - -Using ExaGeoStatCPP -============ -Please refer to **```USER_MANUAL```** for detailed instructions. -Please take a look at the end-to-end examples as a reference for using all the operations. - -Contribute -======= - -[Contribution Guidelines](CONTRIBUTING.md) - -References -========== +ExaGeoStatCPP. + +### R package installation +1. Open the R prompt window by simply running `R` command in the terminal, inside the prompt, we will install needed packages by running the following commands: + ```R + install.packages(Rcpp) + install.packages("assert") + ``` + +2. close the R prompt and return to the terminal. Run the following command, make sure your current path is the ExaGeoStat project directory + + ```commandline + R CMD INSTALL . --configure-args="-r" + ``` + +> For more detailed information on installing ExaGeoStat with different configurations and enabling technologies such as CUDA, MPI, R, etc., please refer to the [User Manual](USER_MANUAL.md) + + +## Usage +#### C++ Example +```C++ +int main(int argc, char **argv) { + + // Create a new configurations object. + Configurations configurations; + // Initialize the arguments with the provided command line arguments + configurations.InitializeArguments(argc, argv); + // Initialize the ExaGeoStat Hardware + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations, data); + // Prediction module + ExaGeoStat::ExaGeoStatPrediction(configurations, data); + + return 0; +} +``` +### R Example: +```R +hardware <- new(Hardware, computation, ncores, ngpus, p, q) +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension) +estimated_theta <- model_data(data=exageostat_data, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10) +predict_data(train_data=list(x, y, z_measurement), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) +``` + +> Please take a look at the end-to-end examples as a reference for using all the operations. + +## Contributing +Find detailed information on how to contribute to ExaGeoStatCPP [here](CONTRIBUTING.md) + +## References 1. Sameh Abdulah, Hatem Ltaief, Ying Sun, Marc G. Genton, and David E. Keyes. "ExaGeoStat: A high performance unified software for geostatistics on manycore systems." IEEE Transactions on Parallel and Distributed Systems 29, no. 12 ( @@ -190,12 +174,17 @@ References geostatistical modeling and prediction for extreme-scale environmental applications." In 2022 SC22: International Conference for High-Performance Computing, Networking, Storage and Analysis (SC), pp. 13-24. IEEE Computer Society, 2022. (ACM GORDON BELL PRIZE Finalist). - + 9. Sagnik Mondal, Sameh Abdulah, Hatem Ltaief, Ying Sun, Marc G. Genton, and David E. Keyes. "Tile low-rank approximations - of non-Gaussian space and space-time Tukey g-and-h random field likelihoods and predictions on large-scale systems." - Journal of Parallel and Distributed Computing 180 (2023): 104715. - + of non-Gaussian space and space-time Tukey g-and-h random field likelihoods and predictions on large-scale systems." + Journal of Parallel and Distributed Computing 180 (2023): 104715. + 10. Qinglei Cao, Sameh Abdulah, Hatem Ltaief, Marc G. Genton, David E. Keyes, and George Bosilca. "Reducing Data Motion and Energy Consumption of Geospatial Modeling Applications Using Automated Precision Conversion." In 2023 IEEE International Conference - on Cluster Computing (CLUSTER), IEEE, 2023. - + on Cluster Computing (CLUSTER), IEEE, 2023. + +## License +[BSD 3-Clause](LICENSE) + +## Handout +![ExaGeoStatCPP-handout.png](docs/ExaGeoStatCPP-handout.png) \ No newline at end of file diff --git a/USER_MANUAL.md b/USER_MANUAL.md index e8a35059..1ebfec7f 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -1,83 +1,104 @@ -ExaGeoStatCPP User Manual -================ +# ExaGeoStatCPP User Manual + +## Content + +1. [ExaGeoStatCPP v1.1.0](#ExaGeoStatCPP) +2. [Configurations of the software](#configurations) +3. [Building ExaGeoStatCPP](#building) +4. [Arguments](#arguments) +5. [List of Descriptors](#list-of-descriptors) +6. [Supported operations](#supported-operations) +7. [Manuals](#Manuals) +8. [Contributing](#contributing) + +## ExaGeoStatCPP +> Current Version of ExaGeoStatCPP: 1.1.0 +### Supported Operations: +1. (Data Generation): Generating large geospatial synthetic datasets using dense, Diagonal Super-Tile (DST) and Tile Low-Rank (TLR) approximation techniques. +2. (Data Modeling): Modeling large geospatial datasets on dense, DST and TLR approximation techniques through the Maximum likelihood Estimation (MLE) operation. +3. (Data Prediction): Predicting missing measurements on given locations using dense, DST, and TLR approximation techniques. +4. (MLOE/MMOM): Computing the Mean Loss of Efficiency (MLOE), Mean Misspecification of the Mean Square Error (MMOM), and Root mean square MOM (RMOM) to describe the prediction performance over the whole observation region. +5. (Fisher Information Matrix (FIM)): Quantifying the information content that a variable x carries about a parameter $\theta$ within a Gaussian distribution. + +### Supported Covariance Functions: +1. Univariate Matérn (Gaussian/Stationary) +2. Univariate Matérn with Nugget (Gaussian/Stationary) +3. Flexible Bivariate Matérn (Gaussian/Stationary) +4. Parsimonious Bivariate Matérn (Gaussian/Stationary) +5. Parsimonious trivariate Matérn (Gaussian/Stationary) +6. Univariate Space/Time Matérn (Gaussian/Stationary) +7. Bivariate Space/Time Matérn (Gaussian/Stationary) +8. Tukey g-and-h Univariate Matérn (non-Gaussian/Stationary) +9. Tukey g-and-h Univariate Power Exponential (non-Gaussian/Stationary) +> To add your kernel, please refer to [Contribution Guidelines](CONTRIBUTING.md) + +### Programming models: +1. MPI +2. Task-based programming models + +### External libraries: +1. NLOPT [https://nlopt.readthedocs.io/en/latest/](https://nlopt.readthedocs.io/en/latest/) +2. GSL [https://www.gnu.org/software/gsl/](https://www.gnu.org/software/gsl/) +3. HWLOC [https://www.open-mpi.org/projects/hwloc/](https://www.open-mpi.org/projects/hwloc/) +4. StarPU dynamic runtime system [https://starpu.gitlabpages.inria.fr/](https://starpu.gitlabpages.inria.fr/) +5. HCORE [https://github.com/ecrc/hcore](https://github.com/ecrc/hcore) +6. HiCMA [https://github.com/ecrc/hicma](https://github.com/ecrc/hicma) +7. Stars-H [https://github.com/ecrc/stars-h](https://github.com/ecrc/stars-h) +8. Chameleon [https://gitlab.inria.fr/solverstack/chameleon](https://gitlab.inria.fr/solverstack/chameleon) + +### Project Hierarchy + +* **```cmake```** A directory contains essential CMake modules that facilitate the importation and location of required dependencies. +* **```docs```** A directory contains all the necessary documents. +* **```examples```** A directory contains a comprehensive collection of demo code that illustrates the framework's application and demonstrates its features and capabilities. +* **```inst```** A directory contains all the system's header files, mirroring the structure of the src directory. +* **```man```** A directory contains all the R functions documentation. +* **```scripts```** A directory contains benchmarking scripts. +* **```src```** A directory contains all the source files. +* **```tests```** A directory contains all the test files and follows the same structure as the src folder. +* **```clean_build.sh```** A script is designed to compile the software tests once all dependencies are installed, and it is set to build everything by default. +* **```CMakeLists.txt```** The top-level CMake file to configure the build system. +* **```configure```** A Script used to generate the building system inside a 'bin' directory. -# Content - -1. Configurations of the software. -2. Building ExaGeoStatCPP. -3. Supported Covariance kernels. -4. Arguments. -5. List of Descriptors. -6. Supported operations. -7. Contributing ## Configurations -* Run help of config.sh to know the needed arguments to run with your specific options. -```commandline -./config.sh -h -``` -* To Enable support of HiCMA add **```-H```** -* To enable examples add **```-e```** - -* To enable tests add **```-t```** - -* To enable CUDA add **```-c```** - -* To enable MPI add **```-m```** +* Run the help of `configure` to know the needed arguments for your specific options. + ``` bash + ./configure -h + ``` + +* To enable R interface, add `-r` disabled by default. +* To enable support of HiCMA, add `-H` disabled by default. +* To enable examples, add `-e` enabled by default. +* To enable tests, add `-t` disabled by default. +* To enable heavy tests, add `-T` disabled by default. +* To enable CUDA, add `-c` disabled by default. +* To enable MPI, add `-m` disabled by default. +* To enable verbose output, add `-v` disabled by default. +* To change the installation path of the dependencies, use `-i ` the default is project_path/installdir/_deps/ on Unix systems. +* To enable packaging system for distribution, add `-p` disabled by default. +* To enable showing code warnings, add `-w` disabled by default. +* To manually set mkl as blas vendor, add `--use-mkl`. MKL is required as blas vendor and it's automatically detected but in some environments it need to be manually set. -* To enable Verbose add **```-v```** - -* To enable debug mode add **```-d```** - -* To change the installation path of the dependencies use **```-i ```** - -Please be aware that we currently offer support for either HiCMA or Chameleon, or both. ## Building -* Run help of clean_build.sh to know the additional arguments options. -```commandline -./clean_build.sh -h -``` -* Run clean_build.sh to clean, Build and Install the project. -```commandline -./clean_build.sh -``` -* To enable verbose printing, Run the following command. -```commandline -./clean_build.sh -v -``` -* To enable building with a specific number of threads, run the following command. -```commandline -./clean_build.sh -j -``` +* Run the help of `clean_build.sh` to know additional argument options. -Supported Covariance Functions/ Kernels: -====================== - -1. univariate_matern_stationary -2. univariate_exp_non_gaussian -3. univariate_matern_dbeta -4. univariate_matern_ddbeta_beta -5. univariate_matern_ddbeta_nu -6. univariate_matern_ddnu_nu -7. univariate_matern_ddsigma_square -8. univariate_matern_ddsigma_square_beta -9. univariate_matern_ddsigma_square_nu -10. univariate_matern_dnu -11. univariate_matern_dsigma_square -12. univariate_matern_non_gaussian -13. univariate_matern_non_sta -14. univariate_matern_non_stationary -15. univariate_matern_nuggets_stationary -16. univariate_spacetime_matern_stationary -17. bivariate_matern_flexible -18. bivariate_matern_parsimonious -19. bivariate_spacetime_matern_stationary -20. trivariate_matern_parsimonious + ```bash + ./clean_build.sh -h + ``` +* Run clean_build.sh to build the project. + ```bash + ./clean_build.sh + ``` +* To enable the installation of the project, add `-i` disabled by default. +* To enable verbose printing, add `-v` disabled by default. +* To enable building with a specific number of threads, add `-j ` running with maximum number of threads by default. -## Arguments +## Arguments +These are the arguments that you can specify when running any C++ example. * {Mandatory} To set the problem size (N) --N= @@ -87,18 +108,18 @@ Supported Covariance Functions/ Kernels: * {Mandatory} To set the dense tile size in the case of Chameleon --dts= -* {Mandatory} To set the low tile size in case of HiCMA +* {Mandatory} To set the low tile size in case of HiCMA --lts= * {Optional} To set the dimension, the default is 2D --dimension=<2D/3D/ST> -* {Optional} To set the p grid +* {Optional} To set the p grid, the default is 1 - --p_grid= -* {Optional} To set the q grid + --p= +* {Optional} To set the q grid, the default is 1 - --q_grid= + --q= * {Optional} To set the time slot, the default is 1 --time_slot= @@ -107,7 +128,7 @@ Supported Covariance Functions/ Kernels: --computation= * {Optional} To set the precision, the default is double - --precision= + --precision= * {Optional} To set the number of cores, the default is 1 --cores= @@ -135,12 +156,15 @@ Supported Covariance Functions/ Kernels: * {Optional} To set the target theta --ttheta= +* {Optional} To set the estimated theta + + --etheta= * {Optional} To set the seed value, the default is 0 --seed= -* {Optional} To set the run mode value, the default is standard +* {Optional} To set the verbose value, the default is standard - --run_mode= + --verbose= * {Optional} To set the path of log files to be written, the default is ./exageostat-cpp/synthetic_ds/ --log_path= @@ -194,8 +218,6 @@ Supported Covariance Functions/ Kernels: 8. DESCRIPTOR_C12UV : HiCMA descCUV descriptor 9. DESCRIPTOR_C22UV : HiCMA descCUV descriptor - - ## Supported Operations ### Provide Arguments @@ -218,45 +240,115 @@ for setting your arguments: synthetic_data_configurations.SetKernelName("BivariateSpacetimeMaternStationary"); synthetic_data_configurations.SetPrecision(exageostat::common::double); ``` -### Initialize the Hardware +### Initialize and Finalize the Hardware class To use any operations, you must initialize the hardware by selecting the number of CPUs and/or GPUs. ```c++ +// Initialize an instance of the hardware auto hardware = ExaGeoStatHardware(computation, number of cores, number of gpus); + +// Other code goes here + +// Finalize the hardware instance. +hardware.FinalizeHardware() ``` +The subsequent arguments are as follows: -### Synthetic and Real Data + - `computation`: Specifies the computation mode for the solver. + - `number of cores`: Indicates the number of CPU cores to be used for the solver. + - `number of gpus`: Specifies the number of GPUs to be used for the solver. -ExaGeoStatCPP can be used with different types of data, including: -Synthetic data: Synthetic data is generated by the software according to the user arguments. +##### *ExaGeoStat R Interface* +```R +hardware <- new(Hardware, computation, number of cores, number of gpus, p-grid, q-grid); +hardware$finalize_hardware() +``` +First arguement represents the name of the R class that wrapps its correponding C++ class, the rest of arguments are the same as the C++ version + +### Types of Data + +ExaGeoStatCPP can be used with 2 types of data: -Real data: ExaGeoStatCPP can also be used with real data, such as data from satellite imagery or weather sensors. Real data -can be used to train the software to predict the values of new data better. +- Synthetic data i.e. generated by the software according to the user arguments. +- Real data e.g. data from satellite imagery or weather sensors. Real data can be used to train the software to predict the values of new data better. -##### Synthetic Data Generation +#### Using Synthetic Data -After you provide your arguments with the Configurations module, you must do the following two steps: +Here we generate the data to be used by providing the needed arguments with the Configurations module, and then using the following code: ```c++ // Create a new ExaGeoStat data that holds the locations and descriptors data. -ExaGeoStatData data; -// Generate data by passing your arguments through the configurations, hardware, and - container of the data, which will be filled with the newly generated data. -ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, data); +std::unique_ptr> data; + +// Generate data by passing your arguments through the configurations, hardware, +//and container of the data, which will be filled with the newly generated data. +ExaGeoStat::ExaGeoStatLoadData(configurations, data); ``` -##### Real Data +#### Using Real Data -- The Data Path must be passed to Configuration. +Here we use existing data by providing the path to it: - --log_path= -- Then do the following two steps. +- The Data Path must be passed to Configuration + ``` + data_path <- + ``` + +And then using the following code: + +```R +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension, data_path=data_path) +``` + +### Location Getters + +ExaGeoStat support 2D and 3D spatial locations, and therefore we have getters for X, Y and Z coordinates. + +#### X-coordinate Getter ```c++ -// Create a new ExaGeoStat data that holds the locations data and descriptors data. -ExaGeoStatData data; -// Generate data by passing your arguments through the configurations, your hardware and your container of the data which will be filled with the new generated data. -ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, data); +double *locations_x = exageostat_data->GetLocations()->GetLocationX(); +``` + +#### Y-coordinate Getter +```c++ +double *locations_y = exageostat_data->GetLocations()->GetLocationY(); +``` + +#### Z-coordinate Getter +```c++ +double *locations_z = exageostat_data->GetLocations()->GetLocationZ(); +``` + +##### *ExaGeoStat R Interface* +```R +locations <- get_locations(data=exageostat_data) ``` +Returns all the locations values. The subsequent arguments are as follows: + +- `exagostat_data`: pointer to ExaGeoStatData object containing the spatial data. + +#### Descriptive Z Values Getter +This function is used to retrieve descriptive Z values from ExaGeoStat data based on type of descriptor. +```c++ +//in this example, we use a chameleon descriptor. Similar code can be used for hicma descriptor. +DescriptorType descriptor_type = CHAMELEON_DESCRIPTOR; +void *descriptor = exageostat_data->GetDescriptorData()->GetDescriptor(descriptor_type, DESCRIPTOR_Z).chameleon_desc; +double *desc_Z_values = exagostat_data->GetDescriptorData()->GetDescriptorMatrix(descriptor_type, descriptor); +``` +The used variables are as follows: + +- `descriptor_type`: enum denoting the descriptor type,e.g. CHAMELEON_DESCRIPTOR,HICMA_DESCRIPTOR. +- `exagostat_data`: pointer to ExaGeoStatData object containing the spatial data. +- `desc_Z_values`: pointer to descriptor matrix. + +##### *ExaGeoStat R Interface* +```R +desc_Z_values <- get_Z_measurement_vector(data=exageostat_data, type="chameleon") +``` +The subsequent arguments are as follows: + +- `exagostat_data`: pointer to ExaGeoStatData object containing the spatial data. +- `type`: string specifying the type of descriptor value to retrieve. ### Data Modeling @@ -266,36 +358,88 @@ To use data modeling, you have to do this operation. ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, data, z_matrix); ``` + +##### *ExaGeoStat R Interface* +```R +estimated_theta <- model_data(matrix=z_value, x=locations_x, y=locations_y, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10, computation=computation, band=1) +``` +Or +```R +estimated_theta <- model_data(data=exageostat_data, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10) +``` + ### Data Prediction ```c++ //You have to pass your arguments through the configurations, your hardware, and your data. -ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); +ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); +``` + + +##### *ExaGeoStat R Interface* +```R +predict_data(train_data=list(locations_x, locations_y, locations_z, z_value), test_data=list(test_x, test_y, test_z), kernel=kernel, dts=dts, estimated_theta=estimated_theta) ``` ### Fisher Function 1. Pass the fisher arguments to the Configurations. +``` +--fisher +``` - --fisher 2. Call the Data Prediction function. ```c++ // you have to pass your arguments through the configurations, your hardware and your data. -ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); +ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); ``` + + +##### *ExaGeoStat R Interface* +```R +fisher_matrix <- fisher(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) +``` + ### MLOE-MMOM Function 1. Pass the MLOE-MMOM arguments to the Configurations. - --mloe-mmom +``` +--mloe-mmom +``` + 2. Call the Data Prediction function. ```c++ // you have to pass your arguments through the configurations, your hardware and your data. -ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); +ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); ``` + + +##### *ExaGeoStat R Interface* +```R +result_mloe_mmom = mloe_mmom(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta, true_theta=true_theta) +``` + ### IDW Function 1. Pass the IDW arguments to the Configurations. - --idw +``` +--idw +``` + 2. Call the Data Prediction function. ```c++ // you have to pass your arguments through the configurations, your hardware and your data. -ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); -``` \ No newline at end of file +ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); +``` + + +##### *ExaGeoStat R Interface* +```R +idw_error = idw(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta, test_measurements=test_measurements) +``` + +## Manuals +- Find a detailed Manual for R functions in [ExaGeoStatCPP-R-Interface-Manual](docs/ExaGeoStat-R-Interface-Manual.pdf) +- Find a detailed Manual for C++ functions in [ExaGeoStatC-CPP-Manual](docs/ExaGeoStat-CPP-Manual.pdf) +- Doxygen Manual: https://ecrc.github.io/ExaGeoStatCPP + +## Contributing +[Contribution Guidelines](CONTRIBUTING.md) diff --git a/clean_build.sh b/clean_build.sh index 8d56b8a9..3cd86582 100755 --- a/clean_build.sh +++ b/clean_build.sh @@ -1,20 +1,21 @@ -#!/bin/bash -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +#! /bin/sh +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file clean_build.sh # @brief This script cleans and builds a software package called ExaGeoStat. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-01-30 # Define variables. verbose="" num_proc="-j $(nproc)" # Use the number of available processors by default. +installation=0 # Parse command-line arguments. -while getopts "vj:h" opt; do +while getopts "vj:hi" opt; do case $opt in v) verbose="VERBOSE=1" @@ -24,6 +25,9 @@ while getopts "vj:h" opt; do num_proc="-j $OPTARG" echo "Using $OPTARG threads to build" ;; + i) + installation=1 + ;; h) # Print help information and exit. echo "Usage: $(basename "$0") [-v] [-j ] [-h]" @@ -31,8 +35,9 @@ while getopts "vj:h" opt; do echo "" echo "Options:" echo " -v Use verbose output." - echo " -j Build with a specific number of threads." + echo " -i To install the software" echo " -h Show this help message." + echo " -j Build with a specific number of threads." exit 0 ;; *) @@ -50,5 +55,15 @@ cd bin/ || { } # Clean the directory and build the code with the specified options. -make clean -make all $num_proc $verbose \ No newline at end of file +cmake --build . "$num_proc" $verbose + +# Install the software if the -i option is provided. +if [ "$installation" -eq 1 ]; then + cmake --install . +fi + +# Check the value of EXAGEOSTAT_PACKAGE variable in CMakeCache.txt +if grep -q "EXAGEOSTAT_PACKAGE:BOOL=ON" CMakeCache.txt; then + echo "CPack is enabled. Packaging the project." + cpack +fi \ No newline at end of file diff --git a/cmake/FindPkgconfigLibrariesAbsolutePath.cmake b/cmake/FindPkgconfigLibrariesAbsolutePath.cmake index c1c94c1f..5eef4e0b 100644 --- a/cmake/FindPkgconfigLibrariesAbsolutePath.cmake +++ b/cmake/FindPkgconfigLibrariesAbsolutePath.cmake @@ -16,7 +16,7 @@ # Univ. of California Berkeley, # Univ. of Colorado Denver. # -# @version 1.0.0 +# @version 1.1.0 # @author Florent Pruvost # @date 06-04-2018 # diff --git a/cmake/FindR.cmake b/cmake/FindR.cmake new file mode 100644 index 00000000..94806380 --- /dev/null +++ b/cmake/FindR.cmake @@ -0,0 +1,172 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file FindR.cmake +# @brief Find the R and Rcpp library, Set some helpful variables. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @author David Helmy +# @date 2024-01-14 + + +# Usage: +# find_package(R [REQUIRED] [QUIET] ) +# +# It sets the following variables: +# R _FOUND ... true if R and Rcpp is found on the system +# R_LIBRARIES ... full path to R and Rcpp library +# R_INCLUDE_DIRS ... R and Rcpp include directory +# +# The following variables will be checked by the function +# R_ROOT_PATH ... if set, the R libraries are exclusively searched +# under this path +# R_LIB_PATH ... if set, the Rcpp libraries are exclusively searched +# under this path + +if (DEFINED ENV{R_HOME}) + set(R_ROOT_PATH "$ENV{R_HOME}") + +else () + execute_process(COMMAND R RHOME OUTPUT_VARIABLE R_HOME) + string(REGEX REPLACE "\n" "" R_HOME "${R_HOME}") + set(R_ROOT_PATH "${R_HOME}") + +endif () + +if (NOT R_INCLUDE_PATH) + execute_process(COMMAND ${R_ROOT_PATH}/bin/Rscript -e "cat(Sys.getenv('R_INCLUDE_DIR'))" OUTPUT_VARIABLE R_INCLUDE_DIR) + string(REGEX REPLACE "\n" "" R_INCLUDE_DIR "${R_INCLUDE_DIR}") + set(R_INCLUDE_PATH "${R_INCLUDE_DIR}") + message(STATUS "R Include Path : " ${R_INCLUDE_PATH}) +endif () + + +if (NOT RCPP_LIB_PATH) + execute_process( + COMMAND ${R_ROOT_PATH}/bin/Rscript -e "cat(find.package('Rcpp'))" + OUTPUT_VARIABLE RCPP_LIB_PATH + RESULT_VARIABLE RSCRIPT_RESULT + ) + + # Check if the command was successful + if (RSCRIPT_RESULT EQUAL 0) + # Trim whitespace from both ends of the output + string(STRIP ${RCPP_LIB_PATH} RCPP_LIB_PATH) + message(STATUS "RCPP_LIB_PATH: ${RCPP_LIB_PATH}") + else() + message(FATAL_ERROR "Error running Rscript. Exit code: ${RSCRIPT_RESULT}") + endif() +endif () + +message(STATUS "R Home Path : " ${R_ROOT_PATH}) + +if (R_ROOT_PATH) + + if (APPLE) + find_library( + R_DYN_LIB + NAMES "libR.dylib" + PATHS ${R_ROOT_PATH} + PATH_SUFFIXES "lib" "lib64" "bin" + NO_DEFAULT_PATH + ) + + else () + #find libs + find_library( + R_DYN_LIB + NAMES "libR.so" + PATHS ${R_ROOT_PATH} + PATH_SUFFIXES "lib" "lib64" "bin" + NO_DEFAULT_PATH + ) + + endif () + + if (R_DYN_LIB MATCHES R_DYN_LIB-NOTFOUND) + set(R_DYN_LIB "") + message("R is built with no dynamic library support") + endif () + + set(R_LIB + ${R_DYN_LIB} + ) + +else () + error("R is not installed ") +endif (R_ROOT_PATH) + + +if (R_INCLUDE_PATH) + # find includes + find_path( + R_INCLUDE_DIRS + REQUIRED + NAMES "R.h" + PATHS ${R_INCLUDE_PATH} + PATH_SUFFIXES "include" + NO_DEFAULT_PATH + ) +endif () + +if (RCPP_LIB_PATH) + #find libs + find_library( + RCPP_LIB + REQUIRED + NAMES "Rcpp.so" + PATHS ${RCPP_LIB_PATH} + PATH_SUFFIXES "/libs" "/lib64" "/bin" + NO_DEFAULT_PATH + ) + + # find includes + find_path( + RCPP_INCLUDE_DIRS + REQUIRED + NAMES "Rcpp.h" + PATHS ${RCPP_LIB_PATH} + PATH_SUFFIXES "/include" + NO_DEFAULT_PATH + ) + + +else () + message("Rcpp is not installed ...") +endif (RCPP_LIB_PATH) + +set(R_INCLUDE + ${R_INCLUDE} + ${R_INCLUDE_DIRS} + ${RCPP_INCLUDE_DIRS} + ) + +add_library(R INTERFACE IMPORTED) + +if (R_LIB) + set_target_properties(R + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${R_INCLUDE}" + INTERFACE_LINK_LIBRARIES "${R_LIB}" + IMPORTED_LOCATION ${RCPP_LIB} + ) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(R DEFAULT_MSG + R_INCLUDE R_LIB) + + include_directories(${R_INCLUDE}) + mark_as_advanced(R_INCLUDE R_INCLUDE_DIRS RCPP_INCLUDE_DIRS R_LIB RCPP_LIB) + +else () + set_target_properties(R + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${R_INCLUDE}" + IMPORTED_LOCATION ${RCPP_LIB} + ) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(R DEFAULT_MSG + R_INCLUDE) + + include_directories(${R_INCLUDE}) + mark_as_advanced(R_INCLUDE R_INCLUDE_DIRS RCPP_INCLUDE_DIRS RCPP_LIB) +endif () \ No newline at end of file diff --git a/cmake/FindTMG.cmake b/cmake/FindTMG.cmake new file mode 100644 index 00000000..bdf63250 --- /dev/null +++ b/cmake/FindTMG.cmake @@ -0,0 +1,308 @@ +### +# +# @copyright (c) 2009-2014 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2016 Inria. All rights reserved. +# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# @copyright (c) 2022 King Abdullah University of Science and Technology (KAUST). +# All rights reserved. +# +### +# +# - Find TMG include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(TMG +# [REQUIRED] # Fail with error if tmg is not found +# ) +# +# This module finds headers and tmg library. +# Results are reported in variables: +# TMG_FOUND - True if headers and requested libraries were found +# TMG_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# TMG_INCLUDE_DIRS - tmg include directories +# TMG_LIBRARY_DIRS - Link directories for tmg libraries +# TMG_LIBRARIES - tmg component libraries to be linked +# TMG_INCLUDE_DIRS_DEP - tmg + dependencies include directories +# TMG_LIBRARY_DIRS_DEP - tmg + dependencies link directories +# TMG_LIBRARIES_DEP - tmg libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DTMG=path/to/tmg): +# TMG_DIR - Where to find the base directory of tmg +# TMG_INCDIR - Where to find the header files +# TMG_LIBDIR - Where to find the library files +# The module can also look for the following environment variables if paths +# are not given as cmake variable: TMG_DIR, TMG_INCDIR, TMG_LIBDIR + +#============================================================================= +# Copyright 2012-2013 Inria +# Copyright 2012-2013 Emmanuel Agullo +# Copyright 2012-2013 Mathieu Faverge +# Copyright 2012 Cedric Castagnede +# Copyright 2013-2016 Florent Pruvost +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file ECRC-Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of Ecrc, substitute the full +# License text for the above reference.) + + +if (NOT TMG_FOUND) + set(TMG_DIR "" CACHE PATH "Installation directory of TMG library") + if (NOT TMG_FIND_QUIETLY) + message(STATUS "A cache variable, namely TMG_DIR, has been set to specify the install directory of TMG") + endif() +endif() + + +# used to test a TMG function after +get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) +if (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFunctionExists) +else (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFortranFunctionExists) +endif (NOT _LANGUAGES_ MATCHES Fortran) + +# TMG depends on LAPACK anyway, try to find it +if (NOT LAPACK_FOUND) + if(TMG_FIND_REQUIRED) + find_package(LAPACKEXT REQUIRED) + else() + find_package(LAPACKEXT) + endif() +endif() + +# TMG depends on LAPACK +if (LAPACK_FOUND) + + # check if a tmg function exists in the LAPACK lib + set(CMAKE_REQUIRED_LIBRARIES "${LAPACK_LINKER_FLAGS};${LAPACK_LIBRARIES}") + include(CheckFunctionExists) + include(CheckFortranFunctionExists) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlarnv TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlarnv TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + if (TMG_WORKS) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlagsy TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlagsy TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + mark_as_advanced(TMG_WORKS) + endif() + set(CMAKE_REQUIRED_LIBRARIES) + + if(TMG_WORKS) + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg: test with lapack succeeds") + endif() + # test succeeds: TMG is in LAPACK + set(TMG_LIBRARIES "${LAPACK_LIBRARIES}") + if (LAPACK_LIBRARY_DIRS) + set(TMG_LIBRARY_DIRS "${LAPACK_LIBRARY_DIRS}") + endif() + if(LAPACK_INCLUDE_DIRS) + set(TMG_INCLUDE_DIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LINKER_FLAGS) + set(TMG_LINKER_FLAGS "${LAPACK_LINKER_FLAGS}") + endif() + else() + + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg : test with lapack fails") + message(STATUS "Looking for tmg : try to find it elsewhere") + endif() + # test fails: try to find TMG lib exterior to LAPACK + + # Looking for lib tmg + # ------------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_TMG_DIR "$ENV{TMG_DIR}") + set(ENV_TMG_LIBDIR "$ENV{TMG_LIBDIR}") + if(ENV_TMG_LIBDIR) + list(APPEND _lib_env "${ENV_TMG_LIBDIR}") + elseif(ENV_TMG_DIR) + list(APPEND _lib_env "${ENV_TMG_DIR}") + list(APPEND _lib_env "${ENV_TMG_DIR}/lib") + else() + if(WIN32) + string(REPLACE ":" ";" _lib_env "$ENV{LIB}") + else() + if(APPLE) + string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}") + else() + string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}") + endif() + list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}") + list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") + endif() + endif() + list(REMOVE_DUPLICATES _lib_env) + + # Try to find the tmg lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(TMG_LIBDIR) + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${TMG_LIBDIR} ) + else() + if(TMG_DIR) + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${TMG_DIR} + PATH_SUFFIXES lib lib32 lib64 ) + else() + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${_lib_env} ) + endif() + endif() + mark_as_advanced(TMG_tmg_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (TMG_tmg_LIBRARY) + get_filename_component(tmg_lib_path ${TMG_tmg_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(TMG_LIBRARIES "${TMG_tmg_LIBRARY}") + set(TMG_LIBRARY_DIRS "${tmg_lib_path}") + else () + set(TMG_LIBRARIES "TMG_LIBRARIES-NOTFOUND") + set(TMG_LIBRARY_DIRS "TMG_LIBRARY_DIRS-NOTFOUND") + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg -- lib tmg not found") + endif() + endif () + + if (TMG_LIBRARY_DIRS) + list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(TMG_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # TMG + if (TMG_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${TMG_INCLUDE_DIRS}") + endif() + if (TMG_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${TMG_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${TMG_LIBRARIES}") + # LAPACK + if (LAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}") + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + endif() + + # set required libraries for link + set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") + set(CMAKE_REQUIRED_LIBRARIES) + list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}") + foreach(lib_dir ${REQUIRED_LIBDIRS}) + list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}") + endforeach() + list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(TMG_WORKS CACHE) + include(CheckFunctionExists) + include(CheckFortranFunctionExists) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlarnv TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlarnv TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + if (TMG_WORKS) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlagsy TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlagsy TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + mark_as_advanced(TMG_WORKS) + endif() + + if(TMG_WORKS) + # save link with dependencies + set(TMG_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(TMG_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(TMG_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(TMG_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES TMG_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES TMG_LINKER_FLAGS) + else() + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg: test of dlarnv and dlagsy with tmg and lapack libraries fails") + message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}") + message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}") + message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) + endif(TMG_LIBRARIES) + + endif() + +else() + + if(NOT TMG_FIND_QUIETLY) + message(STATUS "TMG requires LAPACK but LAPACK has not been found." + "Please look for LAPACK first.") + endif() + +endif() + +if (TMG_LIBRARIES) + list(GET TMG_LIBRARIES 0 first_lib) + get_filename_component(first_lib_path "${first_lib}" PATH) + if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)") + string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}") + set(TMG_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of TMG library" FORCE) + else() + set(TMG_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of TMG library" FORCE) + endif() +endif() +mark_as_advanced(TMG_DIR) +mark_as_advanced(TMG_DIR_FOUND) + +# check that TMG has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TMG DEFAULT_MSG + TMG_LIBRARIES + TMG_WORKS) diff --git a/cmake/ImportBLAS.cmake b/cmake/ImportBLAS.cmake new file mode 100644 index 00000000..8b2bec5d --- /dev/null +++ b/cmake/ImportBLAS.cmake @@ -0,0 +1,36 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file ImportBLAS.cmake +# @brief This file searches for the BLAS library and includes it if not already included. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-03-12 + +# Set basic configuration variables for the BLAS library. +# 'name' is set to "BLAS", which is the identifier used for the dependency throughout the script. +set(name "BLAS") +# 'tag' specifies the version tag of the BLAS library to fetch, indicating a specific state of the source code in the repository. +set(tag "v0.3.21") +# 'version' specifies the version of the BLAS library. This may be used to ensure compatibility or meet specific requirements. +set(version "0.3.21") +# 'flag' can be used to pass additional flags to the configure/make commands when building the dependency, but it's empty here. +set(flag "") +# 'is_cmake' is a boolean flag indicating whether the BLAS library uses CMake for its build system. It's set to ON, meaning it does. +set(is_cmake ON) +# 'is_git' is a boolean flag indicating whether the BLAS library's source code is hosted in a git repository. It's set to ON. +set(is_git ON) +# 'auto_gen' is a boolean flag indicating whether to use autogen scripts for the configuration process. It's set to OFF here. +set(auto_gen OFF) +# 'url' specifies the location of the BLAS library's source code repository. +set(url "https://github.com/xianyi/OpenBLAS") + +# Include the 'ImportDependency' macro script located in the 'macros' directory. +# This macro is responsible for importing and possibly installing the dependency. +include(macros/ImportDependency) +# Call the 'ImportDependency' macro with the previously set configuration parameters. +# This macro checks if BLAS is already available; if not, it proceeds to fetch, configure, build, and install it. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) +# Print a message indicating the completion of the BLAS setup process. +message(STATUS "${name} done") diff --git a/cmake/ImportBLASPP.cmake b/cmake/ImportBLASPP.cmake new file mode 100644 index 00000000..480b2e5c --- /dev/null +++ b/cmake/ImportBLASPP.cmake @@ -0,0 +1,65 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file ImportBLASPP.cmake +# @brief This file searches for the BLAS++ library and includes it if not already included. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-04 + +# Include the ImportBLAS script, which presumably sets up basic BLAS dependencies. +include(ImportBLAS) + +# Set up basic configuration variables for locating or installing BLAS++. +# `name` variable set to 'blaspp' to represent the BLAS++ library throughout the script. +set(name blaspp) +# Convert the name to uppercase and store it in `capital_name` for display purposes. +string(TOUPPER ${name} capital_name) +# Set the `tag` variable to specify the version of BLAS++ to be used or installed. +set(tag "v2023.01.00") +# Set the `url` variable to the location of the BLAS++ repository on GitHub. +set(url "https://github.com/icl-utk-edu/blaspp") +# Configure the directory where BLAS++ will be installed or found. +set(${name}_DIR "${CMAKE_INSTALL_PREFIX}/${capital_name}/${name}-build/") + +# Display a header message indicating the start of the BLAS++ setup process. +message("") +message("---------------------------------------- ${capital_name}") +# Output the version of BLAS++ being checked for or installed. +message(STATUS "Checking for ${capital_name} with Version ${version}") + +# Check if the BLAS++ target is already defined in the current CMake environment. +IF (NOT TARGET ${name}) + # Include the FindPkgConfig module to use pkg-config for finding installed libraries. + include(FindPkgConfig) + # Attempt to find the pkg-config utility quietly. + find_package(PkgConfig QUIET) + # Quietly search for the BLAS++ package, without specifying components or version. + find_package(${name} ${version} QUIET COMPONENTS ${components}) + + # If BLAS++ is found, output its location and libraries linked. + if (${name}_FOUND) + message(" Found ${capital_name}; ${${name}_DIR} ${${name}_LIBRARIES}") + else () + # If BLAS++ is not found, indicate it and proceed to install it. + message(" Can't find ${capital_name}, Installing it instead ..") + # Include the FetchContent module to download external projects during the configure stage. + include(FetchContent) + # Set the base directory for downloading and building the external project. + set(FETCHCONTENT_BASE_DIR ${CMAKE_INSTALL_PREFIX}/${capital_name}) + # Declare the external project (BLAS++) with its Git repository and specific tag. + FetchContent_Declare(${name} GIT_REPOSITORY "${url}" GIT_TAG "${tag}") + # Make the declared content available, effectively downloading and setting up BLAS++. + FetchContent_MakeAvailable(${name}) + + endif () +else () + # If the BLAS++ target is already defined, indicate that it's already included. + message(STATUS "${capital_name} already included") +endif () + +# Add BLAS++ to the list of libraries to be linked against by setting `LIBS`. +set(LIBS ${name} ${LIBS}) +# Final status message indicating completion of the BLAS++ setup. +message(STATUS "${name} done") diff --git a/cmake/ImportBlas.cmake b/cmake/ImportBlas.cmake deleted file mode 100644 index 2df0a6c9..00000000 --- a/cmake/ImportBlas.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportBlas.cmake -# @brief This file searches for the BLAS library and includes it if not already included. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-12 - -# search for BLAS library, if not already included -message("") -message("---------------------------------------- BLAS") -message(STATUS "Checking for BLAS") -include(macros/BuildDependency) - -if (NOT TARGET BLAS) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(BLAS QUIET) - - if (BLAS_FOUND) - message(" Found BLAS: ${BLAS_LIBRARIES}") - else () - message(" Can't find Blas, Installing it instead ..") - # Set installation flags - set(FLAGS "") - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - set(build_tests "false") - BuildDependency(BLAS "https://github.com/xianyi/OpenBLAS" "v0.3.21" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - find_package(BLAS REQUIRED) - endif () - -else () - message(" BLAS already included") -endif () - -message(STATUS "BLAS done") diff --git a/cmake/ImportBlasPP.cmake b/cmake/ImportBlasPP.cmake deleted file mode 100644 index 32f25b0b..00000000 --- a/cmake/ImportBlasPP.cmake +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportBlasPP.cmake -# @brief This file searches for the BLAS++ library and includes it if not already included. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-12 - -# search for BLAS library, if not already included -message("") -message("---------------------------------------- BLAS++") -message(STATUS "Checking for BLAS++") - -if (NOT TARGET blaspp) - - include(FindPkgConfig) - find_package(PkgConfig QUIET) - include(ImportBlas) - - find_package(blaspp QUIET) - - if (blaspp_FOUND) - message("Found BLAS++: ${blaspp_DIR}") - elseif (EXISTS "${CMAKE_SOURCE_DIR}/blaspp/CMakeLists.txt") - set(build_tests_save "${build_tests}") - set(build_tests "false") - add_subdirectory("blaspp") - - set(build_tests "${build_tests_save}") - set(blaspp_DIR "${CMAKE_BINARY_DIR}/blaspp") - else () - set(build_tests_save "${build_tests}") - set(build_tests "false") - set(url "https://github.com/icl-utk-edu/blaspp") - set(tag "v2023.01.00") - message(STATUS "Fetching BLAS++ ${tag} from ${url}") - include(FetchContent) - FetchContent_Declare( - blaspp GIT_REPOSITORY "${url}" GIT_TAG "${tag}") - FetchContent_MakeAvailable(blaspp) - set(build_tests "${build_tests_save}") - endif () -else () - message(" BLAS++ already included") -endif () - -set(LIBS - blaspp - ${LIBS} - ) -message(STATUS "BLAS++ done") diff --git a/cmake/ImportCatch2.cmake b/cmake/ImportCatch2.cmake index 5e70e789..263a54bf 100644 --- a/cmake/ImportCatch2.cmake +++ b/cmake/ImportCatch2.cmake @@ -1,40 +1,34 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportChameleon.cmake # @brief This script checks for Chameleon and includes it in the project if it is not already a target. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy -# @author Sameh Abdulah # @date 2023-03-13 -message("") -message("---------------------------------------- Catch2") -message(STATUS "Checking for Catch2") -include(macros/BuildDependency) +# Sets the 'name' variable to "Catch2", identifying the dependency being imported. +set(name "Catch2") +# Specifies the 'tag' variable as "v3.3.2", which likely corresponds to a specific release or version of Catch2. +set(tag "v3.3.2") +# Sets the 'version' variable to "3.3.2", defining the expected version of Catch2 to be used in the project. +set(version "3.3.2") +# Initializes the 'flag' variable as an empty string, which could be used for additional configuration options during the build or installation process. +set(flag "") +# Sets the 'is_cmake' flag to ON, indicating that Catch2 uses CMake as its build system. +set(is_cmake ON) +# Sets the 'is_git' flag to ON, suggesting that Catch2's source code is hosted in a git repository. +set(is_git ON) +# Initializes the 'auto_gen' flag to OFF, implying that there's no need for auto-generation scripts (like autogen.sh) in the building process of Catch2. +set(auto_gen OFF) +# Defines the 'url' variable with the GitHub repository URL of Catch2, specifying the source location from which Catch2 will be fetched. +set(url "https://github.com/catchorg/Catch2.git") -IF (NOT TARGET Catch2) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(Catch2 QUIET) - - # If Catch2 is not found, fetch and build it - if (Catch2_FOUND) - message(" Found Catch2") - else () - message(" Can't find catch2, Installing it instead ..") - include(FetchContent) - set(FETCHCONTENT_QUIET OFF) - FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.3.2 # Replace with the version of Catch2 you want to use for v3 - GIT_SHALLOW TRUE - ) - FetchContent_MakeAvailable(Catch2) - endif () -else () - message(STATUS "Catch2 already included") -endif () +# Includes the 'ImportDependency' macro script located in the 'macros' directory. This script is responsible for checking the presence of the specified dependency and importing it if necessary. +include(macros/ImportDependency) +# Calls the 'ImportDependency' macro with the previously set variables as arguments. This macro will check for Catch2's presence, and if it's not found, it will attempt to fetch and install it using the provided details. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) +# Logs a message indicating the completion of the Catch2 import process. +message(STATUS "${name} done") diff --git a/cmake/ImportChameleon.cmake b/cmake/ImportChameleon.cmake index 4d19a5ea..650db197 100644 --- a/cmake/ImportChameleon.cmake +++ b/cmake/ImportChameleon.cmake @@ -1,65 +1,45 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportChameleon.cmake # @brief This script checks for Chameleon and includes it in the project if it is not already a target. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-13 -message("") -message("---------------------------------------- Chameleon") -message(STATUS "Checking for Chameleon") -include(macros/BuildDependency) - -if (NOT TARGET CHAMELEON_FOUND) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(CHAMELEON QUIET) - - # If Chameleon is found, include it - if (CHAMELEON_FOUND) - message(" Found Chameleon: ${CHAMELEON_LIBDIR}") - # If Chameleon is not found, install it - else () - message(" Can't find Chameleon, Installing it instead ..") - # Set installation flags - set(FLAGS -DCHAMELEON_USE_CUDA=${USE_CUDA} \-DBLA_VENDOR=${BLA_VENDOR} \-DCHAMELEON_USE_MPI=${USE_MPI} \-DCHAMELEON_SCHED_STARPU=ON \-DCHAMELEON_ENABLE_TESTING=OFF) - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - # Install Chameleon - BuildDependency(CHAMELEON "https://gitlab.inria.fr/solverstack/chameleon.git" "v1.1.0" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - # Reset flags - set(FLAGS "") - find_package(CHAMELEON REQUIRED) - endif () -else() - message(" CHAMELEON already included") -endif() - -link_directories(${CHAMELEON_LIBRARY_DIRS_DEP}) - -include_directories(AFTER ${CHAMELEON_INCLUDE_DIRS_DEP}) +# Set basic configuration variables for the Chameleon library. +# 'name' is set to "CHAMELEON", which is the identifier used for the dependency throughout the script. +set(name "CHAMELEON") +# 'tag' specifies the version tag of the Chameleon library to fetch, indicating a specific state of the source code in the repository. +set(tag "v1.1.0") +# 'version' specifies the version of the Chameleon library. This may be used to ensure compatibility or meet specific requirements. +set(version "1.1.0") +# 'flag' can be used to pass additional flags to the configure/make commands when building the dependency. Flags here are for CUDA, BLAS vendor, MPI, StarPU, and disabling testing. +set(flag -DCHAMELEON_USE_CUDA=${USE_CUDA} \-DBLA_VENDOR=${BLA_VENDOR} \-DCHAMELEON_USE_MPI=${USE_MPI} \-DCHAMELEON_SCHED_STARPU=ON \-DCHAMELEON_ENABLE_TESTING=OFF) +# 'is_cmake' is a boolean flag indicating whether the Chameleon library uses CMake for its build system. It's set to ON, meaning it does. +set(is_cmake ON) +# 'is_git' is a boolean flag indicating whether the Chameleon library's source code is hosted in a git repository. It's set to ON. +set(is_git ON) +# 'auto_gen' is a boolean flag indicating whether to use autogen scripts for the configuration process. It's set to OFF here. +set(auto_gen OFF) +# 'url' specifies the location of the Chameleon library's source code repository. +set(url "https://gitlab.inria.fr/solverstack/chameleon.git") + +# Include the 'ImportDependency' macro script located in the 'macros' directory. +# This macro is responsible for importing and possibly installing the dependency. +include(macros/ImportDependency) +# Call the 'ImportDependency' macro with the previously set configuration parameters. +# This macro checks if CHAMELEON is already available; if not, it proceeds to fetch, configure, build, and install it. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# Additional include directories for Chameleon are specified, ensuring the project can find Chameleon's headers. +# The AFTER keyword specifies that these directories should be searched after the default ones. include_directories(AFTER ${CHAMELEON_DIR_FOUND}/include/coreblas) include_directories(${CHAMELEON_DIR_FOUND}/chameleon-src) +include_directories(${CHAMELEON_DIR_FOUND}) -if (CHAMELEON_LINKER_FLAGS) - list(APPEND CMAKE_EXE_LINKER_FLAGS "${CHAMELEON_LINKER_FLAGS} ") -endif () -if (CHAMELEON_LIBRARY_DIRS) - # the RPATH to be used when installing - list(APPEND CMAKE_INSTALL_RPATH "${CHAMELEON_LIBRARY_DIRS}") -endif () -if (CHAMELEON_LIBRARIES) - if (CHAMELEON_LIBRARIES_DEP) - list(APPEND LIBS ${CHAMELEON_LIBRARIES_DEP}) - else () - list(APPEND LIBS ${CHAMELEON_LIBRARIES}) - endif () -endif () - -message(STATUS "Chameleon done") +# Print a status message indicating the completion of Chameleon's inclusion process. +message(STATUS "${name} done") diff --git a/cmake/ImportCuSolver.cmake b/cmake/ImportCuSolver.cmake deleted file mode 100644 index bdaa0978..00000000 --- a/cmake/ImportCuSolver.cmake +++ /dev/null @@ -1,20 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportCuSolver.cmake -# @brief This script sets CUDA libraries and adds CuSolver, CuBlas, and CuBlasLt to the list of libraries. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-13 - -set(cudart_lib CUDA::cudart) -set(cublas_lib CUDA::cublas) -set(LIBS - CUDA::cusolver - CUDA::cublas - CUDA::cublasLt - ${LIBS} - ) diff --git a/cmake/ImportGFortran.cmake b/cmake/ImportGFortran.cmake deleted file mode 100644 index a57f0517..00000000 --- a/cmake/ImportGFortran.cmake +++ /dev/null @@ -1,17 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportGFortran.cmake -# @brief Defines the gfortran library for use in the project. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-14 - -# Export the list of libraries, including gfortran, for use in the project. -set(LIBS - gfortran - ${LIBS} - ) diff --git a/cmake/ImportGSL.cmake b/cmake/ImportGSL.cmake index 3c111a1b..9a159744 100644 --- a/cmake/ImportGSL.cmake +++ b/cmake/ImportGSL.cmake @@ -1,51 +1,41 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportGSL.cmake # @brief Checks for the GSL library and includes it in the project if it is not already present. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-16 -message("") -message("---------------------------------------- GSL") -message(STATUS "Checking for GSL") - -include(macros/BuildDependency) - -# Check if the GSL library is already included in the project. -if (NOT TARGET GSL_FOUND) - - # If not, attempt to find it with PkgConfig and CMake's find_package function. - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(GSL QUIET) - - # If the GSL library is found, add it to the project's libraries. - if (GSL_FOUND) - message(" Found GSL: ${GSL_INCLUDE_DIRS}") - else () - - # If the GSL library is not found, install it and add it to the project's libraries. - message(" Can't find GSL, Installing it instead ..") - set(FLAGS "") - set(ISCMAKE OFF) - set(ISGIT OFF) - set(AUTO_GEN OFF) - BuildDependency(GSL "https://ftp.gnu.org/gnu/gsl/gsl-2.7.1.tar.gz" "v2.7.1" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - find_package(GSL REQUIRED) - endif () -else () - message(" GSL already included") -endif () - -# Add the GSL library to the project's list of libraries. +# Configurations for integrating the GSL (GNU Scientific Library) +# 'name' is assigned "GSL" to identify the GNU Scientific Library within this script. +set(name "GSL") +# 'tag' specifies the version tag "v2.7.1" for the GSL library, indicating the exact version to be used. +set(tag "v2.7.1") +# 'version' sets "2.7.1" as the version of the GSL library, ensuring compatibility with project requirements. +set(version "2.7.1") +# 'flag' is available for additional configuration options during build or installation, but remains empty here. +set(flag "") +# 'is_cmake' indicates whether GSL uses CMake for building. It is set to OFF, implying an alternative build system is used. +set(is_cmake OFF) +# 'is_git' denotes if GSL's source code is hosted in a Git repository. It is set to OFF, suggesting the source is obtained from a different location. +set(is_git OFF) +# 'auto_gen' signifies the need for autogen scripts in the build process. Here, it is set to OFF, indicating they are not needed. +set(auto_gen OFF) +# 'url' provides the download location for the GSL source code, pointing to the GNU archive. +set(url "https://ftp.gnu.org/gnu/gsl/gsl-2.7.1.tar.gz") + +# Include the 'ImportDependency' macro, responsible for managing the GSL library's import and setup process. +include(macros/ImportDependency) +# Execute the 'ImportDependency' macro with the previously established parameters to handle the detection, downloading, and integration of GSL. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# Add GSL to the project's list of linked libraries, making its functionality accessible within the project. list(APPEND LIBS gsl) -include_directories(${GSL_INCLUDE_DIRS}) -link_directories(${GSL_LIBRARY_DIRS}) -message("${GSL_LIBRARIES}") -message(STATUS "GSL done") +# Output a message signaling the successful integration of the GSL library into the project. +message(STATUS "${name} done") + diff --git a/cmake/ImportHCore.cmake b/cmake/ImportHCore.cmake new file mode 100644 index 00000000..0595ceb1 --- /dev/null +++ b/cmake/ImportHCore.cmake @@ -0,0 +1,37 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file ImportHCore.cmake +# @brief Checks for the Hcore library and includes it in the project if it is not already present. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @author Sameh Abdulah +# @date 2023-03-15 + +# Configurations for the HCORE library +# 'name' is set to "HCORE", serving as the identifier for the dependency throughout this script. +set(name "HCORE") +# 'tag' defines the version tag of the HCORE library to be fetched, represents a specific snapshot of the source code in the repository. +set(tag "v0.1.3") +# 'version' indicates the version of the HCORE library, used to ensure compatibility or fulfill certain requirements. +set(version "0.1.3") +# 'flag' is intended for passing additional flags to the configure/make commands during the building of the dependency, but is left empty here. +set(flag "") +# 'is_cmake' is a boolean flag that denotes whether the HCORE library utilizes CMake for its build process. Here, it's set to ON. +set(is_cmake ON) +# 'is_git' is a boolean flag that signifies if the source code for HCORE is maintained in a git repository. This is set to ON. +set(is_git ON) +# 'auto_gen' is a boolean flag that indicates whether autogen scripts are required for the configuration process. It is set to OFF in this context. +set(auto_gen OFF) +# 'url' provides the location of the HCORE library's source code repository. +set(url "https://github.com/ecrc/hcore.git") + +# The 'ImportDependency' macro script, located in the 'macros' directory, is included. This macro is crucial for importing and potentially installing the dependency. +include(macros/ImportDependency) +# The 'ImportDependency' macro is invoked with the configuration parameters set above to handle the detection, fetching, and setup of HCORE. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) +# A message is logged to indicate the successful completion of the HCORE setup process. +message(STATUS "${name} done") + diff --git a/cmake/ImportHcore.cmake b/cmake/ImportHcore.cmake deleted file mode 100644 index 0c5fe43f..00000000 --- a/cmake/ImportHcore.cmake +++ /dev/null @@ -1,50 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportHcore.cmake -# @brief Checks for the Hcore library and includes it in the project if it is not already present. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-15 - -message("") -message("---------------------------------------- Hcore") -message(STATUS "Checking for Hcore") - -include(macros/BuildDependency) - -# Check if the Hcore library is already included in the project. -if (NOT TARGET HCORE_FOUND) - - # If not, attempt to find it with PkgConfig and CMake's find_package function. - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(HCORE QUIET) - - # If the Hcore library is found, add it to the project's libraries. - if (HCORE_FOUND) - message(" Found Hcore: ${HCORE_LIBDIR}") - else() - - # If the Hcore library is not found, install it and add it to the project's libraries. - message(" Can't find Hcore, Installing it instead ..") - set(FLAGS "") - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - BuildDependency(HCORE "https://github.com/ecrc/hcore.git" "v0.1.3" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - find_package(HCORE REQUIRED) - endif() -else() - message(" HCORE already included") -endif() - -# Add the Hcore library to the project's list of libraries. -list(APPEND LIBS ${HCORE_LIBRARIES}) -link_directories(${HCORE_LIBRARY_DIRS_DEP}) -include_directories(${HCORE_INCLUDE_DIRS}) - -message(STATUS "Hcore done") \ No newline at end of file diff --git a/cmake/ImportHiCMA.cmake b/cmake/ImportHiCMA.cmake index 025ce48f..bb879d66 100644 --- a/cmake/ImportHiCMA.cmake +++ b/cmake/ImportHiCMA.cmake @@ -1,66 +1,42 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportHiCMA.cmake # @brief Find and include HiCMA library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-13 -message("") -message("---------------------------------------- Hicma") -message(STATUS "Checking for HiCMA") -include(macros/BuildDependency) - -if (NOT TARGET HICMA_FOUND) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(HICMA QUIET) - - # If HiCMA is found, print its location. - if (HICMA_FOUND) - message(" Found HiCMA: ${HICMA_LIBDIR}") - # If not found, install it. - else () - message(" Can't find HiCMA, Installing it instead ..") - - # Set the flags to be passed to the build command. - set(FLAGS \-DHICMA_USE_MPI=${USE_MPI}) - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - # Build HiCMA from source. - BuildDependency(HiCMA "https://github.com/ecrc/hicma.git" "v1.0.0" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - # Clear the flags. - set(FLAGS "") - # Find HiCMA after installation. - find_package(HICMA REQUIRED) - endif () -else () - message(" HiCMA already included") -endif () - -# Include HiCMA headers in the project. -include_directories(${HICMA_INCLUDE_DIRS_DEP}) +# Configuration settings for integrating the HICMA library into the project +# 'name' sets the identifier for the HICMA library within this script to "HICMA". +set(name "HICMA") +# 'tag' specifies "v1.0.0" as the version tag of HICMA, denoting a specific release to be fetched. +set(tag "v1.0.0") +# 'version' defines "1.0.0" as the version of the HICMA library, ensuring compatibility with project requirements. +set(version "1.0.0") +# 'flag' is used to pass additional configuration options during the build, specifically for enabling or disabling MPI support based on the project's needs. +set(flag -DHICMA_USE_MPI=${USE_MPI}) +# 'is_cmake' indicates that HICMA uses CMake for its build system, set to ON. +set(is_cmake ON) +# 'is_git' denotes that HICMA's source code is hosted on a Git repository, set to ON. +set(is_git ON) +# 'auto_gen' signals whether autogen scripts are necessary for the build process; it is set to OFF for HICMA. +set(auto_gen OFF) +# 'url' provides the GitHub repository URL for HICMA, specifying where the source code can be cloned from. +set(url "https://github.com/ecrc/hicma.git") + +# The 'ImportDependency' macro, located in the 'macros' directory, is included. This macro handles the import and setup of the HICMA library. +include(macros/ImportDependency) +# The 'ImportDependency' macro is invoked with the previously defined parameters to manage the detection, fetching, and setup of HICMA. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# Directories containing HiCMA headers are included in the project, ensuring that HiCMA's functions and types are accessible. include_directories(${HICMA_LIBDIR}/../hicma-src/hicma_ext) +include_directories(${HICMA_LIBDIR}/../hicma_ext) -# Include HiCMA libraries in the project. -if (HICMA_LINKER_FLAGS) - list(APPEND CMAKE_EXE_LINKER_FLAGS "${HICMA_LINKER_FLAGS}") -endif () -if (HICMA_LIBRARY_DIRS) - list(APPEND CMAKE_INSTALL_RPATH "${HICMA_LIBRARY_DIRS}") - link_directories(${HICMA_LIBRARY_DIRS}) -endif () - -# Add HiCMA libraries to the dependencies of the project. -if (HICMA_LIBRARIES_DEP) - list(APPEND LIBS ${HICMA_LIBRARIES_DEP}) -else () - list(APPEND LIBS ${HICMA_LIBRARIES}) -endif () +# A status message is displayed to indicate the successful inclusion of the HiCMA library into the project. +message(STATUS "HiCMA done") -message(STATUS "HiCMA done") \ No newline at end of file diff --git a/cmake/ImportHwloc.cmake b/cmake/ImportHwloc.cmake index 019f8c82..5f632725 100644 --- a/cmake/ImportHwloc.cmake +++ b/cmake/ImportHwloc.cmake @@ -1,56 +1,38 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportHwloc.cmake # @brief Find and include Hwloc library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-15 +# Configuration settings for integrating the HWLOC library +# 'name' sets the identifier for the HWLOC library within this script to "HWLOC". +set(name "HWLOC") +# 'tag' specifies "hwloc-2.10.0" as the version tag, identifying a specific release of HWLOC to be used. +set(tag "hwloc-2.10.0") +# 'version' defines "2.10.0" as the version of HWLOC, ensuring it meets project compatibility requirements. +set(version "2.10.0") +# 'flag' is available for additional build configuration options but remains empty for HWLOC. +set(flag "") +# 'is_cmake' indicates whether HWLOC uses CMake for its build system. It's set to OFF, suggesting an alternative build system is used. +set(is_cmake OFF) +# 'is_git' denotes that HWLOC's source code is maintained in a Git repository, set to ON. +set(is_git ON) +# 'auto_gen' signals the need for running autogen scripts as part of the build process for HWLOC, set to ON. +set(auto_gen ON) +# 'url' provides the GitHub repository URL for HWLOC, indicating the source code's location. +set(url "https://github.com/open-mpi/hwloc") + +# Includes the 'ImportDependency' macro script, located in the 'macros' directory, responsible for handling the import and setup of dependencies. +include(macros/ImportDependency) +# The 'ImportDependency' macro is called with the configuration parameters above to manage the detection, fetching, and setup of HWLOC. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# A message is logged to indicate the successful integration of the HWLOC library into the project. +message(STATUS "${name} done") -message("") -message("---------------------------------------- Hwloc") -message(STATUS "Checking for Hwloc") - -include(macros/BuildDependency) - -# If Hwloc library is not already included as a target, try to find it. -if (NOT TARGET HWLOC) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(HWLOC 2.4.0 REQUIRED QUIET) - - # If Hwloc is found, print its location. - if (HWLOC_FOUND) - message(" Found HWLOC: ${HWLOC_INCLUDE_DIRS}") - # If not found, install it. - else () - message(" Can't find Hwloc, Installing it instead ..") - - # Set the flags to be passed to the build command. - set(FLAGS "") - set(ISCMAKE OFF) - set(ISGIT ON) - set(AUTO_GEN ON) - - # Build Hwloc from source. - BuildDependency(HWLOC "https://github.com/open-mpi/hwloc" "hwloc-2.4.0" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - - # Find Hwloc after installation. - find_package(HWLOC 2.4.0 REQUIRED) - endif () -else () - message(" HWLOC already included") -endif () - -# Include Hwloc libraries in the project. -list(APPEND LIBS ${HWLOC_LIBRARIES}) -link_directories(${HWLOC_LIBRARY_DIRS_DEP}) - -# Include Hwloc headers in the project. -include_directories(${HWLOC_INCLUDE_DIRS}) - -message(STATUS "HWLOC done") diff --git a/cmake/ImportLapack.cmake b/cmake/ImportLapack.cmake index c0e77417..da0ab62b 100644 --- a/cmake/ImportLapack.cmake +++ b/cmake/ImportLapack.cmake @@ -1,42 +1,38 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportLapack.cmake # @brief Find and include LAPACK library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-12 -# search for LAPACK library, if not already included -message("") -message("---------------------------------------- LAPACK") -message(STATUS "Checking for LAPACK") +# Configuration settings for the integration of the LAPACK library +# 'name' is designated as "LAPACK" to identify the LAPACK library within the scope of this script. +set(name "LAPACK") +# 'tag' is set to "v0.3.21", specifying the particular version tag of LAPACK to be utilized. +set(tag "v0.3.21") +# 'version' denotes the LAPACK library version as "0.3.21", aligned with the tag for consistency in versioning. +set(version "0.3.21") +# 'flag' is intended for any additional flags needed for configuration or building, but is left blank in this case. +set(flag "") +# 'is_cmake' is a boolean flag indicating that LAPACK uses CMake for its build process, set to ON. +set(is_cmake ON) +# 'is_git' signifies that the source code for LAPACK is available in a Git repository, set to ON. +set(is_git ON) +# 'auto_gen' indicates whether autogen scripts are necessary for the configuration process; it is set to OFF for LAPACK. +set(auto_gen OFF) +# 'url' provides the repository URL for LAPACK, pointing to the location where the source code can be accessed. +set(url "https://github.com/xianyi/OpenBLAS") -include(macros/BuildDependency) +# The 'ImportDependency' macro script from the 'macros' directory is included, which facilitates the import and setup of dependencies. +include(macros/ImportDependency) +# The 'ImportDependency' macro is executed with the above-defined parameters to manage the detection, retrieval, and configuration of LAPACK. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) -if (NOT TARGET LAPACK) - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(LAPACK QUIET) +# A status message is output to indicate the successful completion of the LAPACK setup process. +message(STATUS "${name} done") - if (LAPACK_FOUND) - message(" Found LAPACK: ${LAPACK_LIBRARIES}") - else () - message(" Can't find Blas, Installing it instead ..") - # Set installation flags - set(FLAGS "") - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - set(build_tests "false") - BuildDependency(LAPACK "https://github.com/xianyi/OpenBLAS" "v0.3.21" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - find_package(LAPACK REQUIRED) - endif () -else () - message(" LAPACK already included") -endif () - -message(STATUS "LAPACK done") diff --git a/cmake/ImportLapackPP.cmake b/cmake/ImportLapackPP.cmake deleted file mode 100644 index 543c3cd7..00000000 --- a/cmake/ImportLapackPP.cmake +++ /dev/null @@ -1,60 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportLapackPP.cmake -# @brief Find and include LAPACK++ library as a dependency. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-12 - -# search for LAPACK library, if not already included -message("") -message("---------------------------------------- LAPACK++") -message(STATUS "Checking for LAPACK++") -if (NOT TARGET lapackpp) - include(ImportLapack) - - find_package(lapackpp QUIET) - if (lapackpp_FOUND) - message(" Found LAPACK++: ${lapackpp_DIR}") - elseif (EXISTS "${CMAKE_SOURCE_DIR}/lapackpp/CMakeLists.txt") - set(build_tests_save "${build_tests}") - set(build_tests "false") - - add_subdirectory("lapackpp") - - set(build_tests "${build_tests_save}") - set(lapackpp_DIR "${CMAKE_BINARY_DIR}/lapackpp") - else () - set(build_tests_save "${build_tests}") - set(build_tests "false") - - set(url "https://github.com/icl-utk-edu/lapackpp") - set(tag "v2023.01.00") - message(STATUS "Fetching LAPACK++ ${tag} from ${url}") - include(FetchContent) - FetchContent_Declare( - lapackpp GIT_REPOSITORY "${url}" GIT_TAG "${tag}") - FetchContent_MakeAvailable(lapackpp) - - set(build_tests "${build_tests_save}") - endif () -else () - message(" LAPACK++ already included") -endif () - -# Add to linking libs. -set(LIBS - lapackpp - ${LIBS} - ) - -# Add definition indicating version. -if ("${lapackpp_defines}" MATCHES "LAPACK_ILP64") - set(COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS} -DHCORE_HAVE_LAPACK_WITH_ILP64") -endif () - -message(STATUS "LAPACK++ done") diff --git a/cmake/ImportNLOPT.cmake b/cmake/ImportNLOPT.cmake index 3a510b8b..b3ce08c6 100644 --- a/cmake/ImportNLOPT.cmake +++ b/cmake/ImportNLOPT.cmake @@ -1,56 +1,38 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportNLOPT.cmake # @brief Find and include NLOPT library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-26 -message("") -message("---------------------------------------- NLOPT") -message(STATUS "Checking for NLOPT") -include(macros/BuildDependency) -if (NOT TARGET NLOPT_FOUND) - # Try to find NLOPT. - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(NLOPT 2.4.2 QUIET) +# Configuration settings for the integration of the NLOPT library +# 'name' is assigned to "NLOPT", serving as the identifier for this library within the script. +set(name "NLOPT") +# 'tag' defines "v2.7.1" as the version tag of NLOPT, indicating the specific release to be utilized. +set(tag "v2.7.1") +# 'version' specifies "2.7.1" as the version of the NLOPT library, ensuring compatibility with the project's requirements. +set(version "2.7.1") +# 'flag' is intended for additional configuration options during the build process. A space is placed as a placeholder. +set(flag " ") +# 'is_cmake' indicates that NLOPT uses CMake for its build system, which is set to ON. +set(is_cmake ON) +# 'is_git' denotes that the NLOPT source code is hosted in a Git repository, which is set to ON. +set(is_git ON) +# 'auto_gen' signals whether autogen scripts are required for the build process, which is set to OFF for NLOPT. +set(auto_gen OFF) +# 'url' provides the location of the NLOPT source code repository on GitHub. +set(url "https://github.com/stevengj/nlopt") + +# The 'ImportDependency' macro script, located in the 'macros' directory, is included for managing the import and setup of the NLOPT library. +include(macros/ImportDependency) +# The 'ImportDependency' macro is invoked with the above-defined parameters to handle the detection, fetching, and integration of NLOPT into the project. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# A status message is outputted to indicate the successful integration of the NLOPT library into the project. +message(STATUS "${name} done") - # If NLOPT is found, print its location. - if (NLOPT_FOUND) - message(" Found NLOPT: ${NLOPT_LIBRARIES}") - # If not found, install it. - else () - message(" Can't find NLOPT, Installing it instead ..") - - # Set installation flags. - set(FLAGS "") - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - # Build NLOPT from source. - BuildDependency(NLOPT "https://github.com/stevengj/nlopt" "v2.7.1" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - - # Set the location of NLOPT. - set(NLOPT_LIBRARY_DIRS= ${EXAGEOSTAT_INSTALL_PREFIX}/NLOPT/lib:$NLOPT_LIBRARY_DIRS) - set(NLOPT_INCLUDE_DIRS= ${EXAGEOSTAT_INSTALL_PREFIX}/NLOPT/include:$NLOPT_INCLUDE_DIRS) - - # Try to find NLOPT again. - find_package(NLOPT 2.4.2 REQUIRED) - endif () -else () - message(" NLOPT already included") -endif () - -# Include NLOPT headers. -include_directories(${NLOPT_INCLUDE_DIRS}) - -# Link NLOPT libraries. -link_directories(${NLOPT_LIBRARY_DIRS}) -list(APPEND LIBS ${NLOPT_LIBRARIES}) - -message(STATUS "NLOPT done") \ No newline at end of file diff --git a/cmake/ImportOpenMP.cmake b/cmake/ImportOpenMP.cmake deleted file mode 100644 index 4ec5aec9..00000000 --- a/cmake/ImportOpenMP.cmake +++ /dev/null @@ -1,27 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file ImportOpenMP.cmake -# @brief Find and include OpenMP library as a dependency. -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-13 - -# Add OpenMP if requested. -option(USE_OPENMP "Use OpenMP, if available" true) -if (NOT USE_OPENMP) - message(STATUS "User has requested to NOT use OpenMP") -else () - find_package(OpenMP QUIET) - IF (OPENMP_FOUND) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - set(LIBS - OpenMP::OpenMP_CXX - ${LIBS} - ) - ENDIF () -endif () diff --git a/cmake/ImportStarPu.cmake b/cmake/ImportStarPu.cmake index 42e6c47e..523ebc06 100644 --- a/cmake/ImportStarPu.cmake +++ b/cmake/ImportStarPu.cmake @@ -1,78 +1,52 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file ImportSTARPU.cmake # @brief Find and include STARPU library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-13 -message("") -message("---------------------------------------- StarPU") -message(STATUS "Checking for StarPU") +# Configuration settings for integrating the STARPU library into the project +# 'name' is set to "STARPU" to identify this specific library within the script. +set(name "STARPU") +# 'tag' specifies "starpu-1.3.10" as the version tag, indicating the exact version of STARPU to be used. +set(tag "starpu-1.3.10") +# 'version' sets "1.3.10" as the version of the STARPU library, ensuring project compatibility. +set(version "1.3.10") + +# Conditional setting of 'flag' based on project configurations for CUDA and MPI. +if (USE_CUDA AND USE_MPI) + # Sets flags for enabling CUDA and MPI, and disables OpenCL, documentation build, and export dynamic when both CUDA and MPI are used. + set(flag \--enable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--enable-mpi) +elseif(USE_CUDA) + # Sets flags for enabling CUDA and shared libraries, and disables OpenCL, documentation build, export dynamic, and MPI when only CUDA is used. + set(flag \--enable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--disable-mpi) +elseif(USE_MPI) + # Sets flags for enabling MPI and shared libraries, and disables CUDA, OpenCL, documentation build, and export dynamic when only MPI is used. + set(flag \--disable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--enable-mpi) +else() + # Sets flags for enabling shared libraries, and disables CUDA, OpenCL, documentation build, export dynamic, and MPI when neither CUDA nor MPI is used. + set(flag \--disable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--disable-mpi) +endif() + +# 'is_cmake' is set to OFF indicating STARPU does not use CMake as its primary build system. +set(is_cmake OFF) +# 'is_git' is set to ON, denoting that STARPU's source code is maintained in a Git repository. +set(is_git ON) +# 'auto_gen' is set to ON, signaling the need for autogen scripts to be run as part of the build process. +set(auto_gen ON) +# 'url' provides the location of the STARPU source code repository. +set(url "https://gitlab.inria.fr/starpu/starpu.git") + +# Include the 'ImportDependency' macro script, responsible for handling the import and setup of dependencies. +include(macros/ImportDependency) +# The 'ImportDependency' macro is invoked with the configuration parameters to manage the detection, fetching, and integration of STARPU. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "${STARPU_COMPONENT_LIST}" ${is_cmake} ${is_git} ${auto_gen}) + +# A message is logged to indicate the successful integration of the STARPU library into the project. +message(STATUS "${name} done") -include(macros/BuildDependency) - -if (NOT TARGET STARPU) - # Try to find STARPU. - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(STARPU 1.3.9 QUIET COMPONENTS ${STARPU_COMPONENT_LIST}) - - - # If STARPU is found, print its location. - if (STARPU_FOUND) - message(" Found StarPU: ${STARPU_LIBRARIES}") - # If not found, install it. - else () - # Set the flags to be passed to the build command. - set(ISCMAKE OFF) - set(ISGIT ON) - set(AUTO_GEN ON) - - if (USE_CUDA AND USE_MPI) - message(STATUS "Downloading STARPU - MPI CUDA" ) - set(FLAGS \--enable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--enable-mpi) - elseif(USE_CUDA) - message(STATUS "Downloading STARPU - CUDA" ) - set(FLAGS \--enable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--disable-mpi) - elseif(USE_MPI) - message(STATUS "Downloading STARPU - MPI" ) - set(FLAGS \--disable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--enable-mpi) - else() - message(STATUS "Downloading STARPU - SERIAL" ) - set(FLAGS \--disable-cuda \--disable-opencl \--enable-shared \--disable-build-doc \--disable-export-dynamic \--disable-mpi) - endif() - - BuildDependency(STARPU "https://gitlab.inria.fr/starpu/starpu.git" "starpu-1.3.9" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - # Clear the flags. - set(FLAGS "") - # Find StarPU after installation. - find_package(STARPU 1.3.9 QUIET COMPONENTS ${STARPU_COMPONENT_LIST}) - - endif () -else () - message(" STARPU already included") -endif () - -# Include STARPU headers. -list(APPEND LIBS ${STARPU_LIBRARIES}) -link_directories(${STARPU_LIBRARY_DIRS_DEP}) -include_directories(${STARPU_INCLUDE_DIRS}) -include_directories(${STARPU_INCLUDE_DIRS}/runtime/starpu) -include_directories(${STARPU_INCLUDE_DIRS_DEP}) - -# Set linker flags. -if (STARPU_LINKER_FLAGS) - list(APPEND CMAKE_EXE_LINKER_FLAGS "${STARPU_LINKER_FLAGS}") -endif () -set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS_DEP}") -foreach (libdir ${STARPU_LIBRARY_DIRS_DEP}) - list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}") -endforeach () -set(CMAKE_REQUIRED_LIBRARIES "${STARPU_LIBRARIES_DEP}") - -message(STATUS "starpu done") diff --git a/cmake/ImportStarsH.cmake b/cmake/ImportStarsH.cmake index 585fecbb..0fd9cde5 100644 --- a/cmake/ImportStarsH.cmake +++ b/cmake/ImportStarsH.cmake @@ -1,86 +1,37 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief Find and include STARSH library as a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-13 -message("") -message("---------------------------------------- Stars-H") -message(STATUS "Checking for STARSH") -include(macros/BuildDependency) - -if (NOT TARGET STARSH_FOUND) - # Try to find STARSH. - include(FindPkgConfig) - find_package(PkgConfig QUIET) - find_package(STARSH QUIET) - - # If STARSH is found, print its location. - if (STARSH_FOUND) - message(" Found STARSH: ${STARSH_INCLUDE_DIRS}") - # If not found, install it. - else () - message(" Can't find STARSH, Installing it instead ..") - set(FLAGS \-DSTARPU=OFF \-DMPI=${USE_MPI}) - set(ISCMAKE ON) - set(ISGIT ON) - set(AUTO_GEN OFF) - BuildDependency(STARSH "https://github.com/ecrc/stars-h.git" "v0.3.1" ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - set(FLAGS "") - find_package(STARSH REQUIRED) - endif () -else () - message(" STARSH already included") -endif () - -# Include STARSH headers. -include_directories(${STARSH_INCLUDE_DIRS_DEP}) - -# Set linker flags and library directories. -if (STARSH_LINKER_FLAGS) - list(APPEND CMAKE_EXE_LINKER_FLAGS "${STARSH_LINKER_FLAGS}") -endif () -if (STARSH_LIBRARY_DIRS) - list(APPEND CMAKE_INSTALL_RPATH "${STARSH_LIBRARY_DIRS}") -endif () - -# Check if GSL is a dependency of STARSH and add it if needed. -if (STARSH_LIBRARIES) - find_library(_STARSH_LIB NAME starsh PATHS ${STARSH_LIBRARY_DIRS}) - if (_STARSH_LIB AND NOT "${STARSH_LIBRARIES_DEP}" MATCHES "gsl") - execute_process(COMMAND nm ${_STARSH_LIB} COMMAND grep gsl RESULT_VARIABLE GSL_IN_STARSH) - if (${GSL_IN_STARSH} EQUAL 0) - message(STATUS "STARSH depends on gsl. Adding it to dependency list") - find_package(GSL REQUIRED) - if (GSL_FOUND) - if (STARSH_LIBRARIES_DEP) - list(APPEND STARSH_LIBRARIES_DEP ${GSL_LIBRARIES}) - else () - list(APPEND STARSH_LIBRARIES ${GSL_LIBRARIES}) - endif () - endif () - endif () - endif () - - # Add STARSH libraries to the project. - if (STARSH_LIBRARIES_DEP) - list(APPEND LIBS ${STARSH_LIBRARIES_DEP}) - link_directories(${STARSH_LIBRARY_DIRS_DEP}) - link_directories(${STARSH_LIBRARIES_DEP}) - else () - list(APPEND LIBS ${STARSH_LIBRARIES}) - link_directories(${STARSH_LIBRARIES}) - endif () - - list(APPEND LIBS ${STARSH_LIBRARIES}) - link_directories(${STARSH_LIBRARY_DIRS_DEP}) - include_directories(${STARSH_INCLUDE_DIRS}) -endif () - -message(STATUS "StarsH Done") \ No newline at end of file +# Configuration parameters for integrating the STARSH library +# 'name' is set to "STARSH" to identify the STARSH library within this script. +set(name "STARSH") +# 'tag' specifies "v0.3.1" as the version tag for STARSH, denoting the exact release to be used. +set(tag "v0.3.1") +# 'version' sets "0.3.1" as the version of the STARSH library, ensuring it aligns with project requirements. +set(version "0.3.1") +# 'flag' is used for additional build configuration options, specifically disabling StarPU and optionally enabling MPI. +set(flag \-DSTARPU=OFF \-DMPI=${USE_MPI}) +# 'is_cmake' indicates that STARSH uses CMake as its build system, set to ON. +set(is_cmake ON) +# 'is_git' denotes that the source code for STARSH is hosted on a Git repository, set to ON. +set(is_git ON) +# 'auto_gen' signals whether autogen scripts are needed for the build process; it is set to OFF for STARSH. +set(auto_gen OFF) +# 'url' provides the GitHub repository URL for STARSH, specifying the source code's location. +set(url "https://github.com/ecrc/stars-h.git") + +# The 'ImportDependency' macro, located in the 'macros' directory, is included to manage the import and setup of the STARSH library. +include(macros/ImportDependency) +# The 'ImportDependency' macro is called with the configuration parameters set above to manage the detection, fetching, and setup of STARSH. +ImportDependency(${name} ${tag} ${version} ${url} "${flag}" "" ${is_cmake} ${is_git} ${auto_gen}) + +# A message is output to indicate the successful integration of the STARSH library into the project. +message(STATUS "${name} done") diff --git a/cmake/macros/BuildDependency.cmake b/cmake/macros/BuildDependency.cmake index 5edee634..50f5c125 100644 --- a/cmake/macros/BuildDependency.cmake +++ b/cmake/macros/BuildDependency.cmake @@ -1,96 +1,115 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file BuildDependency.cmake # @brief Fetches, builds, and installs a dependency. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-03-12 +# @author Amr Nasr +# @date 2024-02-04 -# @param raw_name The name of the dependency. -# @param url The URL from which to fetch the dependency. -# @param tag The version or tag of the dependency to fetch. -# @param ${FLAGS} Additional flags to pass to the configure/make commands. -# @param ${ISCMAKE} A boolean flag indicating whether the dependency uses CMake as its build system. -# @param ${ISGIT} A boolean flag indicating whether the dependency is hosted on a git repository. -# @param ${AUTO_GEN} A boolean flag indicating whether to use autogen scripts or not. +# After building and installing the dependency, the macro installs the lib, include, and share directories +# in the current directory. -# This macro fetches the dependency using CMake's FetchContent module, and then builds and installs it. -# It also sets several environment variables (LD_LIBRARY_PATH, LIBRARY_PATH, CPATH, PKG_CONFIG_PATH, -# and ${capital_name}_DIR) and includes and links to the installation directory of the dependency. +# BuildDependency Macro: +# This macro is designed to fetch, configure, build, and install a dependency. +# It takes the following parameters: +# - raw_name: The name of the dependency. +# - url: The URL of the repository or source tarball. +# - tag: The version or tag of the dependency to fetch. +# - flags: Additional flags to pass to the configure/make commands. +# - is_using_cmake: A boolean flag indicating whether the dependency uses CMake as its build system. +# - is_using_git: A boolean flag indicating whether the dependency is hosted on a git repository. +# - auto_generation: A boolean flag indicating whether to use autogen scripts or not. -# After building and installing the dependency, the macro installs the lib, include, and share directories in the current directory. -macro(BuildDependency raw_name url tag ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) - # Set the name of the dependency. +# The macro fetches the dependency using CMake's FetchContent module, depending on whether it's a git repo or not. +# It sets up build paths and creates a directory for build artifacts. The subproject is then configured using +# CMake or autotools, and finally, it's built and installed. Environment variables are set, and the dependency's +# lib, include, and share directories are installed in the current directory. + +# Define the macro BuildDependency with parameters for handling various aspects of dependency management. +macro(BuildDependency raw_name url tag flags is_using_cmake is_using_git auto_generation) + + # Convert the raw dependency name to lowercase and uppercase for different uses and set them as 'name' and 'capital_name'. string(TOLOWER ${raw_name} name) string(TOUPPER ${raw_name} capital_name) - # Fetch the dependency, depending on whether it's a git repo or not. + # Log the start of the fetch process for the dependency, including its name, tag, and source URL. message(STATUS "Fetching ${name} ${tag} from ${url}") + # Include the CMake module for downloading and updating content during the configure step. include(FetchContent) - set(FETCHCONTENT_BASE_DIR ${EXAGEOSTAT_INSTALL_PREFIX}/${capital_name}/) - if (ISGIT) + # Set the base directory for fetched content to a directory within the install prefix, named after the dependency. + set(FETCHCONTENT_BASE_DIR ${CMAKE_INSTALL_PREFIX}/${capital_name}) + + # Check if the dependency is hosted in a git repository and declare it accordingly with FetchContent, using git-specific options. + if (${is_using_git}) FetchContent_Declare(${name} GIT_REPOSITORY "${url}" GIT_TAG "${tag}" - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + GIT_SHALLOW TRUE # For a shallow clone, fetching only the history needed for the specified tag + GIT_PROGRESS TRUE # Show progress during the clone ) else () + # If not using git, declare the dependency for FetchContent using a direct URL (e.g., for a tarball). FetchContent_Declare(${name} URL "${url}") endif () + + # Make the content available, effectively downloading it if necessary. FetchContent_Populate(${name}) - # Set up build paths and create directory for build artifacts. - set(${name}_srcpath ${EXAGEOSTAT_INSTALL_PREFIX}/${capital_name}/${name}-src) + # Set variables for the source path, binary (build) path, and installation path of the dependency. + set(${name}_srcpath ${CMAKE_INSTALL_PREFIX}/${capital_name}/${name}-src) set(${name}_binpath ${${name}_srcpath}/bin) - set(${name}_installpath ${EXAGEOSTAT_INSTALL_PREFIX}/${capital_name}/) + set(${name}_installpath ${CMAKE_INSTALL_PREFIX}/${capital_name}) + # Ensure the binary path directory exists. file(MAKE_DIRECTORY ${${name}_binpath}) - # Configure subproject. - if (ISCMAKE) - execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${EXAGEOSTAT_INSTALL_PREFIX}/${capital_name}/ ${FLAGS} + # Configure the project. If using CMake, run cmake command with specified flags and install prefix within the binary path. + if (${is_using_cmake}) + execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/${capital_name} -DCMAKE_C_FLAGS=-fPIC ${flags} ${${name}_srcpath} - WORKING_DIRECTORY - ${${name}_binpath}) + WORKING_DIRECTORY ${${name}_binpath}) else () - if (AUTO_GEN) + # For non-CMake projects, run autogen.sh if auto_generation is true, then configure the project with specified flags. + if (${auto_generation}) execute_process(COMMAND ./autogen.sh WORKING_DIRECTORY ${${name}_srcpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error endif () - execute_process(COMMAND ./configure --prefix=${EXAGEOSTAT_INSTALL_PREFIX}/${capital_name}/ ${FLAGS} + execute_process(COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX}/${capital_name} ${flags} WORKING_DIRECTORY ${${name}_srcpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error endif () - # Build and install subproject. + # Include the ProcessorCount module to determine the number of CPUs for parallel build and install commands. include(ProcessorCount) ProcessorCount(N) - if (ISCMAKE) + # Build the project using make, with parallel jobs based on processor count. This applies to both CMake and non-CMake projects. + if (${is_using_cmake}) execute_process(COMMAND make -j ${N} WORKING_DIRECTORY ${${name}_binpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error + # Install the built project, also with parallel jobs. execute_process(COMMAND make install -j ${N} WORKING_DIRECTORY ${${name}_binpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error else () execute_process(COMMAND make -j ${N} WORKING_DIRECTORY ${${name}_srcpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error execute_process(COMMAND make install -j ${N} WORKING_DIRECTORY ${${name}_srcpath} - COMMAND_ERROR_IS_FATAL ANY) + COMMAND_ERROR_IS_FATAL ANY) # Halt on error endif () - # Set environment variables and include/link to the installation directory of the dependency. + # Set environment variables for dynamic and static linking as well as include paths, pointing to the dependency's installation directory. set(ENV{LD_LIBRARY_PATH} "${${name}_installpath}/lib:${${name}_installpath}/lib64:$ENV{LD_LIBRARY_PATH}") set(ENV{LIBRARY_PATH} "${${name}_installpath}/lib:${${name}_installpath}/lib64:$ENV{LIBRARY_PATH}") set(ENV{CPATH} "${${name}_installpath}/include:$ENV{CPATH}") set(ENV{PKG_CONFIG_PATH} "${${name}_installpath}/lib/pkgconfig:${${name}_installpath}/lib64/pkgconfig:$ENV{PKG_CONFIG_PATH}") - set(${capital_name}_DIR "${${name}_installpath}") + + # Include and link to the installation directory of the dependency include_directories(${${name}_installpath}/include) link_directories(${${name}_installpath}/lib) @@ -113,4 +132,4 @@ macro(BuildDependency raw_name url tag ${FLAGS} ${ISCMAKE} ${ISGIT} ${AUTO_GEN}) DESTINATION . ) -endmacro() +endmacro() \ No newline at end of file diff --git a/cmake/macros/ImportDependency.cmake b/cmake/macros/ImportDependency.cmake new file mode 100644 index 00000000..1e6e71b0 --- /dev/null +++ b/cmake/macros/ImportDependency.cmake @@ -0,0 +1,85 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file ImportDependency.cmake +# @brief CMake script for importing and building external dependencies. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @author Amr Nasr +# @date 2023-12-28 + +# ImportDependency Macro: +# This macro is designed to check for the presence of an external dependency and install it if not found. +# It takes the following parameters: +# - raw_name: The name of the dependency. +# - tag: The tag of the dependency to fetch. +# - version: The version of the dependency. +# - url: The URL of the repository or source tarball. +# - flag: Additional flags to pass to the configure/make commands. +# - is_cmake: A boolean flag indicating whether the dependency uses CMake as its build system. +# - is_git: A boolean flag indicating whether the dependency is hosted on a git repository. +# - auto_gen: A boolean flag indicating whether to use autogen scripts or not. + +# The macro checks whether the dependency is already included. If not, it attempts to find the package. +# If the package is found, it prints a message. If not, it calls the BuildDependency macro to fetch, +# configure, build, and install the dependency. Finally, it attempts to find the package again to validate the installation. + +# Define a macro named ImportDependency for handling external dependencies. The macro checks for the dependency's presence and installs it if missing. +macro(ImportDependency name tag version url flag components is_cmake is_git auto_gen) + + # Check if the installation prefix is set to a system path (like /usr/) and warn the user about potential need for administrative privileges. + if (CMAKE_INSTALL_PREFIX MATCHES "/usr/") + message(WARNING "Installation path not specified. Please set the installation path using -DCMAKE_INSTALL_PREFIX=path/to/install or execute ./config.sh. Otherwise, please note that administrative privileges may be required to install in system paths.") + endif () + + # Convert the dependency name to uppercase for consistent messaging. + string(TOUPPER ${name} capital_name) + # Begin a section in the output to visually separate the handling of this dependency. + message("") + message("---------------------------------------- ${capital_name}") + # Log the attempt to check for the specified version of the dependency. + message(STATUS "Checking for ${capital_name} with Version ${version}") + + # Include the previously defined BuildDependency macro script for potential use. + include(macros/BuildDependency) + + # If the dependency has not already been targeted for building in the current CMake process, proceed to check its presence. + IF (NOT TARGET ${name}) + # Use the FindPkgConfig module to potentially use pkg-config for finding installed libraries. + include(FindPkgConfig) + find_package(PkgConfig QUIET) + # Attempt to find the specified version of the package quietly, without generating much output. + find_package(${name} ${version} QUIET COMPONENTS ${components}) + + # If the package is found, output a message detailing the found configuration. + if (${name}_FOUND) + message(" Found ${capital_name}; ${${name}_DIR} ${${name}_LIBRARIES}") + else () + # If the package is not found, notify and invoke BuildDependency to install it. + message(" Can't find ${capital_name}, Installing it instead ..") + BuildDependency(${name} ${url} ${tag} "${flag}" ${is_cmake} ${is_git} ${auto_gen}) + # After attempting installation, forcibly attempt to find the package again, this time requiring its presence. + find_package(${name} ${version} REQUIRED COMPONENTS ${components}) + endif () + else () + # If the dependency target already exists, log that it's already been included. + message(STATUS "${capital_name} already included") + endif () + + # Setup link and include directories based on the found or installed package configuration. + # Add the dependency's library directories to the link directories for the current CMake target. + link_directories(${${name}_LIBRARY_DIRS_DEP}) + link_directories(${${name}_LIBRARY_DIRS}) + # Add the dependency's include directories to the include path. + include_directories(${${name}_INCLUDE_DIRS}) + include_directories(AFTER ${${name}_INCLUDE_DIRS_DEP}) + + # If the dependency is not GSL, append its libraries to the list of libraries to be linked against. + if(NOT ${name} STREQUAL "GSL") + list(APPEND LIBS ${${name}_LIBRARIES}) + endif() + # Append any additional dependency libraries to the list of libraries. + list(APPEND LIBS ${${name}_LIBRARIES_DEP}) + +endmacro() diff --git a/cmake/toolchains/CudaToolchain.cmake b/cmake/toolchains/CudaToolchain.cmake index f9edaa67..89721ad9 100644 --- a/cmake/toolchains/CudaToolchain.cmake +++ b/cmake/toolchains/CudaToolchain.cmake @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CudaToolchain.cmake # @brief This file is used to set up the CUDA toolchain for compilation. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-12 @@ -19,5 +19,4 @@ set(CUDA_ARCHITECTURES "35;50;72") # Find the CUDA toolkit find_package(CUDAToolkit REQUIRED) -# TODO: Cuda linking set(ENV{LDFLAGS} "-L$ENV{CUDA_DIR}/lib64") diff --git a/cmake/toolchains/GccToolchain.cmake b/cmake/toolchains/GccToolchain.cmake index d02499de..82864184 100644 --- a/cmake/toolchains/GccToolchain.cmake +++ b/cmake/toolchains/GccToolchain.cmake @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file GccToolchain.cmake # @brief This file is used to set up the GCC toolchain for compilation. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-12 diff --git a/config.sh b/config.sh deleted file mode 100755 index 1f7d390b..00000000 --- a/config.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# @file config.sh -# @version 1.0.0 -# @author Mahmoud ElKarargy -# @date 2023-01-30 - -# Set variables and default values -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -BLUE='\033[0;34m' -NC='\033[0m' - -INSTALL_PREFIX=$PWD/installdir/_deps -PROJECT_SOURCE_DIR=$(dirname "$0") -BUILDING_TESTS="OFF" -BUILDING_EXAMPLES="OFF" -USING_HiCMA="OFF" -VERBOSE=OFF -USE_CUDA="OFF" -USE_MPI="OFF" -BLAS_VENDOR="" - -# Parse command line options -while getopts ":tevhHi:cms" opt; do - case $opt in - i) ##### Define installation path ##### - echo -e "${YELLOW}Installation path set to $OPTARG.${NC}" - INSTALL_PREFIX=$OPTARG - ;; - t) ##### Building tests enabled ##### - echo -e "${GREEN}Building tests enabled.${NC}" - BUILDING_TESTS="ON" - ;; - e) ##### Building examples enabled ##### - echo -e "${GREEN}Building examples enabled.${NC}" - BUILDING_EXAMPLES="ON" - ;; - H) ##### Using HiCMA ##### - echo -e "${GREEN}Using HiCMA.${NC}" - USING_HiCMA="ON" - ;; - c)##### Using cuda enabled ##### - echo -e "${GREEN}Cuda enabled ${NC}" - USE_CUDA=ON - ;; - m)##### Using MPI enabled ##### - echo -e "${GREEN}MPI enabled ${NC}" - USE_MPI=ON - ;; - v) ##### printing full output of make ##### - echo -e "${YELLOW}printing make with details.${NC}" - VERBOSE=ON - ;; - s) ##### Passing Blas vendor with mkl ##### - echo -e "${YELLOW}MKL as a Blas vendor${NC}" - BLAS_VENDOR="Intel10_64lp" - ;; - \?) ##### Error unknown option ##### - echo "Option $OPTARG parameter is unknown, please -h for help" - exit 1 - ;; - :) ##### Error in an option ##### - echo "Option $OPTARG requires parameter(s)" - exit 0 - ;; - h) ##### Prints the help ##### - echo "Usage of $(basename "$0"):" - echo "" - printf "%20s %s\n" "-i [path] :" "specify installation path, default = ${PWD}/installdir/_deps/" - printf "%20s %s\n" "-t :" "to enable building tests." - printf "%20s %s\n" "-e :" "to enable building examples." - printf "%20s %s\n" "-H :" "to enable using HiCMA." - printf "%20s %s\n" "-c :" "to enable using CUDA." - printf "%20s %s\n" "-m :" "to enable using MPI." - printf "%20s %s\n" "-v :" "to enable verbose printings." - printf "%20s %s\n" "-d :" "to enable debug mode." - printf "%20s %s\n" "-s :" "to manually pass MKL as your blas vendor." - printf "%20s %s\n" "-h :" "Help." - echo "" - exit 1 - ;; - esac -done - -if [ -z "$BUILDING_TESTS" ]; then - BUILDING_TESTS="OFF" - echo -e "${RED}Building tests disabled.${NC}" -fi - -if [ -z "$BUILDING_EXAMPLES" ]; then - BUILDING_EXAMPLES="OFF" - echo -e "${RED}Building examples disabled.${NC}" -fi - -echo -e "${BLUE}Installation path set to $INSTALL_PREFIX.${NC}" - -if [ -z "$USING_HiCMA" ]; then - echo -e "${RED}Using HiCMA is disabled.${NC}" -fi - -if [ -z "$USE_CUDA" ]; then - USE_CUDA="OFF" - echo -e "${RED}Using CUDA disabled${NC}" -fi - -if [ -z "$USE_MPI" ]; then - USE_MPI="OFF" - echo -e "${RED}Using MPI disabled${NC}" -fi - -echo "" -echo -e "${YELLOW}Use -h to print the usages of exageostat-cpp flags.${NC}" -echo "" -rm -rf bin/ -mkdir -p bin/installdir - -cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DEXAGEOSTAT_INSTALL_PREFIX="${INSTALL_PREFIX}" \ - -DEXAGEOSTAT_BUILD_TESTS="${BUILDING_TESTS}" \ - -DEXAGEOSTAT_BUILD_EXAMPLES="${BUILDING_EXAMPLES}" \ - -DEXAGEOSTAT_USE_HICMA="${USING_HiCMA}" \ - -DCMAKE_VERBOSE_MAKEFILE:BOOL=${VERBOSE} \ - -DUSE_CUDA="${USE_CUDA}" \ - -DUSE_MPI="${USE_MPI}" \ - -DBLA_VENDOR="${BLAS_VENDOR}" \ - -H"${PROJECT_SOURCE_DIR}" \ - -B"${PROJECT_SOURCE_DIR}/bin" \ - -G "Unix Makefiles" diff --git a/configure b/configure new file mode 100755 index 00000000..5e6a92f2 --- /dev/null +++ b/configure @@ -0,0 +1,274 @@ +#! /bin/sh +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file configure +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @author David Helmy +# @date 2024-02-04 + +# Set variables and default values +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +INSTALL_PREFIX=$PWD/installdir/_deps + +# Function to install CMake from source +install_cmake() { + echo "CMake not found. Installing CMake from source..." + + # Create a temporary directory for building CMake + temp_dir=$(mktemp -d) + cd "$temp_dir" || exit 1 + + # Download CMake source code + wget https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1.tar.gz + + # Extract the source code + tar -xzvf cmake-3.28.1.tar.gz + + # Enter the extracted directory + cd cmake-3.28.1 || exit 1 + + # Configure, build, and install CMake to the specified location + ./bootstrap --prefix="$INSTALL_PREFIX" --parallel=2 -- -DCMAKE_USE_OPENSSL=OFF + make -j 2 + sudo make install + + # Clean up + cd "$temp_dir" || exit 1 + rm -rf "$temp_dir" +} + +# shellcheck disable=SC2164 +cd "$(dirname "$0")" +# Get the operating system type using uname +OS_TYPE=$(uname) + +if [ "$OS_TYPE" = "darwin"* ]; then + ABSOLUTE_PATH=$([[ $1 == /* ]] && echo "$1" || echo "$PWD/${1#./}") +else + ABSOLUTE_PATH=$(dirname "$(realpath "$0")") +fi + +BUILDING_TESTS="OFF" +BUILDING_HEAVY_TESTS="OFF" +BUILDING_EXAMPLES="OFF" +USING_HiCMA="OFF" +VERBOSE="OFF" +USE_CUDA="OFF" +USE_MPI="OFF" +BLAS_VENDOR="" +PACKAGE="OFF" +RUNTIME_TYPE="starpu" +SHOW_WARNINGS="OFF" +COMPILE_FLAGS="-Wl,--no-as-needed -w -fpic" +DEVELOPER_WARNINGS="-Wno-dev" + +for arg in "$@" +do + case $arg in + --use-mkl) + echo "${GREEN}MKL as a BLA vendor${NC}" + BLAS_VENDOR="Intel10_64lp" + ;; + --use-parsec) + echo "${GREEN}Parsec as a runtime${NC}" + RUNTIME_TYPE="parsec" + ;; + *) + # Collect non-option arguments as a space-delimited string + params="$params $arg" + ;; + esac +done + +# Reset positional parameters to collected non-option arguments +eval set -- $params + +# Parse command line options +while getopts ":tevhHi:cmpTwr" opt; do + case $opt in + i) ##### Define installation path ##### + echo "${YELLOW}Installation path set to $OPTARG.${NC}" + INSTALL_PREFIX=$OPTARG + ;; + t) ##### Building tests enabled ##### + echo "${GREEN}Building tests enabled.${NC}" + BUILDING_TESTS="ON" + ;; + T) ##### Building heavy tests enabled ##### + echo "${GREEN}Building heavy tests enabled.${NC}" + BUILDING_HEAVY_TESTS="ON" + ;; + e) ##### Building examples enabled ##### + echo "${GREEN}Building examples enabled.${NC}" + BUILDING_EXAMPLES="ON" + ;; + H) ##### Using HiCMA ##### + echo "${GREEN}Using HiCMA.${NC}" + USING_HiCMA="ON" + ;; + c) ##### Using cuda enabled ##### + echo "${GREEN}Cuda enabled ${NC}" + USE_CUDA="ON" + ;; + m) ##### Using MPI enabled ##### + echo "${GREEN}MPI enabled ${NC}" + USE_MPI="ON" + ;; + v) ##### printing full output of make ##### + echo "${GREEN}printing make with details.${NC}" + VERBOSE="ON" + ;; + p) ##### Enabling packaging system for distribution ##### + echo "${GREEN}CPACK enabled${NC}" + PACKAGE=ON + ;; + w) ##### Enable showing all the warnings ##### + echo "${GREEN}Showing Warnings is enabled${NC}" + SHOW_WARNINGS="ON" + ;; + r) ##### Enable R and Rcpp support ##### + echo "${GREEN}R is enabled${NC}" + USE_R="ON" + ;; + \?) ##### Error unknown option ##### + echo "Option $OPTARG parameter is unknown, please -h for help" + exit 1 + ;; + :) ##### Error in an option ##### + echo "Option $OPTARG requires parameter(s)" + exit 0 + ;; + h) ##### Prints the help ##### + echo "Usage of $(basename "$0"):" + echo "" + printf "%20s %s\n" "--use-mkl :" "to use MKL as a BLA vendor." + printf "%20s %s\n" "--use-parsec :" "to use parsec runtime." + printf "%20s %s\n" "-i [path] :" "specify installation path, default = ${PWD}/installdir/_deps/" + printf "%20s %s\n" "-t :" "to enable building tests." + printf "%20s %s\n" "-T :" "to enable building heavy tests." + printf "%20s %s\n" "-e :" "to enable building examples." + printf "%20s %s\n" "-H :" "to enable using HiCMA." + printf "%20s %s\n" "-c :" "to enable using CUDA." + printf "%20s %s\n" "-m :" "to enable using MPI." + printf "%20s %s\n" "-v :" "to enable verbose printings." + printf "%20s %s\n" "-p :" "to enable a packaging system for distribution." + printf "%20s %s\n" "-w :" "to enable showing warnings." + printf "%20s %s\n" "-r :" "to enable R support" + printf "%20s %s\n" "-h :" "Help." + echo "" + exit 1 + ;; + esac +done + +if [ -z "$BUILDING_TESTS" ]; then + BUILDING_TESTS="OFF" + echo "${RED}Building tests disabled.${NC}" +fi + +if [ -z "$BUILDING_EXAMPLES" ]; then + BUILDING_EXAMPLES="OFF" + echo "${RED}Building examples disabled.${NC}" +fi + +if [ -z "$USING_HiCMA" ]; then + echo "${RED}Using HiCMA is disabled.${NC}" +fi + +if [ -z "$USE_CUDA" ]; then + USE_CUDA="OFF" + echo "${RED}Using CUDA disabled${NC}" +fi + +if [ -z "$USE_MPI" ]; then + USE_MPI="OFF" + echo "${RED}Using MPI disabled${NC}" +fi + +if [ "$SHOW_WARNINGS" = "ON" ]; then + COMPILE_FLAGS="$COMPILE_FLAGS -W" + DEVELOPER_WARNINGS="" +elif [ "$SHOW_WARNINGS" = "OFF" ]; then + COMPILE_FLAGS="$COMPILE_FLAGS -w" +fi + +if [ -z "$USE_R" ]; then + USE_R="OFF" + echo "${RED}Using R is disabled${NC}" +fi + +echo "${BLUE}Installation path set to $INSTALL_PREFIX.${NC}" +echo "" +echo "${YELLOW}Use -h to print the usages of exageostat-cpp flags.${NC}" +echo "" + +# cleaning bin +rm -rf bin/ +mkdir bin/ + +# Check if cmake is installed +if command -v cmake /dev/null 2>&1; then + # Save the installation directory to the variable + cmake_install_dir=$(command -v cmake | xargs dirname) + echo "CMake is installed in: $cmake_install_dir" + cmake_command_bin=cmake +elif [ -x "/Applications/CMake.app/Contents/bin/cmake" ]; then + echo "CMake found in /Applications/CMake.app/Contents/bin/cmake." + cmake_install_dir="/Applications/CMake.app/Contents/bin" + cmake_command_bin="${cmake_install_dir}/cmake" +else + echo "Installing CMake from source" + mkdir "${ABSOLUTE_PATH}/inst/_deps/" + install_dir="${ABSOLUTE_PATH}/inst/_deps/" + install_cmake "$install_dir" + cmake_command_bin="${ABSOLUTE_PATH}/inst/_deps/bin/cmake" +fi + +"$cmake_command_bin" "$DEVELOPER_WARNINGS" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_BUILD_TYPE=RELEASE \ + -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \ + -DBUILD_TESTS="${BUILDING_TESTS}" \ + -DBUILD_HEAVY_TESTS="${BUILDING_HEAVY_TESTS}" \ + -DBUILD_EXAMPLES="${BUILDING_EXAMPLES}" \ + -DUSE_HICMA="${USING_HiCMA}" \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=${VERBOSE} \ + -DUSE_CUDA="${USE_CUDA}" \ + -DUSE_MPI="${USE_MPI}" \ + -DUSE_R="${USE_R}" \ + -DBLA_VENDOR="${BLAS_VENDOR}" \ + -DCREATE_PACKAGE="${PACKAGE}" \ + -DRUNTIME_TYPE="${RUNTIME_TYPE}" \ + -DBUILD_SHARED_LIBS=OFF \ + -H"${ABSOLUTE_PATH}" \ + -B"${ABSOLUTE_PATH}/bin" \ + -G "Unix Makefiles" \ + -DCMAKE_CXX_FLAGS_DEBUG="$COMPILE_FLAGS" \ + -DCMAKE_CXX_FLAGS_RELEASE="$COMPILE_FLAGS" + +if [ "$USE_R" = "ON" ]; then + # Change to the bin directory, or exit if it doesn't exist. + cd bin/ || { + echo "Error: bin directory not found." + exit 1 + } + + # Clean the directory and build the code with the specified options. + "$cmake_command_bin" --build . -j 10 + + if [ "$OS_TYPE" = "darwin"* ]; then + cp "${ABSOLUTE_PATH}/bin/src/libExaGeoStatCPP.dylib" "${ABSOLUTE_PATH}/src/ExaGeoStatCPP.so" || echo "Failed: libExaGeoStatCPP.dylib -> src" + else + cp "${ABSOLUTE_PATH}/bin/src/libExaGeoStatCPP.so" "${ABSOLUTE_PATH}/src/ExaGeoStatCPP.so" || echo "Failed: libExaGeoStatCPP.so -> src" + fi + + rm -rf "${ABSOLUTE_PATH:?}/bin/"* + +fi diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 39b38388..28885b94 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief Configures and generates documentation using Doxygen. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-03-12 diff --git a/docs/ExaGeoStat-CPP-Manual.pdf b/docs/ExaGeoStat-CPP-Manual.pdf new file mode 100644 index 00000000..bb2a09ab Binary files /dev/null and b/docs/ExaGeoStat-CPP-Manual.pdf differ diff --git a/docs/ExaGeoStat-R-Interface-Manual.pdf b/docs/ExaGeoStat-R-Interface-Manual.pdf new file mode 100644 index 00000000..940ad14d Binary files /dev/null and b/docs/ExaGeoStat-R-Interface-Manual.pdf differ diff --git a/docs/ExaGeoStatCPP-handout.png b/docs/ExaGeoStatCPP-handout.png new file mode 100644 index 00000000..1bd401bc Binary files /dev/null and b/docs/ExaGeoStatCPP-handout.png differ diff --git a/docs/config.in b/docs/config.in index 0cafddd5..70c8be38 100644 --- a/docs/config.in +++ b/docs/config.in @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "ExaGeoStat CPP" +PROJECT_NAME = "ExaGeoStatCPP" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -44,7 +44,7 @@ PROJECT_NUMBER = # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems." +PROJECT_BRIEF = "ExaGeoStatCPP is a parallel high performance unified framework for geostatistics on manycore systems." # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 @@ -68,7 +68,7 @@ OUTPUT_DIRECTORY = "bin" # performance problems for the file system. # The default value is: NO. -CREATE_SUBDIRS = NO +CREATE_SUBDIRS = YES # If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII # characters to appear in the names of generated files. If set to NO, non-ASCII @@ -162,7 +162,7 @@ FULL_PATH_NAMES = NO # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = "@CMAKE_SOURCE_DIR@" +STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which @@ -367,7 +367,7 @@ DISTRIBUTE_GROUP_DOC = NO # is disabled and one has to add nested compounds explicitly via \ingroup. # The default value is: NO. -GROUP_NESTED_COMPOUNDS = YES +GROUP_NESTED_COMPOUNDS = NO # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that @@ -524,7 +524,7 @@ INTERNAL_DOCS = NO # and Mac users are advised to set this option to NO. # The default value is: system dependent. -CASE_SENSE_NAMES = NO +CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES, the @@ -790,10 +790,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ../src/ \ ../inst/ - - - +INPUT = "../inst/include" + ../README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -946,7 +943,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = "@CMAKE_CURRENT_SOURCE_DIR@/index.md" +USE_MDFILE_AS_MAINPAGE = ../README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing @@ -959,7 +956,7 @@ USE_MDFILE_AS_MAINPAGE = "@CMAKE_CURRENT_SOURCE_DIR@/index.md" # also VERBATIM_HEADERS is set to NO. # The default value is: NO. -SOURCE_BROWSER = YES +SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. diff --git a/exageostatcppConfig.cmake.in b/exageostatcppConfig.cmake.in deleted file mode 100644 index b36a3e51..00000000 --- a/exageostatcppConfig.cmake.in +++ /dev/null @@ -1,67 +0,0 @@ - -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -# All rights reserved. -# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -# defined since 2.8.3 -if (CMAKE_VERSION VERSION_LESS 2.8.3) - get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) -endif () - -# Compute the installation prefix relative to this file. -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -if (_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") -endif () - -set(USE_CUDA "@USE_CUDA@") -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules/cmake) - -set(ENV{PKG_CONFIG_PATH} "${_IMPORT_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") -include_directories(${_IMPORT_PREFIX}/include) -link_directories(${_IMPORT_PREFIX}/lib) -set(BLA_PREFER_PKGCONFIG "ON") - -if (USE_CUDA) - message("-- Exageostat-cpp built CUDA Support") - find_package(CUDAToolkit REQUIRED) - find_package(BLAS REQUIRED) - find_package(blaspp REQUIRED) - unset(BLA_VENDOR) - find_package(LAPACK REQUIRED) -else () - message("-- Exageostat-cpp built x86 Support") - set(gpu_backend CACHE "none" FORCE) - find_package(blaspp REQUIRED) - find_package(lapackpp REQUIRED) -endif () - -# Add component-configs. -include("${CMAKE_CURRENT_LIST_DIR}/exageostat-cppConfig.cmake") - -# Compute the installation prefix relative to this file. -get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) -if (_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") -endif () -set(exageostatcpp_LIBRARIES exageostatcpp) -set(exageostatcpp_LIBRARY_DIRS "${_IMPORT_PREFIX}/lib") -set(exageostatcpp_INCLUDE_DIRS "${_IMPORT_PREFIX}/include") - -find_package_handle_standard_args(exageostatcpp - NAME_MISMATCHED - REQUIRED_VARS exageostatcpp_INCLUDE_DIRS exageostatcpp_LIBRARY_DIRS exageostatcpp_LIBRARIES - VERSION_VAR exageostatcpp_VERSION - ) - -# Cleanup temporary variables. -set(_IMPORT_PREFIX) -if (CMAKE_VERSION VERSION_LESS 2.8.3) - set(CMAKE_CURRENT_LIST_DIR) -endif () diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fd6d1ce3..450c6d91 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,15 +1,18 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief Includes subdirectories for different modules of the ExaGeoStat software package. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy -# @date 2023-01-31 +# @date 2024-02-24 # Include subdirectories for end-to-end module, configurations module and data-generators module. -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/end-to-end) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/configurations) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/data-generators) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/data-loader) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/descriptors) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/end-to-end) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hardware) diff --git a/examples/configurations/CMakeLists.txt b/examples/configurations/CMakeLists.txt index 769ba295..e0ea9f99 100644 --- a/examples/configurations/CMakeLists.txt +++ b/examples/configurations/CMakeLists.txt @@ -1,16 +1,18 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @brief Defines an executable and links it with the ExaGeoStat library and other libraries. -# @version 1.0.0 +# @brief Defines an executables and links them with the ExaGeoStat library and other libraries. +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-01-31 -# Define an executable named "Example_Synthetic_Data_Configurations". -add_executable(Example_Synthetic_Data_Configurations ${CMAKE_CURRENT_SOURCE_DIR}/ConfigurationModule.cpp) +# Define an executable named "Example_Configurations". +add_executable(Example_Configurations_Setup ${CMAKE_CURRENT_SOURCE_DIR}/SetupConfigurations.cpp) +add_executable(Example_Different_Configurations_Running ${CMAKE_CURRENT_SOURCE_DIR}/RunningWithDifferentConfigurations.cpp) # Link the executable with the ExaGeoStat library and other libraries. -target_link_libraries(Example_Synthetic_Data_Configurations ${PROJECT_NAME}_INTERFACE) \ No newline at end of file +target_link_libraries(Example_Configurations_Setup ${PROJECT_NAME}_INTERFACE) +target_link_libraries(Example_Different_Configurations_Running ${PROJECT_NAME}_INTERFACE) \ No newline at end of file diff --git a/examples/configurations/RunningWithDifferentConfigurations.cpp b/examples/configurations/RunningWithDifferentConfigurations.cpp new file mode 100644 index 00000000..4ff37b1a --- /dev/null +++ b/examples/configurations/RunningWithDifferentConfigurations.cpp @@ -0,0 +1,74 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file RunningWithDifferentConfigurations.cpp + * @brief Demonstrates running ExaGeoStat with various configurations. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-04 +**/ + +#include +#include + +using namespace exageostat::api; +using namespace exageostat::configurations; + +/** + * @brief Main entry point for the Data Generation & Data Modeling program. + * @details Initializes configuration settings, loads data, and performs data modeling with ExaGeoStat. + * The program demonstrates running ExaGeoStat with two different sets of configurations to showcase the software's capability in handling various statistical models and computational settings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ +int main() { + + // Create a new configurations object. + Configurations configurations; + int N = 16; + configurations.SetProblemSize(N); + configurations.SetKernelName("UnivariateMaternStationary"); + configurations.SetDenseTileSize(9); + configurations.SetMaxMleIterations(10); + configurations.SetTolerance(4); + std::vector lb{0.1, 0.1, 0.1}; + configurations.SetLowerBounds(lb); + + std::vector ub{5, 5, 5}; + configurations.SetUpperBounds(ub); + + std::vector initial_theta{1, 0.1, 0.5}; + configurations.SetInitialTheta(initial_theta); + + // Initialize the ExaGeoStat Hardware + ExaGeoStatHardware hardware(configurations.GetComputation(), configurations.GetCoresNumber(),configurations.GetGPUsNumbers()); + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations, data); + + LOGGER("") + LOGGER("ANOTHER CONFIGURATIONS\n") + // Create a new configurations object. + Configurations configurations2; + N = 10; + configurations2.SetProblemSize(N); + configurations2.SetKernelName("UnivariateMaternStationary"); + configurations2.SetDenseTileSize(5); + configurations2.SetMaxMleIterations(2); + configurations2.SetTolerance(3); + configurations2.SetLowerBounds(lb); + configurations2.SetUpperBounds(ub); + configurations2.SetInitialTheta(initial_theta); + + // Load data by either read from file or create synthetic data. + ExaGeoStat::ExaGeoStatLoadData(configurations2, data); + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations2, data); + + return 0; +} diff --git a/examples/configurations/ConfigurationModule.cpp b/examples/configurations/SetupConfigurations.cpp similarity index 82% rename from examples/configurations/ConfigurationModule.cpp rename to examples/configurations/SetupConfigurations.cpp index 975b0897..284500d6 100644 --- a/examples/configurations/ConfigurationModule.cpp +++ b/examples/configurations/SetupConfigurations.cpp @@ -1,22 +1,20 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** -* @file ConfigurationsMain.cpp +* @file SetupConfigurations.cpp * @brief Demonstrates how to use the Configurations class from the ExaGeoStat software package. * @details This file demonstrates how to use the Configurations class from the ExaGeoStat software package -* to obtain user-defined configurations for generating synthetic data. -* @version 1.0.0 +* to obtain user-defined configurations. +* @version 1.1.0 * @author Mahmoud ElKarargy -* @date 2023-01-31 +* @date 2024-02-04 * **/ -#include - -#include +#include #include using namespace std; @@ -26,22 +24,20 @@ using namespace exageostat::configurations; /** * @brief The main function of the program. - * - * This function demonstrates how to use the SyntheticDataConfigurations class from the ExaGeoStat software package - * to obtain user-defined configurations for generating synthetic data. - * + * @details This example demonstrates how to use the Configurations class from the ExaGeoStat software package + * to obtain user-defined configurations. * @param[in] argc The number of command line arguments. * @param[in] argv The command line arguments. - * @return The status code of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { - // Create an instance of the SyntheticDataConfigurations class with user-defined configurations. + // Create an instance of the Configurations class with user-defined configurations. Configurations configurations; configurations.InitializeArguments(argc, argv); LOGGER("** These are some examples of the common arguments needed between all modules of ExaGeoStat **") - // Obtain user-defined configurations and print them to the console. int n = configurations.GetProblemSize(); if (n != 0) { @@ -101,5 +97,6 @@ int main(int argc, char **argv) { } VERBOSE("VERBOSE ACTIVATED") + return 0; } \ No newline at end of file diff --git a/examples/data-generators/CMakeLists.txt b/examples/data-generators/CMakeLists.txt index d90f9abe..99324d4d 100644 --- a/examples/data-generators/CMakeLists.txt +++ b/examples/data-generators/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief CMake file for building the Example_Synthetic_Data_Generation executable. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-03-04 diff --git a/examples/data-generators/SyntheticDataGeneration.cpp b/examples/data-generators/SyntheticDataGeneration.cpp index 1c4323df..e4df4645 100644 --- a/examples/data-generators/SyntheticDataGeneration.cpp +++ b/examples/data-generators/SyntheticDataGeneration.cpp @@ -1,34 +1,30 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file SyntheticLocationsGeneration.cpp * @brief This file contains the main function for generating synthetic Locations for ExaGeoStat - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-03-04 + * @date 2024-02-04 **/ -#include - #include -using namespace std; - -using namespace exageostat::configurations; using namespace exageostat::generators; using namespace exageostat::common; -using namespace exageostat::hardware; using namespace exageostat::kernels; +using namespace exageostat::configurations; /** * @brief The main function of the program. * @details This function generates synthetic data for ExaGeoStat using the provided command line arguments. * @param[in] argc The number of command line arguments. * @param[in] argv The command line arguments. - * @return The status code of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { @@ -39,18 +35,19 @@ int main(int argc, char **argv) { synthetic_data_configurations.InitializeDataGenerationArguments(); // initialize ExaGeoStat Hardware. - auto hardware = ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), - synthetic_data_configurations.GetCoresNumber(), - synthetic_data_configurations.GetGPUsNumbers()); + ExaGeoStatHardware hardware(synthetic_data_configurations.GetComputation(), + synthetic_data_configurations.GetCoresNumber(), + synthetic_data_configurations.GetGPUsNumbers()); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(synthetic_data_configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + synthetic_data_configurations.GetKernelName(), synthetic_data_configurations.GetTimeSlot()); // Create a unique pointer to a DataGenerator object - unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( + std::unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( synthetic_data_configurations); // Initialize the locations of the generated data - auto data = *synthetic_generator->CreateData(synthetic_data_configurations, hardware, *pKernel); + auto data = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); // Define a struct to hold pointers to the x, y, and z coordinates of the generated data struct DataPointers { double *x; @@ -59,9 +56,9 @@ int main(int argc, char **argv) { } data_pointers{}; // Set the pointers in the DataPointers struct to the location coordinates of the generated data - data_pointers.x = data.GetLocations()->GetLocationX(); - data_pointers.y = data.GetLocations()->GetLocationY(); - data_pointers.z = data.GetLocations()->GetLocationZ(); + data_pointers.x = data->GetLocations()->GetLocationX(); + data_pointers.y = data->GetLocations()->GetLocationY(); + data_pointers.z = data->GetLocations()->GetLocationZ(); // Print the generated location coordinates LOGGER("Generated Data ...") @@ -76,10 +73,11 @@ int main(int argc, char **argv) { if (synthetic_data_configurations.GetDimension() != Dimension2D) { LOGGER_PRECISION(" Z: " << data_pointers.z[i], 18) } - LOGGER_PRECISION(" Measurements: " << ((double *)data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, exageostat::common::DESCRIPTOR_Z).chameleon_desc->mat)[i] << "\n" , 18) + LOGGER_PRECISION(" Measurements: " << ((double *) data->GetDescriptorData()->GetDescriptor( + exageostat::common::CHAMELEON_DESCRIPTOR, exageostat::common::DESCRIPTOR_Z).chameleon_desc->mat)[i] + << "\n", 18) } delete pKernel; - return 0; } \ No newline at end of file diff --git a/examples/data-generators/SyntheticLocationsGeneration.cpp b/examples/data-generators/SyntheticLocationsGeneration.cpp deleted file mode 100644 index cb9b7880..00000000 --- a/examples/data-generators/SyntheticLocationsGeneration.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file SyntheticLocationsGeneration.cpp - * @brief This file contains the main function for generating synthetic Locations for ExaGeoStat - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @date 2023-03-04 -**/ - -#include - -#include -#include - -using namespace std; - -using namespace exageostat::configurations; -using namespace exageostat::generators; -using namespace exageostat::common; -using namespace exageostat::hardware; - -/** - * @brief The main function of the program. - * @details This function generates synthetic data for ExaGeoStat using the provided command line arguments. - * @param[in] argc The number of command line arguments. - * @param[in] argv The command line arguments. - * @return The status code of the program. - */ - -int main(int argc, char **argv) { - - // Create a new synthetic_data_configurations object with the provided command line arguments - Configurations synthetic_data_configurations; - synthetic_data_configurations.InitializeArguments(argc, argv); - - // initialize ExaGeoStat Hardware. - auto hardware = ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), - synthetic_data_configurations.GetCoresNumber(), - synthetic_data_configurations.GetGPUsNumbers()); - - // Create a unique pointer to a DataGenerator object - unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( - synthetic_data_configurations); - - // Initialize the locations of the generated data - auto *locations = synthetic_generator->CreateLocationsData(synthetic_data_configurations); - - // Define a struct to hold pointers to the x, y, and z coordinates of the generated data - struct DataPointers { - double *x; - double *y; - double *z; - } data_pointers{}; - - // Set the pointers in the DataPointers struct to the location coordinates of the generated data - data_pointers.x = locations->GetLocationX(); - data_pointers.y = locations->GetLocationY(); - data_pointers.z = locations->GetLocationZ(); - - // Print the generated location coordinates - LOGGER("Generated Locations are .. ") - int timeSlot; - if (synthetic_data_configurations.GetDimension() != DimensionST) { - timeSlot = 1; - } else { - timeSlot = synthetic_data_configurations.GetTimeSlot(); - } - for (auto i = 0; i < synthetic_data_configurations.GetProblemSize() * timeSlot; i++) { - LOGGER_PRECISION("X: " << data_pointers.x[i] << " Y: " << data_pointers.y[i], 18) - if (synthetic_data_configurations.GetDimension() != Dimension2D) { - LOGGER_PRECISION(" Z: " << data_pointers.z[i], 18) - } - LOGGER("\n") - } - return 0; -} \ No newline at end of file diff --git a/examples/data-loader/CMakeLists.txt b/examples/data-loader/CMakeLists.txt new file mode 100644 index 00000000..4e1c4ae5 --- /dev/null +++ b/examples/data-loader/CMakeLists.txt @@ -0,0 +1,16 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @brief Defines an executables and link it with the ExaGeoStat library and other libraries. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-14 + +# Define the target executable +add_executable(Example_CSV_Loader ${CMAKE_CURRENT_SOURCE_DIR}/CSVLoader.cpp) + +# Link the target executable with the project and any additional libraries +target_link_libraries(Example_CSV_Loader PRIVATE ${PROJECT_NAME}_INTERFACE) diff --git a/examples/data-loader/CSVLoader.cpp b/examples/data-loader/CSVLoader.cpp new file mode 100644 index 00000000..701f3b10 --- /dev/null +++ b/examples/data-loader/CSVLoader.cpp @@ -0,0 +1,79 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file CSVLoader.cpp + * @brief Example of the CSVLoader class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-18 +**/ + +#include + +using namespace std; + +using namespace exageostat::kernels; +using namespace exageostat::generators; +using namespace exageostat::dataLoader::csv; +using namespace exageostat::configurations; + +/** + * @brief Main entry point demonstrating the usage of CSVLoader in ExaGeoStat. + * @details The program demonstrates initializing configuration settings, creating synthetic data, setting up ExaGeoStat hardware, initializing kernels, and then using the + * CSVLoader to read spatial and measurement data from a CSV file. The spatial dimensions can be 2D or 3D, and the data read includes locations (X, Y, [Z]) and measurements. + * @param argc The number of command-line arguments. + * @param argv The array of command-line arguments. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ + +int main(int argc, char **argv) { + + LOGGER("** Example of CSV Loader **") + + // Create and Initialize a new configurations object. + Configurations configurations; + configurations.InitializeArguments(argc, argv); + + // Generate Data and Log it into file + configurations.SetLogger(true); + configurations.InitializeDataGenerationArguments(); + + // Initialize ExaGeoStat Hardware and Kernel. + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), + configurations.GetGPUsNumbers()); + + Kernel *kernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), configurations.GetTimeSlot()); + int kernel_variables = kernel->GetVariablesNumber(); + + // Create a unique pointer to a DataGenerator object and generate data + configurations.SetIsSynthetic(true); + unique_ptr> synthetic_generator = DataGenerator::CreateGenerator(configurations); + auto data = synthetic_generator->CreateData(configurations, *kernel); + + // Read csv file using data loader + vector measurements_vector; + vector x_locations; + vector y_locations; + vector z_locations; + + auto loader = CSVLoader::GetInstance(); + loader->ReadData(configurations, measurements_vector, x_locations, y_locations, z_locations, kernel_variables); + + // Print loaded data + LOGGER("Data Loaded:") + for (int i = 0; i < x_locations.size(); i++) { + LOGGER_PRECISION("X: " << x_locations[i] << " Y: " << y_locations[i], 18) + if (configurations.GetDimension() != exageostat::common::Dimension2D) { + LOGGER_PRECISION(" Z: " << z_locations[i], 18) + } + LOGGER_PRECISION(" z: " << measurements_vector[i] << "\n", 18) + } + + delete kernel; + return 0; +} diff --git a/examples/descriptors/CMakeLists.txt b/examples/descriptors/CMakeLists.txt new file mode 100644 index 00000000..eb3cf6c2 --- /dev/null +++ b/examples/descriptors/CMakeLists.txt @@ -0,0 +1,24 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @brief Defines an executables and links them with the ExaGeoStat library and other libraries. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-14 + +# Define the target executable +add_executable(Example_Chameleon_Descriptor ChameleonDescriptor.cpp) + +if (USE_HICMA) + add_executable(Example_Hicma_Descriptor HicmaDescriptor.cpp) + add_executable(Example_Chameleon_Hicma_Converter ChameleonToHicmaConverter.cpp) + + target_link_libraries(Example_Hicma_Descriptor PRIVATE ${PROJECT_NAME}_INTERFACE) + target_link_libraries(Example_Chameleon_Hicma_Converter PRIVATE ${PROJECT_NAME}_INTERFACE) +endif () + +# Link the target executable with the project and any additional libraries +target_link_libraries(Example_Chameleon_Descriptor PRIVATE ${PROJECT_NAME}_INTERFACE) \ No newline at end of file diff --git a/examples/descriptors/ChameleonDescriptor.cpp b/examples/descriptors/ChameleonDescriptor.cpp new file mode 100644 index 00000000..929403c5 --- /dev/null +++ b/examples/descriptors/ChameleonDescriptor.cpp @@ -0,0 +1,101 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ChameleonDescriptor.cpp + * @brief Example file for the Chameleon descriptor. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-14 +**/ + +#include +#include +#include + +using namespace std; + +using namespace exageostat::common; +using namespace exageostat::kernels; +using namespace exageostat::dataunits; +using namespace exageostat::configurations; + +/** + * @brief Main entry point for demonstrating the use of Chameleon Descriptor in ExaGeoStat. + * @details Initializes configurations, hardware, data, and kernels. Demonstrates the setup and usage of a Chameleon descriptor for handling matrices, including setting up matrix + * dimensions, tile sizes, distribution grids, and memory management. The example showcases how to interact with the descriptor to access and manage data efficiently for computational purposes. + * @param argc Number of command-line arguments. + * @param argv Array of command-line argument strings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ +int main(int argc, char **argv) { + + LOGGER("** Example of Chameleon Descriptor **") + + // Initialize Configuration + Configurations configuration; + configuration.InitializeArguments(argc, argv); + + // Initialize Hardware and Data + auto hardware = ExaGeoStatHardware(configuration.GetComputation(), configuration.GetCoresNumber(), + configuration.GetGPUsNumbers()); + unique_ptr> data = make_unique>(); + Kernel *kernel = exageostat::plugins::PluginRegistry>::Create( + configuration.GetKernelName(), configuration.GetTimeSlot()); + + // Get arguments for Descriptors Initialization + int kernel_variables_number = kernel->GetVariablesNumber(); + int config_problem_size = configuration.GetProblemSize(); + int config_full_problem_size = config_problem_size * kernel_variables_number; + int config_dts = configuration.GetDenseTileSize(); + int config_p_grid = configuration.GetPGrid(); + int config_q_grid = configuration.GetQGrid(); + bool config_is_OOC = configuration.GetIsOOC(); + + // Randomly Initialized Matrix of Data + std::vector matrix(config_problem_size * config_problem_size); + for (int i = 0; i < config_problem_size; ++i) { + matrix[i] = i; + } + + // Set Data Descriptor + data->SetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C, config_is_OOC, matrix.data(), EXAGEOSTAT_REAL_DOUBLE, + config_dts, + config_dts, + config_dts * config_dts, config_full_problem_size, config_full_problem_size, 0, 0, + config_full_problem_size, + config_full_problem_size, config_p_grid, config_q_grid); + + auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; + + //Print Descriptor Parameters + LOGGER("** Descriptor Parameters:") + LOGGER(" Problem Size: " << CHAM_descriptorC->m) + LOGGER(" Dense Tile Size: " << CHAM_descriptorC->mb) + + LOGGER(" Entire Number of Rows :" << CHAM_descriptorC->lm) + LOGGER(" Entire Number of Columns :" << CHAM_descriptorC->ln) + + LOGGER(" Number of Sub-matrix Tile Rows: " << CHAM_descriptorC->mt) + LOGGER(" Number of Sub-matrix Tile Columns: " << CHAM_descriptorC->nt) + + LOGGER(" Number of Rows of 2D distribution grid: " << CHAM_descriptorC->p) + LOGGER(" Number of Rows of 2D distribution grid: " << CHAM_descriptorC->q) + + LOGGER(" Is Matrix Not Fit in Memory: " << CHAM_descriptorC->ooc) + LOGGER(" Size including Padding: " << CHAM_descriptorC->bsiz) + + // Print Data Matrix of Descriptor + LOGGER("** Data in Matrix:") + LOGGER_2("", 0) + auto *data_mat = (double *) CHAM_descriptorC->mat; + for (int i = 0; i < config_problem_size; ++i) { + LOGGER_PRECISION_1(" " << data_mat[i], 0) + } + + delete kernel; + return 0; +} diff --git a/examples/descriptors/ChameleonToHicmaConverter.cpp b/examples/descriptors/ChameleonToHicmaConverter.cpp new file mode 100644 index 00000000..2806ae75 --- /dev/null +++ b/examples/descriptors/ChameleonToHicmaConverter.cpp @@ -0,0 +1,126 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ChameleonDescriptor.cpp + * @brief Example file for the Chameleon to Hicma Converter. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-14 +**/ + +#include +#include +#include + +using namespace std; + +using namespace exageostat::common; +using namespace exageostat::kernels; +using namespace exageostat::dataunits; +using namespace exageostat::configurations; + +/** + * @brief Main entry point for the Chameleon to Hicma descriptor conversion example. + * @details Demonstrates the process of initializing ExaGeoStat configurations, setting up hardware, creating and initializing a kernel, and then generating and setting up a + * Chameleon descriptor. The example then showcases the conversion of the Chameleon descriptor to a Hicma descriptor, detailing the changes and continuity in descriptor + * attributes and matrix data through the conversion process. + * @param argc Number of command-line arguments. + * @param argv Array of command-line argument strings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ + +int main(int argc, char **argv) { + + LOGGER("** Example of Chameleon To Hicma Converter **") + + // Initialize Configuration + Configurations configuration; + configuration.InitializeArguments(argc, argv); + + // Initialize Hardware and Data + auto hardware = ExaGeoStatHardware(configuration.GetComputation(), configuration.GetCoresNumber(), + configuration.GetGPUsNumbers()); + unique_ptr> data = make_unique>(); + Kernel *kernel = exageostat::plugins::PluginRegistry>::Create( + configuration.GetKernelName(), configuration.GetTimeSlot()); + + // Get arguments for Descriptors Initialization + int kernel_variables_number = kernel->GetVariablesNumber(); + int config_problem_size = configuration.GetProblemSize(); + int config_full_problem_size = config_problem_size * kernel_variables_number; + int config_dts = configuration.GetDenseTileSize(); + int config_p_grid = configuration.GetPGrid(); + int config_q_grid = configuration.GetQGrid(); + bool config_is_OOC = configuration.GetIsOOC(); + + // Randomly Initialized Matrix of Data + std::vector matrix(config_problem_size); + for (int i = 0; i < config_problem_size; ++i) { + matrix[i] = i; + } + + // Set Data Descriptor + data->SetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C, config_is_OOC, matrix.data(), EXAGEOSTAT_REAL_DOUBLE, + config_dts, config_dts, config_dts * config_dts, config_full_problem_size, + config_full_problem_size, 0, 0, config_full_problem_size, config_full_problem_size, + config_p_grid, config_q_grid); + auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; + + //Print Descriptor Attributes Before and After conversion + LOGGER("** Chameleon Descriptor, Before Conversion:") + LOGGER(" Problem Size: " << CHAM_descriptorC->m) + LOGGER(" Dense Tile Size: " << CHAM_descriptorC->mb) + + LOGGER(" Entire Number of Rows :" << CHAM_descriptorC->lm) + LOGGER(" Entire Number of Columns :" << CHAM_descriptorC->ln) + + LOGGER(" Number of Sub-matrix Tile Rows: " << CHAM_descriptorC->mt) + LOGGER(" Number of Sub-matrix Tile Columns: " << CHAM_descriptorC->nt) + + LOGGER(" Number of Rows of 2D distribution grid: " << CHAM_descriptorC->p) + LOGGER(" Number of Rows of 2D distribution grid: " << CHAM_descriptorC->q) + + LOGGER(" Is Matrix Not Fit in Memory: " << CHAM_descriptorC->ooc) + LOGGER(" Size including Padding: " << CHAM_descriptorC->bsiz) + + // Print Data Matrix of Descriptor + LOGGER("** Data in Matrix of Chameleon descriptor:") + LOGGER_2("", 0) + auto *cham_mat = (double *) CHAM_descriptorC->mat; + for (int i = 0; i < config_problem_size; ++i) { + LOGGER_PRECISION_1(" " << cham_mat[i], 0) + } + + auto *HICMA_descriptorC = data->ConvertChameleonToHicma(CHAM_descriptorC, DESCRIPTOR_C); + + //Print Descriptor Attributes + LOGGER(" Problem Size: " << HICMA_descriptorC->m) + LOGGER(" Dense Tile Size: " << HICMA_descriptorC->mb) + + LOGGER(" Entire Number of Rows :" << HICMA_descriptorC->lm) + LOGGER(" Entire Number of Columns :" << HICMA_descriptorC->ln) + + LOGGER(" Number of Sub-matrix Tile Rows: " << HICMA_descriptorC->mt) + LOGGER(" Number of Sub-matrix Tile Columns: " << HICMA_descriptorC->nt) + + LOGGER(" Number of Rows of 2D distribution grid: " << HICMA_descriptorC->p) + LOGGER(" Number of Rows of 2D distribution grid: " << HICMA_descriptorC->q) + + LOGGER(" Is Matrix Not Fit in Memory: " << HICMA_descriptorC->ooc) + LOGGER(" Size including Padding: " << HICMA_descriptorC->bsiz) + + // Print Data Matrix of Descriptor + LOGGER("** Data in Matrix:") + LOGGER_2("", 0) + auto *data_mat = (double *) HICMA_descriptorC->mat; + for (int i = 0; i < config_problem_size; ++i) { + LOGGER_PRECISION_1(" " << data_mat[i], 0) + } + + delete kernel; + return 0; +} diff --git a/examples/descriptors/HicmaDescriptor.cpp b/examples/descriptors/HicmaDescriptor.cpp new file mode 100644 index 00000000..5c81ae16 --- /dev/null +++ b/examples/descriptors/HicmaDescriptor.cpp @@ -0,0 +1,108 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file HicmaDescriptor.cpp + * @brief Example file for the Hicma descriptor. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-14 +**/ + +#include +#include +#include + +using namespace std; + +using namespace exageostat::common; +using namespace exageostat::kernels; +using namespace exageostat::dataunits; +using namespace exageostat::configurations; + +/** + * @brief Main entry point for the Hicma descriptor example in ExaGeoStat. + * @details Initializes configurations tailored for Hicma usage, sets up hardware, creates a kernel, and demonstrates the creation and initialization of a Hicma descriptor. + * The process includes checking for TILE_LOW_RANK computation mode, generating a data matrix, and setting up the Hicma descriptor with this matrix, showcasing how ExaGeoStat + * handles hierarchical matrix representations for efficient large-scale computations. + * @param argc Number of command-line arguments. + * @param argv Array of command-line argument strings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ + +int main(int argc, char **argv) { + + LOGGER("** Example of Hicma Descriptor **") + + // Initialize Synthetic Configuration + Configurations configuration; + configuration.InitializeArguments(argc, argv); + + //Check for TLR computation specific for HICMA descriptor + if (configuration.GetComputation() != TILE_LOW_RANK) { + LOGGER("You must provide TILE_LOW_RANK computation to initialize HICMA descriptor.") + LOGGER("Consider adding \"--computation=tlr\" to the arguments") + return 0; + } + // Initialize Hardware and Data + auto hardware = ExaGeoStatHardware(configuration.GetComputation(), configuration.GetCoresNumber(), + configuration.GetGPUsNumbers()); + unique_ptr> data = make_unique>(); + Kernel *kernel = exageostat::plugins::PluginRegistry>::Create( + configuration.GetKernelName(), configuration.GetTimeSlot()); + + // Get arguments for Descriptors Initialization + int kernel_variables_number = kernel->GetVariablesNumber(); + int config_problem_size = configuration.GetProblemSize(); + int config_full_problem_size = config_problem_size * kernel_variables_number; + int config_dts = configuration.GetDenseTileSize(); + int config_p_grid = configuration.GetPGrid(); + int config_q_grid = configuration.GetQGrid(); + bool config_is_OOC = configuration.GetIsOOC(); + + // Randomly Initialized Matrix of Data + std::vector matrix(config_problem_size * config_problem_size); + for (int i = 0; i < config_problem_size; ++i) { + matrix[i] = i; + } + + // Set Data Descriptor + data->SetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_C, config_is_OOC, matrix.data(), EXAGEOSTAT_REAL_DOUBLE, + config_dts, + config_dts, + config_dts * config_dts, config_full_problem_size, config_full_problem_size, 0, 0, + config_full_problem_size, + config_full_problem_size, config_p_grid, config_q_grid); + + auto *HICMA_descriptorC = data->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_C).hicma_desc; + + //Print Descriptor Attributes + LOGGER(" Problem Size: " << HICMA_descriptorC->m) + LOGGER(" Dense Tile Size: " << HICMA_descriptorC->mb) + + LOGGER(" Entire Number of Rows :" << HICMA_descriptorC->lm) + LOGGER(" Entire Number of Columns :" << HICMA_descriptorC->ln) + + LOGGER(" Number of Sub-matrix Tile Rows: " << HICMA_descriptorC->mt) + LOGGER(" Number of Sub-matrix Tile Columns: " << HICMA_descriptorC->nt) + + LOGGER(" Number of Rows of 2D distribution grid: " << HICMA_descriptorC->p) + LOGGER(" Number of Rows of 2D distribution grid: " << HICMA_descriptorC->q) + + LOGGER(" Is Matrix Not Fit in Memory: " << HICMA_descriptorC->ooc) + LOGGER(" Size including Padding: " << HICMA_descriptorC->bsiz) + + // Print Data Matrix of Descriptor + LOGGER("** Data in Matrix:") + LOGGER_2("", 0) + auto *data_mat = (double *) HICMA_descriptorC->mat; + for (int i = 0; i < config_problem_size; ++i) { + LOGGER_PRECISION_1(" " << data_mat[i], 0) + } + + delete kernel; + return 0; +} diff --git a/examples/end-to-end/CMakeLists.txt b/examples/end-to-end/CMakeLists.txt index bfce4c30..4131b826 100644 --- a/examples/end-to-end/CMakeLists.txt +++ b/examples/end-to-end/CMakeLists.txt @@ -1,10 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @brief Defines an executables and links them with the ExaGeoStat library and other libraries. +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-01-31 @@ -14,6 +15,7 @@ add_executable(Example_Data_Modeling ${CMAKE_CURRENT_SOURCE_DIR}/DataModeling.cp add_executable(Example_Data_Generation_and_Modeling ${CMAKE_CURRENT_SOURCE_DIR}/DataGenerationAndModeling.cpp) add_executable(Example_Data_Generation_Modeling_and_Prediction ${CMAKE_CURRENT_SOURCE_DIR}/DataGenerationModelingAndPrediction.cpp) add_executable(Example_Data_Prediction ${CMAKE_CURRENT_SOURCE_DIR}/DataPrediction.cpp) +add_executable(Example_Data_Generation_and_Prediction ${CMAKE_CURRENT_SOURCE_DIR}/DataGenerationAndPrediction.cpp) # Link the target executable with the project and any additional libraries target_link_libraries(Example_Data_Generation PUBLIC ${PROJECT_NAME}_INTERFACE) @@ -21,3 +23,4 @@ target_link_libraries(Example_Data_Modeling PUBLIC ${PROJECT_NAME}_INTERFACE) target_link_libraries(Example_Data_Generation_and_Modeling PUBLIC ${PROJECT_NAME}_INTERFACE) target_link_libraries(Example_Data_Generation_Modeling_and_Prediction PUBLIC ${PROJECT_NAME}_INTERFACE) target_link_libraries(Example_Data_Prediction PUBLIC ${PROJECT_NAME}_INTERFACE) +target_link_libraries(Example_Data_Generation_and_Prediction PUBLIC ${PROJECT_NAME}_INTERFACE) diff --git a/examples/end-to-end/DataGeneration.cpp b/examples/end-to-end/DataGeneration.cpp index 5d3ad6b0..fde12d35 100644 --- a/examples/end-to-end/DataGeneration.cpp +++ b/examples/end-to-end/DataGeneration.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,25 +7,22 @@ * @file DataGeneration.cpp * @brief This program either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data. * @details The program takes command line arguments to configure the data generation. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-05-30 + * @date 2024-02-04 **/ -#include #include using namespace exageostat::configurations; -using namespace exageostat::api; -using namespace exageostat::hardware; -using namespace exageostat::dataunits; /** * @brief Main entry point for the DataGeneration program. * @details This function either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data. * @param[in] argc The number of command line arguments. * @param[in] argv An array of command line argument strings. - * @return An integer indicating the success or failure of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { @@ -33,14 +30,12 @@ int main(int argc, char **argv) { Configurations configurations; // Initialize the arguments with the provided command line arguments configurations.InitializeArguments(argc, argv); - LOGGER("** initialize ExaGeoStat hardware ** ") + // Initialize the ExaGeoStat Hardware auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); - LOGGER("** Create ExaGeoStat data **") - ExaGeoStatData data; - LOGGER("** Generate ExaGeoStat data ** ") - ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, data); - LOGGER("** All example stages have been completed successfully ** ") + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(configurations, data); return 0; } \ No newline at end of file diff --git a/examples/end-to-end/DataGenerationAndModeling.cpp b/examples/end-to-end/DataGenerationAndModeling.cpp index 0b70d8a3..30fdf5d8 100644 --- a/examples/end-to-end/DataGenerationAndModeling.cpp +++ b/examples/end-to-end/DataGenerationAndModeling.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,25 +7,23 @@ * @file DataGenerationAndModeling.cpp * @brief This program either generates synthetic data using the ExaGeoStat library, or reads an CSV file. * @details The program takes command line arguments to configure the data generation. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-06-21 + * @date 2024-02-04 **/ -#include #include -using namespace exageostat::configurations; using namespace exageostat::api; -using namespace exageostat::hardware; -using namespace exageostat::dataunits; +using namespace exageostat::configurations; /** * @brief Main entry point for the Data Generation & Data Modeling program. * @details This function either generates synthetic data using the ExaGeoStat library, or reads an CSV file, then models the loaded data. * @param[in] argc The number of command line arguments. * @param[in] argv An array of command line argument strings. - * @return An integer indicating the success or failure of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { @@ -33,16 +31,14 @@ int main(int argc, char **argv) { Configurations configurations; // Initialize the arguments with the provided command line arguments configurations.InitializeArguments(argc, argv); - LOGGER("** initialize ExaGeoStat hardware ** ") + // Initialize the ExaGeoStat Hardware auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); - LOGGER("** Create ExaGeoStat data **") - ExaGeoStatData data; - LOGGER("** ExaGeoStat data generation ** ") - ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, data); - LOGGER("** ExaGeoStat data Modeling ** ") - ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, data); - LOGGER("** All example stages have been completed successfully ** ") + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations, data); return 0; } diff --git a/examples/end-to-end/DataGenerationAndPrediction.cpp b/examples/end-to-end/DataGenerationAndPrediction.cpp new file mode 100644 index 00000000..7150c78e --- /dev/null +++ b/examples/end-to-end/DataGenerationAndPrediction.cpp @@ -0,0 +1,44 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file DataGenerationAndPrediction.cpp + * @brief This program This program either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data, then predicts missing measurements using the ExaGeoStat library. + * @details The program takes command line arguments to configure the data generation. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-03-03 +**/ + +#include + +using namespace exageostat::api; +using namespace exageostat::configurations; + +/** + * @brief Main entry point for the Data Generation & Data Modeling program. + * @details This function either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data, models it, and predicts missing values. + * @param[in] argc The number of command line arguments. + * @param[in] argv An array of command line argument strings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ +int main(int argc, char **argv) { + + // Create a new configurations object. + Configurations configurations; + // Initialize the arguments with the provided command line arguments + configurations.InitializeArguments(argc, argv); + // Initialize the ExaGeoStat Hardware + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), + configurations.GetGPUsNumbers()); + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + // Prediction module + ExaGeoStat::ExaGeoStatPrediction(configurations, data); + + return 0; +} diff --git a/examples/end-to-end/DataGenerationModelingAndPrediction.cpp b/examples/end-to-end/DataGenerationModelingAndPrediction.cpp index a1ec90ea..746efdd8 100644 --- a/examples/end-to-end/DataGenerationModelingAndPrediction.cpp +++ b/examples/end-to-end/DataGenerationModelingAndPrediction.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,43 +7,40 @@ * @file DataGenerationModelingAndPrediction.cpp * @brief This program This program either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data, performs data modeling on loaded data, then predicts missing measurements using the ExaGeoStat library. * @details The program takes command line arguments to configure the data generation. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-06-21 + * @date 2024-02-04 **/ -#include #include -using namespace exageostat::configurations; using namespace exageostat::api; -using namespace exageostat::hardware; -using namespace exageostat::dataunits; +using namespace exageostat::configurations; /** * @brief Main entry point for the Data Generation & Data Modeling program. * @details This function either generates synthetic data using the ExaGeoStat library, or reads an CSV file containing real data, models it, and predicts missing values. * @param[in] argc The number of command line arguments. * @param[in] argv An array of command line argument strings. - * @return An integer indicating the success or failure of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { // Create a new configurations object. Configurations configurations; - // Initialize the arguments with the provided command line arguments + // Initialize the arguments with the provided command line arguments configurations.InitializeArguments(argc, argv); - LOGGER("** Initialise ExaGeoStat hardware **") + // Initialize the ExaGeoStat Hardware auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); - LOGGER("** Create ExaGeoStat data **") - ExaGeoStatData data; - LOGGER("** ExaGeoStat data generation **") - ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, data); - LOGGER("** ExaGeoStat data Modeling **") - ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, data); - LOGGER("** ExaGeoStat data Prediction **") - ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data); - LOGGER("** All example stages have been completed successfully ** ") + // Load data by either read from file or create synthetic data. + std::unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations, data); + // Prediction module + ExaGeoStat::ExaGeoStatPrediction(configurations, data); + return 0; } diff --git a/examples/end-to-end/DataModeling.cpp b/examples/end-to-end/DataModeling.cpp index 76706ea8..3ce1070f 100644 --- a/examples/end-to-end/DataModeling.cpp +++ b/examples/end-to-end/DataModeling.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,20 +7,15 @@ * @file DataModeling.cpp * @brief This program models data using the ExaGeoStat library. * @details The program takes command line arguments and example variables to configure the data modeling. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-06-21 + * @date 2024-02-04 **/ -#include - -#include #include using namespace exageostat::api; -using namespace exageostat::dataunits; using namespace exageostat::configurations; -using namespace exageostat::hardware; /** * @brief Main entry point for the Data Modeling program. @@ -30,14 +25,15 @@ using namespace exageostat::hardware; * the library's efficiency in handling large spatial datasets while efficiently utilizing hardware resources.. * @param[in] argc The number of command line arguments. * @param[in] argv An array of command line argument strings. - * @return An integer indicating the success or failure of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { // Create a new data_modeling_configurations object with the provided command line arguments and example variables Configurations configurations; configurations.InitializeArguments(argc, argv); /** - * Since this example is currently relying on user inputs instead of reading files, The following points are important to know: + * Since this example is relying on user inputs, The following points are important to know: * The N and dts have to match with the Location X, Y and Z_values you're going to provide. * You have to provide Locations and Z values in order to use Modeling without generation. */ @@ -47,13 +43,12 @@ int main(int argc, char **argv) { configurations.SetDenseTileSize(dts); // initialize ExaGeoStat hardware with the selected number of cores and gpus. - LOGGER("** initialize ExaGeoStat hardware ** ") auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); //Data Setup - LOGGER("** Create ExaGeoStat data ** ") - ExaGeoStatData data(configurations.GetProblemSize(), configurations.GetDimension()); + std::unique_ptr> data = std::make_unique>( + configurations.GetProblemSize(), configurations.GetDimension()); // Initiating the matrix of the CHAMELEON Descriptor Z. auto *z_matrix = new double[N]{-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, @@ -77,15 +72,16 @@ int main(int argc, char **argv) { 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, 0.942824444953078489}; - data.GetLocations()->SetLocationX(*location_x, N); - data.GetLocations()->SetLocationY(*location_y, N); + data->GetLocations()->SetLocationX(*location_x, N); + data->GetLocations()->SetLocationY(*location_y, N); + + // Modeling module. + ExaGeoStat::ExaGeoStatDataModeling(configurations, data, z_matrix); - LOGGER("** ExaGeoStat Data Modeling ** ") - ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, data, z_matrix); - LOGGER("** All example stages have been completed successfully ** ") // Freeing the allocated memory. delete[] z_matrix; delete[] location_x; delete[] location_y; + return 0; } diff --git a/examples/end-to-end/DataPrediction.cpp b/examples/end-to-end/DataPrediction.cpp index 9e51f737..dbe1a1f8 100644 --- a/examples/end-to-end/DataPrediction.cpp +++ b/examples/end-to-end/DataPrediction.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,25 +7,23 @@ * @file DataPrediction.cpp * @brief This program predicts missing measurements using the ExaGeoStat library. * @details The program takes command line arguments to configure the data prediction module. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-09-11 + * @date 2024-02-04 **/ -#include #include -using namespace exageostat::configurations; using namespace exageostat::api; -using namespace exageostat::hardware; -using namespace exageostat::dataunits; +using namespace exageostat::configurations; /** * @brief Main entry point for the Data Prediction program. * @details This function predicts missing values. * @param[in] argc The number of command line arguments. * @param[in] argv An array of command line argument strings. - * @return An integer indicating the success or failure of the program. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * */ int main(int argc, char **argv) { @@ -34,7 +32,7 @@ int main(int argc, char **argv) { // Initialize the arguments with the provided command line arguments configurations.InitializeArguments(argc, argv); /** - * Since this example is currently relying on user inputs instead of reading files, The following points are important to know: + * Since this example is currently relying on user inputs, The following points are important to know: * The N and dts have to match with the Location X, Y and Z_values you're going to provide. * You have to provide Locations and Z values in order to use Modeling without generation. */ @@ -44,13 +42,12 @@ int main(int argc, char **argv) { configurations.SetDenseTileSize(dts); // initialize ExaGeoStat hardware with the selected number of cores and gpus. - LOGGER("** Initialise ExaGeoStat hardware **") auto hardware = ExaGeoStatHardware(configurations.GetComputation(), configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); //Data Setup - LOGGER("** Create ExaGeoStat data **") - ExaGeoStatData data(configurations.GetProblemSize(), configurations.GetDimension()); + std::unique_ptr> data = std::make_unique>( + configurations.GetProblemSize(), configurations.GetDimension()); //creating locations x and y. auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, @@ -75,15 +72,15 @@ int main(int argc, char **argv) { 0.971213790000161170, 0.538973474182433021, -0.752828466476077041, 0.290822066007430102}; - data.GetLocations()->SetLocationX(*location_x, N); - data.GetLocations()->SetLocationY(*location_y, N); + data->GetLocations()->SetLocationX(*location_x, N); + data->GetLocations()->SetLocationY(*location_y, N); - LOGGER("** ExaGeoStat data Prediction **") - ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); - LOGGER("** All example stages have been completed successfully **") + // Prediction module + ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); delete[] location_x; delete[] location_y; delete[] z_matrix; + return 0; } \ No newline at end of file diff --git a/examples/hardware/CMakeLists.txt b/examples/hardware/CMakeLists.txt new file mode 100644 index 00000000..82d5e8f9 --- /dev/null +++ b/examples/hardware/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @brief Defines an executable and links it with the ExaGeoStat library and other libraries. +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-14 + +# Define the target executable +add_executable(Example_Hardware ${CMAKE_CURRENT_SOURCE_DIR}/ExaGeoStatHardware.cpp) + +# Link the target executable with the project and any additional libraries +target_link_libraries(Example_Hardware PRIVATE ${PROJECT_NAME}_INTERFACE) + diff --git a/examples/hardware/ExaGeoStatHardware.cpp b/examples/hardware/ExaGeoStatHardware.cpp new file mode 100644 index 00000000..0710943f --- /dev/null +++ b/examples/hardware/ExaGeoStatHardware.cpp @@ -0,0 +1,42 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestExaGeoStatHardware.cpp + * @briefExample for the ExaGeoStatHardware class in the ExaGeoStat software package. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-14 +**/ + +#include +#include + +using namespace exageostat::configurations; + +/** + * @brief Main entry point for demonstrating the ExaGeoStatHardware class usage. + * @details This program demonstrates how to initialize the ExaGeoStatHardware class using configuration settings derived from command-line arguments. + * It showcases the initialization process for hardware configurations, including the computation mode, number of cores, and number of GPUs, + * highlighting the simplicity and effectiveness of managing hardware resources in ExaGeoStat. + * @param argc Number of command-line arguments. + * @param argv Array of command-line argument strings. + * @return An integer indicating the success or failure of the program. A return value of 0 indicates success, while any non-zero value indicates failure. + * + */ +int main(int argc, char **argv) { + + LOGGER("** Example of Hardware **") + + // Initialize Configuration + Configurations configuration; + configuration.InitializeArguments(argc, argv); + + // Initialize Hardware + auto hardware = ExaGeoStatHardware(configuration.GetComputation(), configuration.GetCoresNumber(), + configuration.GetGPUsNumbers()); + + return 0; +} \ No newline at end of file diff --git a/inst/include/Rcpp-adapters/FunctionsAdapter.hpp b/inst/include/Rcpp-adapters/FunctionsAdapter.hpp new file mode 100644 index 00000000..17cb7dc3 --- /dev/null +++ b/inst/include/Rcpp-adapters/FunctionsAdapter.hpp @@ -0,0 +1,260 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file FunctionAdapter.hpp + * @brief Header file for function adapters in the ExaGeoStat software. + * @details It provides declarations for functions that adapt and initialize statistical models or algorithms based on user-defined configurations. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-29 +**/ + +#ifndef EXAGEOSTATCPP_FUNCTIONSADAPTER_HPP +#define EXAGEOSTATCPP_FUNCTIONSADAPTER_HPP + +#include + +#include +#include + +namespace exageostat::adapters { + + /** + * @brief Retrieves locations from ExaGeoStat data. + * @details Extracts and returns the locations stored in an ExaGeoStatData object, + * @param[in] apData Pointer to ExaGeoStatData object containing the spatial data. + * @return vector of locations coordinates. + * + */ + std::vector> R_GetLocations(ExaGeoStatData *apData); + + /** + * @brief Retrieves descriptive Z values from ExaGeoStat data based on type. + * @details Extracts and returns Z values from an ExaGeoStatData object, aiding in targeted spatial data analysis and visualization within ExaGeoStat. + * @param[in] apData Pointer to ExaGeoStatData object containing the spatial data. + * @param[in] aType String specifying the type of descriptor value to retrieve (e.g., "Chameleon", "HiCMA"). + * @return Numeric vector of descriptive Z values. + * + */ + Rcpp::NumericVector R_GetDescZValues(ExaGeoStatData *apData, const std::string &aType); + + /** + * @brief Function to load ExaGeoStat data. + * @details This function loads data into an ExaGeoStatData object using the provided configuration and computational settings. + * It is designed to initialize the data structure necessary for subsequent statistical model operations within the ExaGeoStat framework. + * @param[in] aKernelName Name of the computational kernel to be utilized. + * @param[in] aInitialTheta Initial parameter values for the statistical model. + * @param[in] aDistanceMatrix Type of distance matrix to be used ("euclidean", "manhattan", etc.). + * @param[in] aProblemSize Size of the problem or dataset. + * @param[in] aSeed Seed for random number generation, ensuring reproducibility. + * @param[in] aDenseTileSize Size of the tile for dense computations. + * @param[in] aLowTileSize Size of the tile for low-rank computations. + * @param[in] aDimension Dimensionality of the problem ("2D" for two dimensions, "3D" for three dimensions). + * @param[in] aLogPath Path to the log file where execution details will be stored. + * @param[in] aDataPath Path to the data file containing spatial observations. + * @param[in] aRecoveryFilePath Path for saving intermediate computation states, aiding in recovery from interruptions. + * @param[in] aObservationsFilePath Path to the file containing observation data. + * @return A pointer to an ExaGeoStatData object containing the loaded data. + * + */ + ExaGeoStatData * + R_ExaGeoStatLoadData(const std::string &aKernelName, const std::vector &aInitialTheta, + const std::string &aDistanceMatrix, const int &aProblemSize, const int &aSeed, + const int &aDenseTileSize, const int &aLowTileSize, const std::string &aDimension, + const std::string &aLogPath, const std::string &aDataPath, + const std::string &aRecoveryFilePath, const std::string &aObservationsFilePath); + + /** + * @brief Models ExaGeoStat data using specified arguments. + * @details Applies statistical modeling to ExaGeoStatData based on the provided configurations. + * This function is essential for preparing the data for in-depth statistical analysis and predictions, + * optimizing internal representations and parameters for the modeling process. + * @param[in] aComputation Computational method to be used. + * @param[in] aKernelName Name of the kernel for computations. + * @param[in] aDistanceMatrix Type of distance matrix ("euclidean", "manhattan", etc.). + * @param[in] aLowerBound Lower bound for optimization parameters. + * @param[in] aUpperBound Upper bound for optimization parameters. + * @param[in] aTolerance Tolerance level for the optimization algorithm. + * @param[in] aMleIterations Maximum number of iterations for the Maximum Likelihood Estimation (MLE) algorithm. + * @param[in] aDenseTileSize Tile size for dense matrix computations. + * @param[in] aLowTileSize Tile size for low-rank approximations. + * @param[in] aDimension Dimensionality of the problem ("2D" or "3D"). + * @param[in] aBand Bandwidth for band matrices, applicable in certain computational kernels. + * @param[in] aMaxRank Maximum rank for low-rank approximations. + * @param[in] apData Pointer to ExaGeoStatData object to be modeled. + * @param[in] aMeasurementsVector Optional vector of measurements to enhance modeling, can be nullable. + * @param[in] aLocationsX Optional vector of X coordinates for locations, can be nullable. + * @param[in] aLocationsY Optional vector of Y coordinates for locations, can be nullable. + * @param[in] aLocationsZ Optional vector of Z coordinates for locations, can be nullable. + * @return Vector of doubles represents the modeled theta. + * + */ + std::vector R_ExaGeoStatModelData(const std::string &aComputation, const std::string &aKernelName, + const std::string &aDistanceMatrix, + const std::vector &aLowerBound, + const std::vector &aUpperBound, const int &aTolerance, + const int &aMleIterations, const int &aDenseTileSize, + const int &aLowTileSize, const std::string &aDimension, const int &aBand, + const int &aMaxRank, SEXP apData, + Rcpp::Nullable aMeasurementsVector = R_NilValue, + Rcpp::Nullable aLocationsX = R_NilValue, + Rcpp::Nullable aLocationsY = R_NilValue, + Rcpp::Nullable aLocationsZ = R_NilValue); + + /** + * @brief Predicts outcomes using ExaGeoStat data and configurations. + * @details Utilizes a modeled ExaGeoStatData object to perform predictions, leveraging specified computational settings and statistical models. + * This function is integral for generating spatial predictions based on the data and models within the ExaGeoStat framework. + * @param[in] aKernelName Name of the kernel used for prediction computations. + * @param[in] aDistanceMatrix Type of distance matrix used ("euclidean", "manhattan", etc.). + * @param[in] aEstimatedTheta Vector of estimated parameters from the model. + * @param[in] aDenseTileSize Tile size for dense matrix operations. + * @param[in] aLowTileSize Tile size for low-rank matrix operations. + * @param[in] aDimension Dimensionality of the spatial data ("2D" or "3D"). + * @param[in] aTrainData Training data set used for predictions. + * @param[in] aTestData Test data set for which predictions are made. + * @return Vector of predicted values based on the test data. + * + */ + std::vector R_ExaGeoStatPredictData(const std::string &aKernelName, const std::string &aDistanceMatrix, + const std::vector &aEstimatedTheta, const int &aDenseTileSize, + const int &aLowTileSize, const std::string &aDimension, + std::vector> &aTrainData, + std::vector> &aTestData); + + /** + * @brief Calculates the Mean Logarithmic Error (MLOE) and the Mean Measure of Model Output (MMOM) for ExaGeoStat predictions. + * @details Assesses the accuracy of spatial predictions made by the ExaGeoStat framework by computing the MLOE and MMOM, + * which provide insights into the predictive performance and uncertainty of the models. + * @param[in] aKernelName Kernel used for the prediction computations. + * @param[in] aDistanceMatrix Type of distance matrix ("euclidean", "manhattan", etc.). + * @param[in] aEstimatedTheta Vector of estimated parameters from the model. + * @param[in] aTrueTheta Vector of true parameter values for validation. + * @param[in] aDenseTileSize Tile size for dense matrix operations. + * @param[in] aLowTileSize Tile size for low-rank matrix operations. + * @param[in] aDimension Dimensionality of the spatial data ("2D" or "3D"). + * @param[in] aTrainData Training data set used in the model. + * @param[in] aTestData Test data set used for validation. + * @return Vector containing the calculated MLOE and MMOM values. + * + */ + std::vector R_ExaGeoStatMLOE_MMOM(const std::string &aKernelName, const std::string &aDistanceMatrix, + const std::vector &aEstimatedTheta, + const std::vector &aTrueTheta, const int &aDenseTileSize, + const int &aLowTileSize, const std::string &aDimension, + std::vector> &aTrainData, + std::vector> &aTestData); + + /** + * @brief Computes the Fisher information matrix for ExaGeoStat models. + * @details Utilizes the estimated parameters and the Fisher information matrix to evaluate the information content and + * parameter uncertainties within the ExaGeoStat framework, contributing to the understanding of model reliability and sensitivity. + * @param[in] aKernelName Kernel used for computations. + * @param[in] aDistanceMatrix Type of distance matrix ("euclidean", "manhattan", etc.). + * @param[in] aEstimatedTheta Vector of estimated parameters from the model. + * @param[in] aDenseTileSize Tile size for dense matrix operations. + * @param[in] aLowTileSize Tile size for low-rank matrix operations. + * @param[in] aDimension Dimensionality of the spatial data ("2D" or "3D"). + * @param[in] aTrainData Training data set used in the model. + * @param[in] aTestData Test data set used for validation. + * @return Vector represents the Fisher information matrix. + * + */ + std::vector R_ExaGeoStatFisher(const std::string &aKernelName, const std::string &aDistanceMatrix, + const std::vector &aEstimatedTheta, const int &aDenseTileSize, + const int &aLowTileSize, const std::string &aDimension, + std::vector> &aTrainData, + std::vector> &aTestData); + + /** + * @brief Applies Inverse Distance Weighting (IDW) for spatial interpolation using ExaGeoStat data. + * @details Implements the IDW interpolation method to estimate spatial variables at unsampled locations based on the distances + * and values of nearby sampled points within the ExaGeoStat framework, enhancing spatial prediction capabilities. + * @param[in] aKernelName Kernel used for IDW computations. + * @param[in] aDistanceMatrix Type of distance matrix ("euclidean", "manhattan", etc.). + * @param[in] aEstimatedTheta Vector of parameters, typically used for weighting in IDW. + * @param[in] aDenseTileSize Tile size for dense matrix operations. + * @param[in] aLowTileSize Tile size for low-rank matrix operations. + * @param[in] aDimension Dimensionality of the spatial data ("2D" or "3D"). + * @param[in] aTrainData Training data set providing sampled locations and values. + * @param[in] aTestData Test data set providing unsampled locations for which values are interpolated. + * @param[in] aTestMeasurementsValues Vector of measured values at the test locations, used as reference in some IDW implementations. + * @return Vector of interpolated values at the test locations. + * + */ + std::vector R_ExaGeoStatIDW(const std::string &aKernelName, const std::string &aDistanceMatrix, + const std::vector &aEstimatedTheta, const int &aDenseTileSize, + const int &aLowTileSize, const std::string &aDimension, + std::vector> &aTrainData, + std::vector> &aTestData, + std::vector &aTestMeasurementsValues); + + /** + * @brief Extracts and prepares data from given arguments for ExaGeoStat operations. + * @details This function is designed to parse and prepare spatial and measurement data from provided arguments, + * making it suitable for processing within the ExaGeoStat framework. It handles optional data vectors for measurements + * and locations (X, Y, Z coordinates), and configures an ExaGeoStatData object based on these inputs along with other + * computational and configuration parameters. + * @param[in] aMeasurementsVector vector of measurements to enhance modeling, can be nullable. + * @param[in] aLocationsX vector of X coordinates for locations, can be nullable. + * @param[in] aLocationsY vector of Y coordinates for locations, can be nullable. + * @param[in] aLocationsZ vector of Z coordinates for locations, can be nullable. + * @param[in] aData Pointer to ExaGeoStatData object to be modeled. + * @param[in] aConfigurations Configuration settings specifying computational details such as the kernel type, matrix storage format, etc. + * @param[in] aKernelName Name of the kernel for computations. + * @param[in] aDistanceMatrix Type of distance matrix ("euclidean", "manhattan", etc.). + * @param[in] aDenseTileSize Tile size for dense matrix computations. + * @param[in] aLowTileSize Tile size for low-rank approximations. + * @param[in] aDimension Dimensionality of the problem ("2D" or "3D"). + * @param[in] aComputation Computational method to be used. + * @return Pointer to a double array containing the prepared data, ready for use in ExaGeoStat operations. + * + */ + double *GetDataFromArguments(Rcpp::Nullable aMeasurementsVector, + Rcpp::Nullable aLocationsX, + Rcpp::Nullable aLocationsY, + Rcpp::Nullable aLocationsZ, + std::unique_ptr> &aData, + configurations::Configurations &aConfigurations, const std::string &aKernelName, + const std::string &aDistanceMatrix, const int &aDenseTileSize, const int &aLowTileSize, + const std::string &aDimension, const common::Computation &aComputation); + + /** + * @brief Validates the dimensions of input data. + * @details This function checks the dimensions of the provided data vectors to ensure they meet the expected format and size requirements for a given data type. + * It's used to verify that the data structures passed into algorithms or processes are correctly formatted, preventing errors or inconsistencies in data processing. + * @param aData A constant reference to a vector of vectors containing the data to be validated. + * @param aDataType A string describing the type of data being validated, which influences the expected dimensions and format of the data. + * @return void + * + */ + void ValidateDataDimensions(const std::vector> &aData, const std::string &aDataType); + + /** + * @brief Sets up the prediction environment. + * @details This function prepares the necessary configurations and data structures for making predictions. It involves setting up various parameters, including kernel names, distance matrices, tile sizes, dimensions, and training/test data. The function is crucial for initializing the prediction process with the appropriate settings and data. + * @param aConfigurations Reference to a Configurations object containing various prediction and algorithm configurations. + * @param aKernelName Name of the kernel to be used in predictions. + * @param aDistanceMatrix String representation of the distance matrix to be used. + * @param aDenseTileSize Size of the dense tiles in the matrix. + * @param aLowTileSize Size of the low-resolution tiles in the matrix. + * @param aDimension String representation of the dimensionality of the data. + * @param aTrainData Reference to a vector of vectors containing the training data. + * @param aTestData Reference to a vector of vectors containing the test data. + * @param aEstimatedTheta Vector containing estimated theta values for the model. + * @param aTestMeasurementsValues Vector containing the test measurement values. + * @return Pointer to a double array containing the prepared data, ready for use in ExaGeoStat operations. + * + */ + void PredictionSetupHelper(configurations::Configurations &aConfigurations, const std::string &aKernelName, + const std::string &aDistanceMatrix, const int &aDenseTileSize, const int &aLowTileSize, + const std::string &aDimension, std::vector> &aTrainData, + std::vector> &aTestData, + const std::vector &aEstimatedTheta, + const std::vector &aTestMeasurementsValues); + +} +#endif //EXAGEOSTATCPP_FUNCTIONSADAPTER_HPP diff --git a/inst/include/api/ExaGeoStat.hpp b/inst/include/api/ExaGeoStat.hpp index 7de91beb..54c61c16 100644 --- a/inst/include/api/ExaGeoStat.hpp +++ b/inst/include/api/ExaGeoStat.hpp @@ -1,14 +1,14 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStat.hpp * @brief High-Level Wrapper class containing the static API for ExaGeoStat operations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-05-30 + * @date 2024-02-04 **/ #ifndef EXAGEOSTATCPP_EXAGEOSTAT_HPP @@ -16,10 +16,8 @@ #include -#include #include #include -#include namespace exageostat::api { /** @@ -33,28 +31,24 @@ namespace exageostat::api { /** * @brief Generates Data whether it's synthetic data or real. - * @param[in] aHardware Reference to Hardware configuration for the ExaGeoStat solver. * @param[in] aConfigurations Reference to Configurations object containing user input data. * @param[out] aData Reference to an ExaGeoStatData object where generated data will be stored. * @return void * */ - static void ExaGeoStatLoadData(const hardware::ExaGeoStatHardware &aHardware, - configurations::Configurations &aConfigurations, - dataunits::ExaGeoStatData &aData); + static void ExaGeoStatLoadData(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData); /** * @brief Models Data whether it's synthetic data or real. - * @param[in] aHardware Reference to Hardware configuration for the ExaGeoStat solver. * @param[in] aConfigurations Reference to Configurations object containing user input data. * @param[in] aData Reference to an ExaGeoStatData object containing needed descriptors, and locations. * @param[in] apMeasurementsMatrix Pointer to the user input measurements matrix. - * @return void + * @return the last optimum value of MLE. * */ - static T ExaGeoStatDataModeling(const hardware::ExaGeoStatHardware &aHardware, - configurations::Configurations &aConfigurations, - exageostat::dataunits::ExaGeoStatData &aData, + static T ExaGeoStatDataModeling(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, T *apMeasurementsMatrix = nullptr); @@ -64,28 +58,25 @@ namespace exageostat::api { * @param[in] aGrad An array of length n where you can optionally return the gradient of the objective function. * @param[in] apInfo pointer containing needed configurations and data. * @return double MLE results. + * */ static double ExaGeoStatMLETileAPI(const std::vector &aTheta, std::vector &aGrad, void *apInfo); /** * @brief Predict missing measurements values. - * @param[in] aHardware Reference to Hardware configuration for the ExaGeoStat solver. * @param[in] aConfigurations Reference to Configurations object containing user input data. * @param[in, out] aData Reference to an ExaGeoStatData object containing needed descriptors, and locations. * @param[in] apMeasurementsMatrix Pointer to the user input measurements matrix. + * @param[in] apTrainLocations (Optional) Pointer to Locations represents training locations. these are used in training phase. + * @param[in] apTestLocations (Optional) Pointer to Locations represents test locations. These are used in prediction phase. * @return void + * */ - static void ExaGeoStatPrediction(const hardware::ExaGeoStatHardware &aHardware, - configurations::Configurations &aConfigurations, - exageostat::dataunits::ExaGeoStatData &aData, - T *apMeasurementsMatrix = nullptr); + static void + ExaGeoStatPrediction(configurations::Configurations &aConfigurations, std::unique_ptr> &aData, + T *apMeasurementsMatrix = nullptr, dataunits::Locations *apTrainLocations = nullptr, + dataunits::Locations *apTestLocations = nullptr); - private: - /** - * @brief - * Prevent Class Instantiation for API Wrapper Class. - */ - ExaGeoStat() = default; }; /** diff --git a/inst/include/common/Definitions.hpp b/inst/include/common/Definitions.hpp index 406e44c4..400e26df 100644 --- a/inst/include/common/Definitions.hpp +++ b/inst/include/common/Definitions.hpp @@ -1,11 +1,11 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Definitions.hpp - * @version 1.0.0 + * @version 1.1.0 * @brief This file contains common definitions used in ExaGeoStat software package. * @details These definitions include enums for dimension, computation, precision, and floating point arithmetic; * A macro for instantiating template classes with supported types; and a set of available kernels. @@ -14,27 +14,24 @@ * @date 2023-03-21 **/ - #ifndef EXAGEOSTATCPP_DEFINITIONS_HPP #define EXAGEOSTATCPP_DEFINITIONS_HPP -//// TODO: This is a hot fix to avoid the problem in HiCMA which set the min definition with a conflict implementation of chrono library. +// This is a fix to avoid the problem in HiCMA which set the min definition with a conflict implementation of chrono library. +#ifdef USE_HICMA #ifdef min #undef min #endif +#endif -#include -#include -#include #include #include -#include /** * @def EXAGEOSTAT_INSTANTIATE_CLASS * @brief Macro definition to instantiate the EXAGEOSTAT template classes with supported types. + * **/ - #define EXAGEOSTAT_INSTANTIATE_CLASS(TEMPLATE_CLASS) template class TEMPLATE_CLASS; \ template class TEMPLATE_CLASS; @@ -57,6 +54,11 @@ */ #define Q_NORM 1.959964 +/** + * Logging Path Definition + */ +#define LOG_PATH PROJECT_SOURCE_DIR "/synthetic_ds/" + namespace exageostat::common { /** @@ -84,6 +86,7 @@ namespace exageostat::common { /** * @enum Side * @brief Enum denoting the side on which the matrix appears in an equation. + * */ enum Side { EXAGEOSTAT_LEFT = 141, @@ -93,6 +96,7 @@ namespace exageostat::common { /** * @enum Trans * @brief Enum denoting whether or not to transpose a matrix. + * */ enum Trans { EXAGEOSTAT_NO_TRANS = 111, @@ -103,6 +107,7 @@ namespace exageostat::common { /** * @enum Diag * @brief Enum denoting whether the diagonal is unitary. + * */ enum Diag { EXAGEOSTAT_NON_UNIT = 131, @@ -112,6 +117,7 @@ namespace exageostat::common { /** * @enum Distance metric * @brief Enum denoting distance metric type. + * */ enum DistanceMetric { EUCLIDEAN_DISTANCE = 0, @@ -121,15 +127,27 @@ namespace exageostat::common { /** * @enum Descriptor Type * @brief Enum denoting the Descriptor Type. + * */ enum DescriptorType { CHAMELEON_DESCRIPTOR = 0, HICMA_DESCRIPTOR = 1 }; + /** + * @enum Data source Type + * @brief Enum denoting the data source Type. + * + */ + enum DataSourceType { + SYNTHETIC = 0, + CSV_FILE = 1 + }; + /** * @enum Descriptor Name * @brief Enum denoting all Descriptors Names. + * */ enum DescriptorName : int { DESCRIPTOR_C = 0, @@ -184,10 +202,15 @@ namespace exageostat::common { DESCRIPTOR_C_DIAG = 49, DESCRIPTOR_A = 50, DESCRIPTOR_RESULTS = 51, + DESCRIPTOR_SUM = 52, + DESCRIPTOR_R = 53, + DESCRIPTOR_R_COPY = 54, }; /** + * @enum Tile Storage * @brief Matrix tile storage + * */ typedef enum TileStorage { EXAGOSTAT_CM = 101, @@ -246,6 +269,16 @@ namespace exageostat::common { EXAGEOSTAT_UPPER_LOWER = 123 /**< Use the full A */ }; + /** + * @enum CopyDirection + * @brief Enum denoting the copy descriptors flow + * + */ + enum CopyDirection : int { + CHAMELEON_TO_HICMA = 0, + HICMA_TO_CHAMELEON = 1 + }; + /** * @var availableKernels * @brief Set denoting the available kernels supported in matrix generation. @@ -253,14 +286,13 @@ namespace exageostat::common { * The set is initialized with a lambda function that iterates through a directory * and extracts the kernel names from the filenames. It also adds lowercase versions * of the kernel names with underscores before each capital letter. + * @return set of all available kernels names * */ const static std::set availableKernels = []() { // This set stores the kernel names. std::set kernelNames; // This string stores the directory path where the kernel files are located. - // The path is obtained by using the __FILE__ macro to get the full path of the current source file, - // and then navigating two levels up to reach the directory that contains the kernel files. const std::string directoryPath = KERNELS_PATH; // This loop iterates through all the files in the directory and extracts the kernel names. for (const auto &entry: std::filesystem::directory_iterator(directoryPath)) { diff --git a/inst/include/common/PluginRegistry.hpp b/inst/include/common/PluginRegistry.hpp index b0ba4f6e..b59a9d7f 100644 --- a/inst/include/common/PluginRegistry.hpp +++ b/inst/include/common/PluginRegistry.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file PluginRegistry.hpp * @brief Defines a template class for registering and creating plugins. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-04-30 **/ @@ -14,17 +14,17 @@ #ifndef EXAGEOSTATCPP_PLUGINREGISTRY_HPP #define EXAGEOSTATCPP_PLUGINREGISTRY_HPP -//// TODO: This is a hot fix to avoid the problem in HiCMA which set the min definition with a conflict implementation of chrono library. +// This is a fix to avoid the problem in HiCMA which set the min definition with a conflict implementation of chrono library. +#ifdef USE_HICMA #ifdef min #undef min #endif +#endif -#include -#include -#include -#include #include +#include + namespace exageostat::plugins { /** * @brief Template class for registering and creating plugins. @@ -68,13 +68,17 @@ namespace exageostat::plugins { * @return A pointer to the created plugin, or nullptr if the plugin could not be created. * */ - static T *Create(const std::string &aName) { + static T *Create(const std::string &aName, const int &aTimeSlot) { auto map = GetFactoryMap(); if (map.find(aName) == map.end()) { return nullptr; } - return map[aName](); + // Get the object from the map. + T *object = map[aName](); + // Automatically set the new P value which will get updated with the user input of P. + object->SetPValue(aTimeSlot); + return object; } private: diff --git a/inst/include/common/Utils.hpp b/inst/include/common/Utils.hpp deleted file mode 100644 index f0428098..00000000 --- a/inst/include/common/Utils.hpp +++ /dev/null @@ -1,106 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file Utils.hpp - * @brief This file contains common functions used in ExaGeoStat software package. - * @details These functions include so far the VERBOSE macro that prints a message - * to the console if the verbosity setting is set to "verbose mode. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-03-21 -**/ - -#ifndef EXAGEOSTATCPP_UTILS_HPP -#define EXAGEOSTATCPP_UTILS_HPP - -#include -#include -#include - -#include -#include -#include - -/** - * DEFAULT_PRECISION the value of the default C++ std::cout number of precision. - */ -#define DEFAULT_PRECISION 6 - -/** -* Verbose macro for logging and debugging mode -*/ -#define VERBOSE(msg) \ - if(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::DETAILED_MODE && exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) \ - std::cout << "\t\t\t " << msg << std::endl; - -/** - * LOGGER_1 macro for logging outputs with double taps and new line at the end. - */ - -#define LOGGER_1(msg) \ - if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) \ - std::cout << "\t\t " << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg << std::endl; - -/** - * LOGGER_2 macro for logging outputs with double taps and without new line at the end. - */ -#define LOGGER_2(msg, A) \ - if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) \ - std::cout << "\t\t " << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg; - -/** - * LOGGER_CONTROL is The internal macro that simply strips the excess and ends up with the required macro - */ -#define LOGGER_CONTROL(x, A, B, FUNC, ...) FUNC - -/** - * LOGGER macro that's called, Used to logging outputs - */ -#define LOGGER(...) LOGGER_CONTROL(,##__VA_ARGS__, \ - LOGGER_2(__VA_ARGS__), \ - LOGGER_1(__VA_ARGS__), \ - ) - -/** -* LOGGER_PRECISION_1 macro for logging outputs without any taps, without new line at the end and with customized precision. -*/ -#define LOGGER_PRECISION_1(msg, precision) \ - if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) \ - std::cout << std::fixed << std::setprecision(precision) << msg; - -/** -* LOGGER_PRECISION macro for logging outputs without any taps, without new line at the end and with default C++ precision. -*/ -#define LOGGER_PRECISION_2(msg) \ - if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) \ - std::cout << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg; - -/** - * LOGGER_CONTROL is The internal macro that simply strips the excess and ends up with the required macro - */ -#define LOGGER_PRECISION_CONTROL(x, A, B, FUNC, ...) FUNC - -/** - * LOGGER macro that's called, Used to logging outputs - */ -#define LOGGER_PRECISION(...) LOGGER_PRECISION_CONTROL(,##__VA_ARGS__, \ - LOGGER_PRECISION_1(__VA_ARGS__), \ - LOGGER_PRECISION_2(__VA_ARGS__), \ - ) - -/** - * Timing macro to start timing. - */ -#define START_TIMING(t) auto t##_start = std::chrono::high_resolution_clock::now() - -/** - * Timing macro to stop timing. - */ -#define STOP_TIMING(t) auto t##_end = std::chrono::high_resolution_clock::now(); \ - t = std::chrono::duration_cast>(t##_end - t##_start).count() - -#endif //EXAGEOSTATCPP_UTILS_HPP diff --git a/inst/include/configurations/Configurations.hpp b/inst/include/configurations/Configurations.hpp index 4c69a9b1..5e523cc8 100644 --- a/inst/include/configurations/Configurations.hpp +++ b/inst/include/configurations/Configurations.hpp @@ -1,15 +1,15 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Configurations.hpp -* @version 1.0.0 +* @version 1.1.0 * @brief Contains the declaration of the Configurations class and its member functions. -* @author Sameh Abdulah * @author Mahmoud ElKarargy -* @date 2023-01-31 +* @author Sameh Abdulah +* @date 2024-02-04 **/ #ifndef EXAGEOSTAT_CPP_CONFIGURATIONS_HPP @@ -27,7 +27,6 @@ * the specified type and sets the member variable with the specified name * to the value of the argument. The name of the member variable is used as * the key to set the corresponding value in the specified dictionary. - * * @param[in] name The name of the member variable to be set. * @param[in] type The data type of the member variable. * @param[in] argument_name The name of the argument to the generated function. @@ -44,7 +43,6 @@ void Set##name(type argument_name) \ * @brief Macro that generates a getter function for a member variable. * @details This macro generates a function named Get##name that returns the value of * the member variable with the specified name from the specified dictionary. - * * @param[in] name The name of the member variable to be retrieved. * @param[in] type The data type of the member variable. * @param[in] dictionary_name The name of the dictionary to retrieve the value from. @@ -75,23 +73,26 @@ namespace exageostat::configurations { Configurations(); /** - * @brief Virtual destructor to allow calls to the correct concrete destructor. + * @brief destructor to allow calls to the correct concrete destructor. * */ - virtual ~Configurations() = default; + ~Configurations(); /** * @brief Initialize the module arguments. * @param[in] aArgC The number of arguments being passed into the program from the command line. * @param[in] apArgV The array of arguments. + * @param[in] aEnableR check if R is enabled * @details This method initializes the command line arguments and set default values for unused args. + * @return void * */ - void InitializeArguments(const int &aArgC, char **apArgV); + void InitializeArguments(const int &aArgC, char **apArgV, const bool &aEnableR = false); /** * @brief Initialize the all theta arguments. * @return void + * */ void InitializeAllTheta(); @@ -190,7 +191,7 @@ namespace exageostat::configurations { CREATE_GETTER_FUNCTION(LoggerPath, std::string, "LoggerPath") - CREATE_SETTER_FUNCTION(InitialTheta, std::vector &, apTheta, "InitialTheta") + CREATE_SETTER_FUNCTION(InitialTheta, const std::vector &, apTheta, "InitialTheta") CREATE_GETTER_FUNCTION(InitialTheta, std::vector &, "InitialTheta") @@ -206,30 +207,26 @@ namespace exageostat::configurations { CREATE_GETTER_FUNCTION(Logger, bool, "Logger") - CREATE_SETTER_FUNCTION(P, int, aP, "P") - - CREATE_GETTER_FUNCTION(P, int, "P") - - CREATE_SETTER_FUNCTION(MeanSquareError, double, aMeanSquareError, "MeanSquareError") - - CREATE_GETTER_FUNCTION(MeanSquareError, double, "MeanSquareError") - - CREATE_SETTER_FUNCTION(LowerBounds, std::vector &, apTheta, "LowerBounds") + CREATE_SETTER_FUNCTION(LowerBounds, const std::vector &, apTheta, "LowerBounds") CREATE_GETTER_FUNCTION(LowerBounds, std::vector &, "LowerBounds") - CREATE_SETTER_FUNCTION(UpperBounds, std::vector &, apTheta, "UpperBounds") + CREATE_SETTER_FUNCTION(UpperBounds, const std::vector &, apTheta, "UpperBounds") CREATE_GETTER_FUNCTION(UpperBounds, std::vector &, "UpperBounds") - CREATE_SETTER_FUNCTION(EstimatedTheta, std::vector &, apTheta, "EstimatedTheta") + CREATE_SETTER_FUNCTION(EstimatedTheta, const std::vector &, apTheta, "EstimatedTheta") CREATE_GETTER_FUNCTION(EstimatedTheta, std::vector &, "EstimatedTheta") - CREATE_SETTER_FUNCTION(StartingTheta, std::vector &, apTheta, "StartingTheta") + CREATE_SETTER_FUNCTION(StartingTheta, const std::vector &, apTheta, "StartingTheta") CREATE_GETTER_FUNCTION(StartingTheta, std::vector &, "StartingTheta") + CREATE_SETTER_FUNCTION(IsNonGaussian, bool, aIsNonGaussian, "IsNonGaussian") + + CREATE_GETTER_FUNCTION(IsNonGaussian, bool, "IsNonGaussian") + /** * @brief Getter for the verbosity. * @return The verbosity mode. @@ -250,10 +247,6 @@ namespace exageostat::configurations { CREATE_GETTER_FUNCTION(IsSynthetic, bool, "IsSynthetic") - CREATE_SETTER_FUNCTION(IsCSV, bool, aIsCSV, "IsCSV") - - CREATE_GETTER_FUNCTION(IsCSV, bool, "IsCSV") - CREATE_SETTER_FUNCTION(DataPath, const std::string&, aDataPath, "DataPath") CREATE_GETTER_FUNCTION(DataPath, std::string, "DataPath") @@ -271,16 +264,6 @@ namespace exageostat::configurations { CREATE_SETTER_FUNCTION(FileLogName, const std::string&, aFileLogName, "FileLogName") - CREATE_GETTER_FUNCTION(FileLogName, std::string, "FileLogName") - - CREATE_SETTER_FUNCTION(AvgExecutedTimePerIteration, double, aAvgExecTimePerIter, "AvgExecuted") - - CREATE_GETTER_FUNCTION(AvgExecutedTimePerIteration, double, "AvgExecuted") - - CREATE_SETTER_FUNCTION(AvgFlopsPerIteration, double, aAvgFlopsPerIter, "AvgFlops") - - CREATE_GETTER_FUNCTION(AvgFlopsPerIteration, double, "AvgFlops") - CREATE_SETTER_FUNCTION(DistanceMetric, common::DistanceMetric, aDistanceMetric, "DistanceMetric") CREATE_GETTER_FUNCTION(DistanceMetric, common::DistanceMetric, "DistanceMetric") @@ -293,7 +276,7 @@ namespace exageostat::configurations { CREATE_GETTER_FUNCTION(Accuracy, int, "Accuracy") - CREATE_SETTER_FUNCTION(Tolerance, double, aTolerance, "Tolerance") + void SetTolerance(double aTolerance); CREATE_GETTER_FUNCTION(Tolerance, double, "Tolerance") @@ -320,6 +303,10 @@ namespace exageostat::configurations { CREATE_GETTER_FUNCTION(IsFisher, bool, "IsFisher") + CREATE_SETTER_FUNCTION(ObservationNumber, int, aObservationsNumber, "ObservationNumber") + + CREATE_GETTER_FUNCTION(ObservationNumber, int, "ObservationNumber") + /** END OF THE DATA PREDICTION MODULES. **/ /** @@ -332,7 +319,7 @@ namespace exageostat::configurations { /** * @brief Checks the value of the dimension parameter. - * @param[in] aDimension A string representing the dimension. + * @param[in] aDimension A string represents the dimension. * @return The corresponding dimension value. * */ @@ -364,8 +351,9 @@ namespace exageostat::configurations { /** * @brief Checks the value of the unknown observations parameter. - * @param[in] aValue A string representing the number of unknown observations. + * @param[in] aValue A string represents the number of unknown observations. * @return The corresponding integer value. + * */ int CheckUnknownObservationsValue(const std::string &aValue); @@ -381,37 +369,16 @@ namespace exageostat::configurations { /** * @brief print the summary of MLE inputs. * @return void + * */ - inline void PrintSummary(); + void PrintSummary(); /** * @brief Calculates the number of observed measurements. * @return number of observed measurements. - */ - int CalculateZObsNumber(); - - - private: - - /// static bool to make sure that print summary is only performed once. - static bool mIsPrinted; - - /** - * @brief Checks the run mode and sets the verbosity level. - * @param[in] aVerbosity A string representing the desired run mode ("verbose" or "standard"). - * @throws std::range_error if the input string is not "verbose" or "standard". - * @return void - * - */ - static void ParseVerbose(const std::string &aVerbosity); - - /** - * @brief Checks if a given string is in camel case format. - * @param[in] aString The string to check. - * @return true if the string is in camel case format, false otherwise. * */ - static bool IsCamelCase(const std::string &aString); + int CalculateZObsNumber(); /** * @brief Parses a string of theta values and returns an array of doubles. @@ -421,21 +388,33 @@ namespace exageostat::configurations { */ static std::vector ParseTheta(const std::string &aInputValues); + /** * @brief parse user's input to distance metric. * @param[in] aDistanceMetric string specifying the used distance metric. * @return void + * */ void ParseDistanceMetric(const std::string &aDistanceMetric); + private: + /** - * @brief Initializes the log file. - * @details This function attempts to open a log file with the name returned by GetFileLogName(), - * and sets the file log path accordingly. If an exception occurs during the file opening, - * a default log file named "log_file" is created. + * @brief Checks the run mode and sets the verbosity level. + * @param[in] aVerbosity A string represents the desired run mode ("verbose" or "standard"). + * @throws std::range_error if the input string is not "verbose" or "standard". * @return void + * */ - void InitLog(); + static void ParseVerbose(const std::string &aVerbosity); + + /** + * @brief Checks if a given string is in camel case format. + * @param[in] aString The string to check. + * @return true if the string is in camel case format, false otherwise. + * + */ + static bool IsCamelCase(const std::string &aString); /// Used Dictionary std::unordered_map mDictionary; @@ -447,9 +426,11 @@ namespace exageostat::configurations { static exageostat::common::Verbose mVerbosity; //// Used bool for init theta static bool mIsThetaInit; - + //// Used bool for R allocated memory on heap + static bool mHeapAllocated; + //// Used bool for indicating the first init of configurations for printing summary + static bool mFirstInit; }; }//namespace exageostat #endif //EXAGEOSTAT_CPP_CONFIGURATIONS_HPP - diff --git a/inst/include/data-generators/DataGenerator.hpp b/inst/include/data-generators/DataGenerator.hpp index e0c167cb..2e5d4344 100644 --- a/inst/include/data-generators/DataGenerator.hpp +++ b/inst/include/data-generators/DataGenerator.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DataGenerator.hpp * @brief Contains definition for abstract Data Generator Class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-02-14 **/ @@ -14,8 +14,6 @@ #ifndef EXAGEOSTAT_CPP_DATAGENERATOR_HPP #define EXAGEOSTAT_CPP_DATAGENERATOR_HPP -#include - #include #include @@ -36,13 +34,12 @@ namespace exageostat::generators { * @brief Either generates synthetic data or reads data files. * @details This method generates the X, Y, and Z variables used to define the locations of the data points. * @param[in] aConfigurations Reference to the data configurations. - * @param[in] aHardware Reference to the used hardware. - * @return Pointer to a populated data. + * @param[in] aKernel Reference to the used Kernel. + * @return unique Pointer to a populated data. * */ - virtual dataunits::ExaGeoStatData * - CreateData(exageostat::configurations::Configurations &aConfigurations, - const exageostat::hardware::ExaGeoStatHardware &aHardware, + virtual std::unique_ptr> + CreateData(configurations::Configurations &aConfigurations, exageostat::kernels::Kernel &aKernel) = 0; /** @@ -53,7 +50,7 @@ namespace exageostat::generators { * */ static std::unique_ptr - CreateGenerator(exageostat::configurations::Configurations &aConfigurations); + CreateGenerator(configurations::Configurations &aConfigurations); /** * @brief Destructor for the data generator object. @@ -63,10 +60,9 @@ namespace exageostat::generators { virtual ~DataGenerator(); protected: - /// Used bool identifying type of generation. - static bool mIsSynthetic; - /// Used bool identifying type of generation. - static bool mIsCSV; + + /// Used enum for data generators types. + static common::DataSourceType aDataSourceType; }; /** diff --git a/inst/include/data-generators/LocationGenerator.hpp b/inst/include/data-generators/LocationGenerator.hpp new file mode 100644 index 00000000..798d2271 --- /dev/null +++ b/inst/include/data-generators/LocationGenerator.hpp @@ -0,0 +1,74 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file LocationGenerator.hpp + * @brief Generates and manages spatial locations for ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-04 +**/ + +#ifndef EXAGEOSTATCPP_LOCATIONGENERATOR_HPP +#define EXAGEOSTATCPP_LOCATIONGENERATOR_HPP + +#include + +namespace exageostat::generators { + + /** + * @class LocationGenerator + * @brief Generates spatial locations based on given parameters. + * @tparam T Data Type: float or double + * + */ + template + class LocationGenerator { + + public: + + /** + * @brief Generates the data locations. + * @details This method generates the X, Y, and Z variables used to define the locations of the data points. + * @param[in] aN The number of data points. + * @param[in] aTimeSlot The time slot. + * @param[in] aDimension The dimension of the locations. + * @param[out] aLocations Reference to the Locations object where the generated data will be stored. + * @return void + * + */ + static void GenerateLocations(const int &aN, const int &aTimeSlot, const common::Dimension &aDimension, + dataunits::Locations &aLocations); + + /** + * @brief Generate uniform distribution between rangeLow , rangeHigh. + * @param[in] aRangeLow The Lower range. + * @param[in] aRangeHigh The Higher range. + * @return The scaled uniform distribution between the two bounds. + * + */ + static T UniformDistribution(const T &aRangeLow, const T &aRangeHigh); + + /** + * @brief Sort locations in Morton order (input points must be in [0;1]x[0;1] square]). + * @param[in] aN The problem size divided by P-Grid. + * @param[in] aDimension Dimension of locations. + * @param[in,out] aLocations Locations to be sorted. + * @return void + * + */ + static void + SortLocations(const int &aN, const common::Dimension &aDimension, dataunits::Locations &aLocations); + }; + + /** + * @brief Instantiates the Data Generator class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(LocationGenerator) +}//namespace exageostat + +#endif //EXAGEOSTATCPP_LOCATIONGENERATOR_HPP diff --git a/inst/include/data-generators/concrete/CSVDataGenerator.hpp b/inst/include/data-generators/concrete/CSVDataGenerator.hpp deleted file mode 100644 index 5ad3e266..00000000 --- a/inst/include/data-generators/concrete/CSVDataGenerator.hpp +++ /dev/null @@ -1,98 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file CSVDataGenerator.hpp - * @brief A class for generating synthetic data. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-02-14 -**/ - -#ifndef EXAGEOSTAT_CPP_CSVDATAGENERATOR_HPP -#define EXAGEOSTAT_CPP_CSVDATAGENERATOR_HPP - -#include - -namespace exageostat::generators::csv { - - /** - * @class CSVDataGenerator - * @brief A class for creating data by reading CSV files. - * @tparam T Data Type: float or double - */ - template - class CSVDataGenerator : public DataGenerator { - public: - - /** - * @brief Get a pointer to the singleton instance of the CSVDataGenerator class. - * @return A pointer to the instance of the CSVDataGenerator class. - * - */ - static CSVDataGenerator *GetInstance(); - - /** - * @brief Creates the data by reading a CSV file. - * @copydoc DataGenerator::CreateData() - * - */ - dataunits::ExaGeoStatData * - CreateData(exageostat::configurations::Configurations &, - const exageostat::hardware::ExaGeoStatHardware &aHardware, - exageostat::kernels::Kernel &aKernel) override; - - /** - * @brief Reads CSV files containing 2D, 3D, or ST locations, and measurements vector. - * @param aConfigurations Reference to the Configurations object. - * @param aMeasurementsMatrix Reference to the Measurement matrix to be filled with read data. - * @param aXLocations Reference to the location's x coordinates matrix to be filled with read data. - * @param aYLocations Reference to the location's y coordinates matrix to be filled with read data. - * @param aZLocations Reference to the location's z coordinates matrix to be filled with read data. - * @return void - */ - void - ReadData(exageostat::configurations::Configurations &aConfigurations, std::vector &aMeasurementsMatrix, - std::vector &aXLocations, - std::vector &aYLocations, std::vector &aZLocations); - - /** - * @brief Release the singleton instance of the CSVDataGenerator class. - * @return void - * - */ - static void ReleaseInstance(); - - private: - /** - * @brief Constructor for the CSVDataGenerator class. - * @return void - * - */ - CSVDataGenerator() = default; - - /** - * @brief Default destructor. - * - */ - ~CSVDataGenerator() override = default; - - /** - * @brief Pointer to the singleton instance of the CSVDataGenerator class. - * - */ - static CSVDataGenerator *mpInstance; - - }; - - /** - * @brief Instantiates the CSV Data Generator class for float and double types. - * @tparam T Data Type: float or double - * - */ - EXAGEOSTAT_INSTANTIATE_CLASS(CSVDataGenerator) -} -#endif //EXAGEOSTAT_CPP_CSVDATAGENERATOR_HPP \ No newline at end of file diff --git a/inst/include/data-generators/concrete/SyntheticGenerator.hpp b/inst/include/data-generators/concrete/SyntheticGenerator.hpp index a4d0aeae..d159f161 100644 --- a/inst/include/data-generators/concrete/SyntheticGenerator.hpp +++ b/inst/include/data-generators/concrete/SyntheticGenerator.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file SyntheticGenerator.hpp * @brief A class for generating synthetic data. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-02-14 @@ -38,74 +38,15 @@ namespace exageostat::generators::synthetic { */ static SyntheticGenerator *GetInstance(); - /** - * @brief Generates the data locations. - * @details This method generates the X, Y, and Z variables used to define the locations of the data points. - * @param[in] aN The number of data points. - * @param[in] aTimeSlot The time slot. - * @param[in] aDimension The dimension of the locations. - * @param[out] aLocations Reference to the Locations object where the generated data will be stored. - * @return void - * - */ - void GenerateLocations(const int &aN, const int &aTimeSlot, const common::Dimension &aDimension, - dataunits::Locations &aLocations); - /** * @brief Creates the data by synthetically generating it. * @copydoc DataGenerator::CreateData() * */ - dataunits::ExaGeoStatData * - CreateData(exageostat::configurations::Configurations &aConfigurations, - const exageostat::hardware::ExaGeoStatHardware &aHardware, + std::unique_ptr> + CreateData(configurations::Configurations &aConfigurations, exageostat::kernels::Kernel &aKernel) override; - /** - * @brief Generate uniform distribution between rangeLow , rangeHigh. - * @param[in] aRangeLow The Lower range. - * @param[in] aRangeHigh The Higher range. - * @return The scaled uniform distribution between the two bounds. - * - */ - static double UniformDistribution(const double &aRangeLow, const double &aRangeHigh); - - /** - * @brief Sort locations in Morton order (input points must be in [0;1]x[0;1] square]). - * @param[in] aN The problem size divided by P-Grid. - * @param[in] aDimension Dimension of locations. - * @param[in,out] aLocations Locations to be sorted. - * @return void - * - */ - void - SortLocations(const int &aN, const common::Dimension &aDimension, dataunits::Locations &aLocations); - - /** - * @brief Spread bits by three spaces. - * @param[in] aInputByte The input 64 bit to be spread. - * @return The byte after being spread. - * - */ - static uint64_t SpreadBits(uint64_t aInputByte); - - /** - * @brief Reverse Spread bits operation. - * @param[in] aInputByte The input spread 64 bit to be compacted. - * @return The byte after being compacted. - * - */ - static uint64_t ReverseSpreadBits(uint64_t aInputByte); - - /** - * @brief Compares two Unit64 values - * @param[in] aFirstValue Constant reference to the first input 64 bit value. - * @param[in] aSecondValue Constant reference to the second input 64 bit value. - * @return True if the second value is bigger than the first value, false otherwise. - * - */ - static bool CompareUint64(const uint64_t &aFirstValue, const uint64_t &aSecondValue); - /** * @brief Release the singleton instance of the SyntheticGenerator class. * @return void diff --git a/inst/include/data-loader/DataLoader.hpp b/inst/include/data-loader/DataLoader.hpp new file mode 100644 index 00000000..5f530bd6 --- /dev/null +++ b/inst/include/data-loader/DataLoader.hpp @@ -0,0 +1,80 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file DataLoader.hpp + * @brief Manages data loading operations for ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-04 +**/ + +#ifndef EXAGEOSTATCPP_DATALOADER_HPP +#define EXAGEOSTATCPP_DATALOADER_HPP + +#include + +namespace exageostat::dataLoader { + + /** + * @class DataLoader + * @brief Extends DataGenerator to include data loading functionalities. + * @tparam T Data Type: float or double + * + */ + template + class DataLoader : public generators::DataGenerator { + + public: + + /** + * @brief Creates the data by synthetically generating it. + * @copydoc DataGenerator::CreateData() + * + */ + std::unique_ptr> + CreateData(configurations::Configurations &aConfigurations, kernels::Kernel &aKernel) override; + + /** + * @brief Reads data from external sources into ExaGeoStat format. + * @param aConfigurations Configuration settings for data loading. + * @param aMeasurementsMatrix Vector to store measurement values. + * @param aXLocations Vector to store X coordinates of locations. + * @param aYLocations Vector to store Y coordinates of locations. + * @param aZLocations Vector to store Z coordinates of locations (if applicable). + * @param aP Partition index for distributed data loading. + * @return void + * + */ + virtual void + ReadData(configurations::Configurations &aConfigurations, std::vector &aMeasurementsMatrix, + std::vector &aXLocations, + std::vector &aYLocations, std::vector &aZLocations, const int &aP) = 0; + + /** + * @brief Writes a matrix of vectors to disk. + * @param[in] aMatrixPointer A Reference to the matrix data. + * @param[in] aProblemSize The size of the problem. + * @param[in] aP The number of processes. + * @param[in] aLoggerPath The path to the logger file. + * @param[in] aLocations A Reference to the Locations object. + * @return void + * + */ + virtual void + WriteData(const T &aMatrixPointer, const int &aProblemSize, const int &aP, std::string &aLoggerPath, + exageostat::dataunits::Locations &aLocations) = 0; + }; + + /** + * @brief Instantiates the Synthetic Data Generator class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DataLoader) +} // namespace exageostat + +#endif //EXAGEOSTATCPP_DATALOADER_HPP diff --git a/inst/include/data-loader/concrete/CSVLoader.hpp b/inst/include/data-loader/concrete/CSVLoader.hpp new file mode 100644 index 00000000..52b185bd --- /dev/null +++ b/inst/include/data-loader/concrete/CSVLoader.hpp @@ -0,0 +1,92 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file CSVLoader.hpp + * @brief A class for generating synthetic data. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-04 +**/ + +#ifndef EXAGEOSTAT_CPP_CSVDATALOADER_HPP +#define EXAGEOSTAT_CPP_CSVDATALOADER_HPP + +#include + +namespace exageostat::dataLoader::csv { + + /** + * @class CSVLoader + * @brief A class for creating data by reading CSV files. + * @tparam T Data Type: float or double + */ + template + class CSVLoader : public DataLoader { + public: + + /** + * @brief Get a pointer to the singleton instance of the CSVLoader class. + * @return A pointer to the instance of the CSVLoader class. + * + */ + static CSVLoader *GetInstance(); + + /** + * @brief Reads data from external sources into ExaGeoStat format. + * @copydoc DataLoader::ReadData() + * + */ + void ReadData(configurations::Configurations &aConfigurations, std::vector &aMeasurementsMatrix, + std::vector &aXLocations, std::vector &aYLocations, std::vector &aZLocations, + const int &aP) override; + + /** + * @brief Writes a matrix of vectors to disk. + * @copydoc DataLoader::WriteData() + * + */ + void + WriteData(const T &aMatrixPointer, const int &aProblemSize, const int &aP, std::string &aLoggerPath, + exageostat::dataunits::Locations &aLocations) override; + + /** + * @brief Release the singleton instance of the CSVLoader class. + * @return void + * + */ + static void ReleaseInstance(); + + private: + /** + * @brief Constructor for the CSVLoader class. + * @return void + * + */ + CSVLoader() = default; + + /** + * @brief Default destructor. + * + */ + ~CSVLoader() override = default; + + /** + * @brief Pointer to the singleton instance of the CSVLoader class. + * + */ + static CSVLoader *mpInstance; + + }; + + /** + * @brief Instantiates the CSV Data Generator class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(CSVLoader) +} +#endif //EXAGEOSTAT_CPP_CSVDATALOADER_HPP \ No newline at end of file diff --git a/inst/include/data-units/DescriptorData.hpp b/inst/include/data-units/DescriptorData.hpp index 242f2ec1..4c2b1d89 100644 --- a/inst/include/data-units/DescriptorData.hpp +++ b/inst/include/data-units/DescriptorData.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DescriptorData.hpp * @brief Contains the definition of the DescriptorData class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-07-18 @@ -15,18 +15,21 @@ #ifndef EXAGEOSTATCPP_DESCRIPTORDATA_HPP #define EXAGEOSTATCPP_DESCRIPTORDATA_HPP +#include + #include #include namespace exageostat::dataunits { /** - * @brief Union representing the base descriptor. + * @brief Union represents the base descriptor. * @details This union is used to store different types of descriptors based on the configuration. + * */ union BaseDescriptor { CHAM_desc_t *chameleon_desc; -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA HICMA_desc_t *hicma_desc; #endif }; @@ -35,6 +38,7 @@ namespace exageostat::dataunits { * @Class DescriptorData * @brief Manages geo-statistical descriptor data with functions for retrieving and manipulating descriptors * @tparam T Data Type: float or double + * */ template class DescriptorData { @@ -42,21 +46,24 @@ namespace exageostat::dataunits { public: /** * @brief Default Constructor for DescriptorData. + * */ explicit DescriptorData() = default; /** * @brief Destructor for DescriptorData. + * */ - virtual ~DescriptorData(); + ~DescriptorData(); /** * @brief Get the base descriptor. * @param[in] aDescriptorType The type of the descriptor. * @param[in] aDescriptorName The name of the descriptor. * @return The base descriptor. - * @throws std::runtime_error if the corresponding library is not enabled (EXAGEOSTAT_USE_CHAMELEON or EXAGEOSTAT_USE_HICMA). + * @throws std::runtime_error if the corresponding library is not enabled (USE_HICMA). + * */ BaseDescriptor GetDescriptor(const common::DescriptorType &aDescriptorType, const common::DescriptorName &aDescriptorName); @@ -71,7 +78,7 @@ namespace exageostat::dataunits { /** * @brief Set the sequence. * @param[in] apSequence Pointer to the sequence. - * + * @return void */ void SetSequence(void *apSequence); @@ -85,18 +92,22 @@ namespace exageostat::dataunits { /** * @brief Set the request. * @param[in] apRequest Pointer to the request. + * @return void * */ void SetRequest(void *apRequest); -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA /** * @brief Converts a CHAMELEON descriptor to a HICMA descriptor. * @param[in] apChameleonDesc Pointer to the CHAMELEON descriptor to be converted. + * @param[in] aDescriptorName The name of the descriptor. * @return Pointer to the converted HICMA descriptor. + * */ - HICMA_desc_t *ConvertChameleonToHicma(CHAM_desc_t *apChameleonDesc); + HICMA_desc_t * + ConvertChameleonToHicma(CHAM_desc_t *apChameleonDesc, const common::DescriptorName &aDescriptorName); #endif @@ -118,32 +129,40 @@ namespace exageostat::dataunits { * @param[in] aN The number of columns in the sub-matrix. * @param[in] aP The number of rows in the complete matrix. * @param[in] aQ The number of columns in the complete matrix. + * @param[in] aValidOOC Boolean refer to whether this descriptor can be created with OOC technology or not, default is true + * @param[in] aConverted Boolean indicates whether it's a converted descriptor from chameleon to hicma or not, default is false * @return void - * @throws std::runtime_error if the corresponding library is not enabled (EXAGEOSTAT_USE_CHAMELEON or EXAGEOSTAT_USE_HICMA). + * @throws std::runtime_error if the corresponding library is not enabled (USE_HICMA). + * */ void SetDescriptor(const common::DescriptorType &aDescriptorType, const common::DescriptorName &aDescriptorName, const bool &aIsOOC, void *apMatrix, const common::FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, - const int &aJ, const int &aM, const int &aN, const int &aP, const int &aQ); + const int &aJ, const int &aM, const int &aN, const int &aP, const int &aQ, + const bool &aValidOOC = true, const bool &aConverted = false); /** * @brief Getter for the Descriptor matrix. * @param[in] aDescriptorType Type of the descriptor, whether it's CHAMELEON or HiCMA. - * @param[in] apDescriptor Pointer to the descriptor. + * @param[in] aDescriptorName The name of the descriptor. * @return pointer to the Descriptor matrix. - * @throws std::runtime_error if the corresponding library is not enabled (EXAGEOSTAT_USE_CHAMELEON or EXAGEOSTAT_USE_HICMA). + * @throws std::runtime_error if the corresponding library is not enabled (USE_HICMA). + * */ - T *GetDescriptorMatrix(const common::DescriptorType &aDescriptorType, void *apDescriptor); + T *GetDescriptorMatrix(const common::DescriptorType &aDescriptorType, + const common::DescriptorName &aDescriptorName); /** * @brief Getter for the mIsDescriptorInitiated field. * @return mIsDescriptorInitiated + * */ bool GetIsDescriptorInitiated(); /** * @brief Setter for mIsDescriptorInitiated field. * @param aIsInitiated Boolean for setting the mIsDescriptorInitiated field. + * */ void SetIsDescriptorInitiated(bool aIsInitiated); @@ -153,6 +172,7 @@ namespace exageostat::dataunits { * @param[in] aDescriptorName The descriptor name. * @return The descriptor name as a string. * @throws std::invalid_argument if the provided descriptor name is not available. + * */ std::string GetDescriptorName(const common::DescriptorName &aDescriptorName); diff --git a/inst/include/data-units/ExaGeoStatData.hpp b/inst/include/data-units/ExaGeoStatData.hpp index c35f1ac8..bc9017bf 100644 --- a/inst/include/data-units/ExaGeoStatData.hpp +++ b/inst/include/data-units/ExaGeoStatData.hpp @@ -1,15 +1,15 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatData.hpp * @brief Contains the definition of the ExaGeoStatData class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-07-19 + * @date 2024-02-04 **/ #ifndef EXAGEOSTATCPP_EXAGEOSTATDATA_HPP @@ -17,90 +17,103 @@ #include #include -#include -#include -namespace exageostat::dataunits { +/** + * @Class ExaGeoStatData + * @brief Manages geo-statistical data with functions for location and descriptor manipulation + * @tparam T Data Type: float or double + */ +template +class ExaGeoStatData { + +public: + /** + * @brief Constructor for ExaGeoStatData. + * @param[in] aSize The size of the data. + * @param[in] aDimension The dimension of the data. + * + */ + ExaGeoStatData(const int &aSize, const exageostat::common::Dimension &aDimension); + + /** + * @brief Constructor for ExaGeoStatData. + * @param[in] aSize The size of the data. + * @param[in] aDimension The dimension of the data. + * + */ + ExaGeoStatData(const int &aSize, const std::string &aDimension); + + /** + * @brief Default constructor for ExaGeoStatData. + * + */ + ExaGeoStatData() = default; /** - * @Class ExaGeoStatData - * @brief Manages geo-statistical data with functions for location and descriptor manipulation - * @tparam T Data Type: float or double + * @brief Destructor for ExaGeoStatData. + * */ - template - class ExaGeoStatData { - - public: - /** - * @brief Constructor for ExaGeoStatData. - * @param[in] aSize The size of the data. - * @param[in] aDimension The dimension of the data. - */ - ExaGeoStatData(const int &aSize, const exageostat::common::Dimension &aDimension); - - /** - * @brief Default constructor for ExaGeoStatData. - */ - ExaGeoStatData() = default; - - /** - * @brief Destructor for ExaGeoStatData. - */ - ~ExaGeoStatData(); - - /** - * @brief Get the locations. - * @return Pointer to the Locations object. - */ - Locations *GetLocations(); - - /** - * @brief Set the locations. - * @param[in] aLocation Pointer to the Locations object. - */ - void SetLocations(Locations &aLocation); - - /** - * @brief Get the descriptor data. - * @return Pointer to the DescriptorData object. - */ - DescriptorData *GetDescriptorData(); - - /** - * @brief Setter for the number of performed MLE iterations. - * @param[in] aMleIterations number of performed MLE iterations. - * @return void - */ - void SetMleIterations(const int &aMleIterations); - - /** - * @brief Get the number of performed MLE iterations. - * @return Pointer to the DescriptorData object. - */ - int GetMleIterations(); - - /** - * @brief Calculates Median Locations. - * @param[in] aKernelName Name of the Kernel used. - * @param[out] aLocations Location object to save medianLocations in. - * @return void - */ - void CalculateMedianLocations(const std::string &aKernelName, dataunits::Locations &aLocations); - - private: - //// Used descriptor data. - DescriptorData *mpDescriptorData = nullptr; - //// Used locations data. - Locations *mpLocations = nullptr; - //// Current number of performed MLE iterations. - int mMleIterations = 0; - }; + ~ExaGeoStatData(); /** - * @brief Instantiates the ExaGeoStatData class for float and double types. - * @tparam T Data Type: float or double + * @brief Get the locations. + * @return Pointer to the Locations object. + * */ - EXAGEOSTAT_INSTANTIATE_CLASS(ExaGeoStatData) -} // namespace exageostat + exageostat::dataunits::Locations *GetLocations(); + + /** + * @brief Set the locations. + * @param[in] aLocation Pointer to the Locations object. + * @return void + * + */ + void SetLocations(exageostat::dataunits::Locations &aLocation); + + /** + * @brief Get the descriptor data. + * @return Pointer to the DescriptorData object. + * + */ + exageostat::dataunits::DescriptorData *GetDescriptorData(); + + /** + * @brief Setter for the number of performed MLE iterations. + * @param[in] aMleIterations number of performed MLE iterations. + * @return void + * + */ + void SetMleIterations(const int &aMleIterations); + + /** + * @brief Get the number of performed MLE iterations. + * @return Pointer to the DescriptorData object. + * + */ + int GetMleIterations(); + + /** + * @brief Calculates Median Locations. + * @param[in] aKernelName Name of the Kernel used. + * @param[out] aLocations Location object to save medianLocations in. + * @return void + * + */ + void CalculateMedianLocations(const std::string &aKernelName, exageostat::dataunits::Locations &aLocations); + +private: + //// Used descriptor data. + exageostat::dataunits::DescriptorData *mpDescriptorData = nullptr; + //// Used locations data. + exageostat::dataunits::Locations *mpLocations = nullptr; + //// Current number of performed MLE iterations. + int mMleIterations = 0; +}; + +/** + * @brief Instantiates the ExaGeoStatData class for float and double types. + * @tparam T Data Type: float or double + */ +EXAGEOSTAT_INSTANTIATE_CLASS(ExaGeoStatData) #endif //EXAGEOSTATCPP_EXAGEOSTATDATA_HPP \ No newline at end of file diff --git a/inst/include/data-units/Locations.hpp b/inst/include/data-units/Locations.hpp index 032be1f9..72115ddd 100644 --- a/inst/include/data-units/Locations.hpp +++ b/inst/include/data-units/Locations.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Locations.hpp * @brief Header file for the Locations class, which contains methods to set and get location data. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-02-27 @@ -39,14 +39,15 @@ namespace exageostat::dataunits { /** * @brief Default copy constructor. * @param[in] aLocations Locations to be copied. + * */ Locations(const Locations &aLocations) = default; /** - * @brief Virtual destructor to allow calls to the correct concrete destructor. + * @brief destructor for Locations. * */ - virtual ~Locations(); + ~Locations(); /** * @brief Setter for LocationX. diff --git a/inst/include/data-units/ModelingDataHolders.hpp b/inst/include/data-units/ModelingDataHolders.hpp index b0efc0f7..bc9b8f15 100644 --- a/inst/include/data-units/ModelingDataHolders.hpp +++ b/inst/include/data-units/ModelingDataHolders.hpp @@ -1,7 +1,7 @@ /** * @file ModelingDataHolders.hpp * @brief This file contains the definition of the mModelingData struct, which contains all the data needed for modeling. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-08-24 **/ @@ -18,11 +18,9 @@ namespace exageostat::dataunits { template struct mModelingData { /// ExaGeoStatData object containing needed descriptors, and locations. - dataunits::ExaGeoStatData *mpData; + std::unique_ptr> *mpData; /// Configurations object containing user input data. configurations::Configurations *mpConfiguration; - /// Hardware configuration for the ExaGeoStat solver. - const hardware::ExaGeoStatHardware *mpHardware; /// Used Kernel for ExaGeoStat Modeling Data. const kernels::Kernel *mpKernel; @@ -33,13 +31,12 @@ namespace exageostat::dataunits { * @brief Constructor. * @param aData The ExaGeoStatData object. * @param aConfiguration The Configurations object. - * @param aHardware The hardware configuration object. * @param aKernel The Kernel object. */ - mModelingData(dataunits::ExaGeoStatData &aData, configurations::Configurations &aConfiguration, - const hardware::ExaGeoStatHardware &aHardware, T &aMatrix, const kernels::Kernel &aKernel) : - mpData(std::move(&aData)), mpConfiguration(&aConfiguration), mpHardware(&aHardware), - mpMeasurementsMatrix(&aMatrix), mpKernel(&aKernel) {} + mModelingData(std::unique_ptr> &aData, configurations::Configurations &aConfiguration, + T &aMatrix, const kernels::Kernel &aKernel) : + mpData(std::move(&aData)), mpConfiguration(&aConfiguration), mpMeasurementsMatrix(&aMatrix), + mpKernel(&aKernel) {} }; }//namespace exageostat diff --git a/inst/include/data-units/descriptor/ExaGeoStatDescriptor.hpp b/inst/include/data-units/descriptor/ExaGeoStatDescriptor.hpp index ab82aeb5..fbf1eb3d 100644 --- a/inst/include/data-units/descriptor/ExaGeoStatDescriptor.hpp +++ b/inst/include/data-units/descriptor/ExaGeoStatDescriptor.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatDescriptor.hpp * @brief Class for creating matrix descriptors used in CHAMELEON and HiCMA libraries. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-07-16 @@ -15,8 +15,6 @@ #ifndef EXAGEOSTATCPP_EXAGEOSTATDESCRIPTOR_HPP #define EXAGEOSTATCPP_EXAGEOSTATDESCRIPTOR_HPP -#include - #include #include #include @@ -69,13 +67,14 @@ namespace exageostat::dataunits::descriptor { * @param[in] aN The number of columns of the sub-matrix. * @param[in] aP The number of rows of the 2D distribution grid. * @param[in] aQ The number of columns of the 2D distribution grid. + * @param[in] aValidOOC Boolean refer to whether this descriptor can be created with OOC technology or not. * @return A pointer to the newly created descriptor. * */ void *CreateDescriptor(void *apDescriptor, const common::DescriptorType &aDescriptorType, const bool &aIsOOC, void *apMatrix, const common::FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, - const int &aM, const int &aN, const int &aP, const int &aQ); + const int &aM, const int &aN, const int &aP, const int &aQ, const bool &aValidOOC); /** * @brief destroys and finalize a descriptor diff --git a/inst/include/data-units/descriptor/concrete/ChameleonDescriptor.hpp b/inst/include/data-units/descriptor/concrete/ChameleonDescriptor.hpp index 1d8ce866..cabe7557 100644 --- a/inst/include/data-units/descriptor/concrete/ChameleonDescriptor.hpp +++ b/inst/include/data-units/descriptor/concrete/ChameleonDescriptor.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ChameleonDescriptor.hpp * @brief Defines the ChameleonDescriptor class for creating matrix descriptors using the CHAMELEON library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-08-15 @@ -16,7 +16,6 @@ #define EXAGEOSTATCPP_CHAMELEONDESCRIPTOR_HPP #include - #include namespace exageostat::dataunits::descriptor { @@ -47,6 +46,7 @@ namespace exageostat::dataunits::descriptor { * @param[in] aN The number of columns of the sub-matrix. * @param[in] aP The number of rows of the 2D distribution grid. * @param[in] aQ The number of columns of the 2D distribution grid. + * @param[in] aValidOOC Boolean refer to whether this descriptor can be created with OOC technology or not. * @return A pointer to the newly created CHAM_desc_t descriptor. * */ @@ -54,7 +54,7 @@ namespace exageostat::dataunits::descriptor { const common::FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, const int &aM, const int &aN, - const int &aP, const int &aQ); + const int &aP, const int &aQ, const bool &aValidOOC); /** * @brief destroys and finalize a descriptor diff --git a/inst/include/data-units/descriptor/concrete/HicmaDescriptor.hpp b/inst/include/data-units/descriptor/concrete/HicmaDescriptor.hpp index 7d62663d..0ffb27fe 100644 --- a/inst/include/data-units/descriptor/concrete/HicmaDescriptor.hpp +++ b/inst/include/data-units/descriptor/concrete/HicmaDescriptor.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file HicmaDescriptor.hpp * @brief Defines the Hicma Descriptor class for creating matrix descriptors using the HICMA library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-08-15 @@ -16,7 +16,6 @@ #define EXAGEOSTATCPP_HICMADESCRIPTOR_HPP #include - #include namespace exageostat::dataunits::descriptor { @@ -47,6 +46,7 @@ namespace exageostat::dataunits::descriptor { * @param[in] aN The number of columns of the sub-matrix. * @param[in] aP The number of rows of the 2D distribution grid. * @param[in] aQ The number of columns of the 2D distribution grid. + * @param[in] aValidOOC Boolean refer to whether this descriptor can be created with OOC technology or not. * @return A pointer to the newly created HICMA_desc_t descriptor. * */ @@ -54,7 +54,7 @@ namespace exageostat::dataunits::descriptor { const common::FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, const int &aM, const int &aN, - const int &aP, const int &aQ); + const int &aP, const int &aQ, const bool &aValidOOC); /** * @brief destroys and finalize a descriptor diff --git a/inst/include/hardware/ExaGeoStatHardware.hpp b/inst/include/hardware/ExaGeoStatHardware.hpp index a5daf00b..6e872091 100644 --- a/inst/include/hardware/ExaGeoStatHardware.hpp +++ b/inst/include/hardware/ExaGeoStatHardware.hpp @@ -1,15 +1,15 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatHardware.hpp * @brief Contains the definition of the ExaGeoStatHardware class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-08-07 + * @date 2024-01-24 **/ #ifndef EXAGEOSTATCPP_EXAGEOSTATHARDWARE_HPP @@ -17,64 +17,131 @@ #include -namespace exageostat::hardware { +/** + * @brief Class represents the hardware configuration for the ExaGeoStat solver. + * + */ +class ExaGeoStatHardware { +public: /** - * @brief Class representing the hardware configuration for the ExaGeoStat solver. + * @brief Constructor for ExaGeoStatHardware. + * @param[in] aComputation The computation mode for the solver. + * @param[in] aCoreNumber The number of CPU cores to use for the solver. + * @param[in] aGpuNumber The number of GPUs to use for the solver. + * @param[in] aP The P grid dimension setting, default is 1. + * @param[in] aQ The Q grid dimension setting, default is 1. + * */ - class ExaGeoStatHardware { - - public: - /** - * @brief Constructor for ExaGeoStatHardware. - * @param[in] aComputation The computation mode for the solver. - * @param[in] aCoreNumber The number of CPU cores to use for the solver. - * @param[in] aGpuNumber The number of GPUs to use for the solver. - * - */ - ExaGeoStatHardware(const common::Computation &aComputation, const int &aCoreNumber, const int &aGpuNumber); - - /** - * @brief Destructor for ExaGeoStatHardware. - */ - virtual ~ExaGeoStatHardware(); - - /** - * @brief Get the Chameleon hardware context. - * @return Pointer to the hardware context. - * - */ - [[nodiscard]] void *GetChameleonContext() const; - -#ifdef EXAGEOSTAT_USE_HICMA + explicit ExaGeoStatHardware(const exageostat::common::Computation &aComputation, const int &aCoreNumber, + const int &aGpuNumber, const int &aP = 1, const int &aQ = 1); -/** - * @brief Get the Hicma hardware context. - * @return Pointer to the hardware context. - * - */ - [[nodiscard]] void *GetHicmaContext() const; - -#endif - - /** - * @brief Get the hardware context. - * @param[in] aComputation Used computation to decide whether to use Hicma or Chameleon context. - * @return Pointer to the hardware context. - * - */ - [[nodiscard]] void *GetContext(common::Computation aComputation) const; - - private: - //// Used Pointer to the Chameleon hardware context. - void *mpChameleonContext = nullptr; -#ifdef EXAGEOSTAT_USE_HICMA - //// Used Pointer to the Hicma hardware context. - void *mpHicmaContext = nullptr; -#endif - //// Used Computation mode for the solver. - common::Computation mComputation; - }; -} // namespace exageostat + /** + * @brief Constructor for ExaGeoStatHardware. + * @param[in] aComputation The computation mode for the solver as a string. + * @param[in] aCoreNumber The number of CPU cores to use for the solver. + * @param[in] aGpuNumber The number of GPUs to use for the solver. + * @param[in] aP The P grid dimension setting. + * @param[in] aQ The Q grid dimension setting. + * + */ + explicit ExaGeoStatHardware(const std::string &aComputation, const int &aCoreNumber, const int &aGpuNumber, + const int &aP = 1, const int &aQ = 1); + + /** + * @brief A Finalize caller for Hardware. + * @return void. + * + */ + void FinalizeHardware(); + + /** + * @brief Destructor for ExaGeoStatHardware. + * + */ + ~ExaGeoStatHardware(); + + /** + * @brief Initializes hardware configuration. + * @param[in] aComputation The computation mode for the solver. + * @param[in] aCoreNumber The number of CPU cores to use for the solver. + * @param[in] aGpuNumber The number of GPUs to use for the solver. + * @param[in] aP The P grid dimension setting. + * @param[in] aQ The Q grid dimension setting. + * @return void + * + */ + static void + InitHardware(const exageostat::common::Computation &aComputation, const int &aCoreNumber, const int &aGpuNumber, + const int &aP, const int &aQ); + + /** + * @brief Get the Chameleon hardware context. + * @return Pointer to the hardware context. + * + */ + [[nodiscard]] static void *GetChameleonContext(); + + /** + * @brief Get the HiCMA hardware context. + * @return Pointer to the hardware context. + * + */ + [[nodiscard]] static void *GetHicmaContext(); + + /** + * @brief Get the hardware context. + * @param[in] aComputation Used computation to decide whether to use Hicma or Chameleon context. + * @return Pointer to the hardware context. + * + */ + [[nodiscard]] static void *GetContext(exageostat::common::Computation aComputation); + + /** + * @brief Retrieves the P dimension of the grid. + * @details This function returns the current setting of the P dimension of the grid, which is part of the grid configuration used in various computational processes. + * @return The current P dimension setting. + * + **/ + static int GetPGrid(); + + /** + * @brief Retrieves the Q dimension of the grid. + * @details This function returns the current setting of the Q dimension of the grid, which is part of the grid configuration used in various computational processes. + * @return int The current Q dimension setting. + * + **/ + static int GetQGrid(); + + /** + * @brief Sets the P dimension of the grid. + * @details This function updates the P dimension setting of the grid. This dimension is critical in configuring the grid's layout for simulations or calculations. + * @param[in] aP The new value for the P dimension. + * @return void + * + **/ + static void SetPGrid(int aP); + + /** + * @brief Sets the Q dimension of the grid. + * @details This function updates the Q dimension setting of the grid. This dimension is crucial in configuring the grid's layout for simulations or calculations. + * @param[in] aQ The new value for the Q dimension. + * @return void + * + **/ + static void SetQGrid(int aQ); + +private: + //// Used Pointer to the Chameleon hardware context. + static void *mpChameleonContext; + //// Used Pointer to the Hicma hardware context. + static void *mpHicmaContext; + //// Used P-Grid + static int mPGrid; + //// Used Q-Grid + static int mQGrid; + //// Used boolean to avoid re-init mpi + static bool mIsMPIInit; +}; #endif // EXAGEOSTATCPP_EXAGEOSTATHARDWARE_HPP \ No newline at end of file diff --git a/inst/include/helpers/BasselFunction.hpp b/inst/include/helpers/BasselFunction.hpp new file mode 100644 index 00000000..2ce49385 --- /dev/null +++ b/inst/include/helpers/BasselFunction.hpp @@ -0,0 +1,69 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file BasselFunction.hpp + * @brief This file contains the BasselFunction class which provides methods for computing derivatives of the modified Bessel function of the second kind. These functions are crucial in statistical and mathematical computations, especially in fields such as geostatistics and spatial analysis. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2023-01-24 +**/ + +#ifndef EXAGEOSTATCPP_BASSELFUNCTION_HPP +#define EXAGEOSTATCPP_BASSELFUNCTION_HPP + +#include + +namespace exageostat::helpers { + + /** + * @class BasselFunction + * @brief The BasselFunction class provides methods for computing various derivatives of the modified Bessel function of the second kind, \( K_{\nu} \). This class is templated to support both float and double data types, enabling precision-based computations as required by different applications. + * @tparam T Data Type: float or double + * + */ + template + class BasselFunction { + + public: + /** + * @brief Calculates the derivative of the modified Bessel function of the second kind (K_nu) with respect to its order, evaluated at input_value and order aOrder. + * @param[in] aOrder The order of the Bessel function. + * @param[in] aInputValue The input value at which to evaluate the derivative. + * @return The value of the derivative of K_nu with respect to its order, evaluated at input_value and order aOrder. + * + */ + static T CalculateDerivativeBesselNu(const T &aOrder, const T &aInputValue); + + /** + * @brief Calculates the second derivative of the modified Bessel function of the second kind (K_nu) with respect to its input, evaluated at input_value and order aOrder. + * @param[in] aOrder The order of the Bessel function. + * @param[in] aInputValue The input value at which to evaluate the second derivative. + * @return The value of the second derivative of K_nu with respect to its input, evaluated at input_value and order aOrder. + * + */ + static T CalculateSecondDerivativeBesselNu(const T &aOrder, const T &aInputValue); + + /** + * @brief Calculates the second derivative of the modified Bessel function of the second kind (K_nu) with respect to its input, evaluated at input_value and order aOrder. + * @param[in] aOrder The order of the Bessel function. + * @param[in] aInputValue The input value at which to evaluate the derivative. + * @return The value of the derivative of K_nu with respect to its input, evaluated at input_value and order aOrder. + * + */ + static T CalculateSecondDerivativeBesselNuInput(const T &aOrder, const T &aInputValue); + + }; + + /** + * @brief Instantiates the DiskWriter class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(BasselFunction) +} + +#endif //EXAGEOSTATCPP_BASSELFUNCTION_HPP diff --git a/inst/include/helpers/ByteHandler.hpp b/inst/include/helpers/ByteHandler.hpp new file mode 100644 index 00000000..2a7f41d1 --- /dev/null +++ b/inst/include/helpers/ByteHandler.hpp @@ -0,0 +1,48 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ByteHandler.hpp + * @brief Implementation of byte manipulation functions for ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-01-24 +**/ + +#ifndef EXAGEOSTATCPP_BYTEHANDLER_HPP +#define EXAGEOSTATCPP_BYTEHANDLER_HPP + +#include + +namespace exageostat::helpers { + + /** + * @brief Spread bits by three spaces. + * @param[in] aInputByte The input 64 bit to be spread. + * @return The byte after being spread. + * + */ + uint64_t SpreadBits(uint64_t aInputByte); + + /** + * @brief Reverse Spread bits operation. + * @param[in] aInputByte The input spread 64 bit to be compacted. + * @return The byte after being compacted. + * + */ + uint64_t ReverseSpreadBits(uint64_t aInputByte); + + /** + * @brief Compares two Unit64 values + * @param[in] aFirstValue Constant reference to the first input 64 bit value. + * @param[in] aSecondValue Constant reference to the second input 64 bit value. + * @return True if the second value is bigger than the first value, false otherwise. + * + */ + bool CompareUint64(const uint64_t &aFirstValue, const uint64_t &aSecondValue); + +} +#endif //EXAGEOSTATCPP_BYTEHANDLER_HPP diff --git a/inst/include/helpers/CommunicatorMPI.hpp b/inst/include/helpers/CommunicatorMPI.hpp index d9051cbb..1b1f1bb9 100644 --- a/inst/include/helpers/CommunicatorMPI.hpp +++ b/inst/include/helpers/CommunicatorMPI.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file CommunicatorMPI.hpp * @brief Defines the CommunicatorMPI class for MPI rank communication. - * @version 1.0.0 + * @version 1.1.0 * @author Sameh Abdulah * @date 2023-11-10 **/ @@ -27,6 +27,7 @@ namespace exageostat::helpers { /** * @brief Get a pointer to the singleton instance of the CommunicatorMPI class. * @return A pointer to the instance of the CommunicatorMPI class. + * */ static CommunicatorMPI *GetInstance(); @@ -35,7 +36,7 @@ namespace exageostat::helpers { * @return The rank of the MPI process. * */ - [[nodiscard]] bool GetRank() const; + [[nodiscard]] int GetRank() const; /** * @brief Set the hardware initialization flag. @@ -55,14 +56,19 @@ namespace exageostat::helpers { private: + /** + * @brief Prevent Class Instantiation for Communicator MPI Class. + * + */ + CommunicatorMPI() = default; + /** * @brief Pointer to the singleton instance of the CommunicatorMPI class. * */ static CommunicatorMPI *mpInstance; - /// Used boolean to check if hardware is initialized. - bool mIsHardwareInitialized = false; + bool mIsHardwareInitialized; }; } #endif //EXAGEOSTATCPP_COMMUNICATORMPI_HPP diff --git a/inst/include/helpers/DiskWriter.hpp b/inst/include/helpers/DiskWriter.hpp deleted file mode 100644 index 822e86a4..00000000 --- a/inst/include/helpers/DiskWriter.hpp +++ /dev/null @@ -1,55 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file DiskWriter.hpp - * @brief Contains the definition of the DiskWriter class for writing data to disk. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-06-08 -**/ - -#ifndef EXAGEOSTATCPP_DISKWRITER_HPP -#define EXAGEOSTATCPP_DISKWRITER_HPP - -#include -#include - -namespace exageostat::helpers { - - /** - * @class DiskWriter - * @brief A class for writing data to disk. - * @tparam T Data Type: float or double - * - */ - template - class DiskWriter { - public: - - /** - * @brief Writes a matrix of vectors to disk. - * @param[in] aMatrixPointer A Reference to the matrix data. - * @param[in] aProblemSize The size of the problem. - * @param[in] aP The number of processes. - * @param[in] aLoggerPath The path to the logger file. - * @param[in] aLocations A Reference to the Locations object. - * @return void - * - */ - void static - WriteVectorsToDisk(const T &aMatrixPointer, const int &aProblemSize, const int &aP, std::string &aLoggerPath, - exageostat::dataunits::Locations &aLocations); - }; - - /** - * @brief Instantiates the DiskWriter class for float and double types. - * @tparam T Data Type: float or double - * - */ - EXAGEOSTAT_INSTANTIATE_CLASS(DiskWriter) -} -#endif //EXAGEOSTATCPP_DISKWRITER_HPP diff --git a/inst/include/helpers/DistanceCalculationHelpers.hpp b/inst/include/helpers/DistanceCalculationHelpers.hpp index c8c5e44f..bf74c31a 100644 --- a/inst/include/helpers/DistanceCalculationHelpers.hpp +++ b/inst/include/helpers/DistanceCalculationHelpers.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DistanceCalculationHelpers.hpp * @brief Contains the definition of the DistanceCalculationHelpers class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -23,6 +23,7 @@ namespace exageostat::helpers { * @Class DistanceCalculationHelpers * @brief Class to calculate the distance between two points. * @tparam T Data Type: float or double. + * */ template @@ -37,6 +38,7 @@ namespace exageostat::helpers { * @param[in] aDistanceMetric Flag indicating the distance metric to use (1 for Manhattan distance, 2 for Euclidean distance). * @param[in] aFlagZ Flag indicating whether the points are in 2D or 3D space (0 for 2D, 1 for 3D). * @return The Euclidean distance between the two points. + * */ static T CalculateDistance(exageostat::dataunits::Locations &aLocations1, exageostat::dataunits::Locations &aLocations2, const int &aIdxLocation1, @@ -49,9 +51,19 @@ namespace exageostat::helpers { * @param[in] aLatitude2 Latitude of the second point in degrees. * @param[in] aLongitude2 Longitude of the second point in degrees. * @return The distance between the two points in kilometers. + * */ static T DistanceEarth(T &aLatitude1, T &aLongitude1, T &aLatitude2, T &aLongitude2); + /** + * @brief Converts an angle from degrees to radians. + * @details This function converts an angle from degrees to radians using the conversion factor π/180. + * @param[in] aDegree The angle in degrees. + * @return The angle converted to radians. + * + */ + static T DegreeToRadian(T aDegree); + }; /** * @brief Instantiates the PredictionHelpers class for float and double types. diff --git a/inst/include/kernels/Kernel.hpp b/inst/include/kernels/Kernel.hpp index 0ee2d1d2..3d018d5c 100644 --- a/inst/include/kernels/Kernel.hpp +++ b/inst/include/kernels/Kernel.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,7 +7,7 @@ /** * @file Kernels.hpp * @brief Header file for the Kernels class, which contains the main kernel functions. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -30,6 +30,7 @@ extern "C" { #include #include #include +#include /** * @def EARTH_RADIUS @@ -39,15 +40,6 @@ extern "C" { */ #define EARTH_RADIUS 6371.0 -/** - * @def POW_e - * @brief The value of e to the power of 1. - * @details This macro defines the value of e to the power of 1, which is used in some kernel functions. - * - */ -#define POW_e (2.71828182845904) - - namespace exageostat::kernels { struct KernelsConfigurations { @@ -77,6 +69,7 @@ namespace exageostat::kernels { /** * Default virtual destructor to be overridden by the the suitable concrete kernel destructor. + * */ virtual ~Kernel() = default; @@ -93,6 +86,7 @@ namespace exageostat::kernels { * @param[in] aLocalTheta An array of kernel parameters. * @param [in] aDistanceMetric Distance metric to be used (1 = Euclidean, 2 = Manhattan, 3 = Minkowski). * @return void + * */ virtual void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, @@ -100,55 +94,20 @@ namespace exageostat::kernels { dataunits::Locations &aLocation2, dataunits::Locations &aLocation3, T *apLocalTheta, const int &aDistanceMetric) = 0; - /** - * @brief Calculates the derivative of the modified Bessel function of the second kind (K_nu) with respect to its input, evaluated at input_value and order aOrder. - * @param[in] aOrder The order of the Bessel function. - * @param[in] aInputValue The input value at which to evaluate the derivative. - * @return The value of the derivative of K_nu with respect to its input, evaluated at input_value and order aOrder. - */ - static T CalculateDerivativeBesselInputNu(const T &aOrder, const T &aInputValue); - - /** - * @brief Calculates the derivative of the modified Bessel function of the second kind (K_nu) with respect to its order, evaluated at input_value and order aOrder. - * @param[in] aOrder The order of the Bessel function. - * @param[in] aInputValue The input value at which to evaluate the derivative. - * @return The value of the derivative of K_nu with respect to its order, evaluated at input_value and order aOrder. - * - */ - static T CalculateDerivativeBesselNu(const T &aOrder, const T &aInputValue); - - /** - * @brief Calculates the second derivative of the modified Bessel function of the second kind (K_nu) with respect to its input, evaluated at input_value and order aOrder. - * @param[in] aOrder The order of the Bessel function. - * @param[in] aInputValue The input value at which to evaluate the second derivative. - * @return The value of the second derivative of K_nu with respect to its input, evaluated at input_value and order aOrder. - * - */ - static T CalculateSecondDerivativeBesselNu(const T &aOrder, const T &aInputValue); - - /** - * @brief Calculates the second derivative of the modified Bessel function of the second kind (K_nu) with respect to its input, evaluated at input_value and order aOrder. - * @param[in] aOrder The order of the Bessel function. - * @param[in] aInputValue The input value at which to evaluate the derivative. - * @return The value of the derivative of K_nu with respect to its input, evaluated at input_value and order aOrder. - * - */ - static T CalculateSecondDerivativeBesselNuInput(const T &aOrder, const T &aInputValue); - /** * @brief Returns the value of the parameter P used by the kernel function. - * @return The value of P. + * @return The value of P (Variables Number). * */ - [[nodiscard]] int GetPValue() const; + [[nodiscard]] int GetVariablesNumber() const; /** * @brief Sets the value of the parameter P used by the kernel function. - * @param[in] aP Value to set `mP` with. + * @param[in] aTimeSlot Value to set `mP` with. * @return void * */ - void SetPValue(int aP); + void SetPValue(int aTimeSlot); /** * @brief Returns the number of the parameters used by the kernel function. @@ -160,6 +119,8 @@ namespace exageostat::kernels { protected: //// Used P. int mP = 1; + //// Used Variable number which is P multiplied by timeslot + int mVariablesNumber = 1; //// Used number of parameters. int mParametersNumber = 3; }; diff --git a/inst/include/kernels/concrete/BivariateMaternFlexible.hpp b/inst/include/kernels/concrete/BivariateMaternFlexible.hpp index c8286aea..73caa332 100644 --- a/inst/include/kernels/concrete/BivariateMaternFlexible.hpp +++ b/inst/include/kernels/concrete/BivariateMaternFlexible.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateMaternFlexible.hpp * @brief Defines the BivariateMaternFlexible class, a Bivariate Matern Flexible kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class BivariateMaternFlexible - * @brief A class representing a Bivariate Matern Flexible kernel. + * @brief A class represents a Bivariate Matern Flexible kernel. * @details This class represents a Bivariate Matern Flexible, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new BivariateMaternFlexible object. * @details Initializes a new BivariateMaternFlexible object with default values. + * */ BivariateMaternFlexible(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/BivariateMaternParsimonious.hpp b/inst/include/kernels/concrete/BivariateMaternParsimonious.hpp index ae702c31..f98b2d32 100644 --- a/inst/include/kernels/concrete/BivariateMaternParsimonious.hpp +++ b/inst/include/kernels/concrete/BivariateMaternParsimonious.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateMaternParsimonious.hpp * @brief Defines the BivariateMaternParsimonious class, a Bivariate Matern Parsimonious kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class BivariateMaternParsimonious - * @brief A class representing a Bivariate Matern Parsimonious kernel. + * @brief A class represents a Bivariate Matern Parsimonious kernel. * @details This class represents a Bivariate Matern Parsimonious, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new BivariateMaternParsimonious object. * @details Initializes a new BivariateMaternParsimonious object with default values. + * */ BivariateMaternParsimonious(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/BivariateSpacetimeMaternStationary.hpp b/inst/include/kernels/concrete/BivariateSpacetimeMaternStationary.hpp index a6b0416a..89236fae 100644 --- a/inst/include/kernels/concrete/BivariateSpacetimeMaternStationary.hpp +++ b/inst/include/kernels/concrete/BivariateSpacetimeMaternStationary.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateSpacetimeMaternStationary.hpp * @brief Defines the BivariateSpacetimeMaternStationary class, a Bivariate Spacetime Matern Stationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class BivariateSpacetimeMaternStationary - * @brief A class representing a Bivariate Spacetime Matern Stationary kernel. + * @brief A class represents a Bivariate Spacetime Matern Stationary kernel. * @details This class represents a Bivariate Spacetime Matern Stationary, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new BivariateSpacetimeMaternStationary object. * @details Initializes a new BivariateSpacetimeMaternStationary object with default values. + * */ BivariateSpacetimeMaternStationary(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/TrivariateMaternParsimonious.hpp b/inst/include/kernels/concrete/TrivariateMaternParsimonious.hpp index c81bd704..b3024753 100644 --- a/inst/include/kernels/concrete/TrivariateMaternParsimonious.hpp +++ b/inst/include/kernels/concrete/TrivariateMaternParsimonious.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TrivariateMaternParsimonious.hpp * @brief Defines the TrivariateMaternParsimonious class, a Trivariate Matern Parsimonious kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class TrivariateMaternParsimonious - * @brief A class representing a Trivariate Matern Parsimonious kernel. + * @brief A class represents a Trivariate Matern Parsimonious kernel. * @details This class represents a Trivariate Matern Parsimonious, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new TrivariateMaternParsimonious object. * @details Initializes a new TrivariateMaternParsimonious object with default values. + * */ TrivariateMaternParsimonious(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateExpNonGaussian.hpp b/inst/include/kernels/concrete/UnivariateExpNonGaussian.hpp index 3248cfed..7a51d0db 100644 --- a/inst/include/kernels/concrete/UnivariateExpNonGaussian.hpp +++ b/inst/include/kernels/concrete/UnivariateExpNonGaussian.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateExpNonGaussian.hpp * @brief Defines the UnivariateExpNonGaussian class, a Univariate Exp Non Gaussian kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateExpNonGaussian - * @brief A class representing a Univariate Exp Non Gaussian kernel. + * @brief A class represents a Univariate Exp Non Gaussian kernel. * @details This class represents a Univariate Exp Non Gaussian, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateExpNonGaussian object. * @details Initializes a new UnivariateExpNonGaussian object with default values. + * */ UnivariateExpNonGaussian(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDbeta.hpp b/inst/include/kernels/concrete/UnivariateMaternDbeta.hpp index b1a6a95f..7f51a7eb 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDbeta.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDbeta.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDbeta.hpp * @brief Defines the UnivariateMaternDbeta class, a Univariate Matern Dbeta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDbeta - * @brief A class representing a Univariate Matern Dbeta kernel. + * @brief A class represents a Univariate Matern Dbeta kernel. * @details This class represents a Univariate Matern Dbeta, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDbeta object. * @details Initializes a new UnivariateMaternDbeta object with default values. + * */ UnivariateMaternDbeta(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdbetaBeta.hpp b/inst/include/kernels/concrete/UnivariateMaternDdbetaBeta.hpp index a012eb87..33cc1dc6 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdbetaBeta.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdbetaBeta.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdbetaBeta.hpp * @brief Defines the UnivariateMaternDdbetaBeta class, a Univariate Matern Ddbeta Beta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdbetaBeta - * @brief A class representing a Univariate Matern Ddbeta Beta kernel. + * @brief A class represents a Univariate Matern Ddbeta Beta kernel. * @details This class represents a Univariate Matern Ddbeta Beta, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdbetaBeta object. * @details Initializes a new UnivariateMaternDdbetaBeta object with default values. + * */ UnivariateMaternDdbetaBeta(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdbetaNu.hpp b/inst/include/kernels/concrete/UnivariateMaternDdbetaNu.hpp index 689e37ee..06fa2bc0 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdbetaNu.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdbetaNu.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdbetaNu.hpp * @brief Defines the UnivariateMaternDdbetaNu class, a Univariate Matern Ddbeta Nu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdbetaNu - * @brief A class representing a Univariate Matern Ddbeta Nu kernel. + * @brief A class represents a Univariate Matern Ddbeta Nu kernel. * @details This class represents a Univariate Matern Ddbeta Nu, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdbetaNu object. * @details Initializes a new UnivariateMaternDdbetaNu object with default values. + * */ UnivariateMaternDdbetaNu(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdnuNu.hpp b/inst/include/kernels/concrete/UnivariateMaternDdnuNu.hpp index 5623debd..6d2376a3 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdnuNu.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdnuNu.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdnuNu.hpp * @brief Defines the UnivariateMaternDdnuNu class, a Univariate Matern Ddnu Nu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdnuNu - * @brief A class representing a Univariate Matern Ddnu Nu kernel. + * @brief A class represents a Univariate Matern Ddnu Nu kernel. * @details This class represents a Univariate Matern Ddnu Nu , which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdnuNu object. * @details Initializes a new UnivariateMaternDdnuNu object with default values. + * */ UnivariateMaternDdnuNu(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquare.hpp b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquare.hpp index 162bee37..9b596972 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquare.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquare.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquare.hpp * @brief Defines the UnivariateMaternDdsigmaSquare class, a univariate stationary Matern kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -28,7 +28,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdsigmaSquare - * @brief A class representing a Univariate Matern Ddsigma Square kernel. + * @brief A class represents a Univariate Matern Ddsigma Square kernel. * @details This class represents a Univariate Matern Ddsigma Square, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -41,6 +41,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdsigmaSquare object. * @details Initializes a new UnivariateMaternDdsigmaSquare object with default values. + * */ UnivariateMaternDdsigmaSquare(); @@ -53,6 +54,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.hpp b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.hpp index 57f622fc..46c71588 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquareBeta.hpp * @brief Defines the UnivariateMaternDdsigmaSquareBeta class, a Univariate Matern Ddsigma Square Beta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdsigmaSquareBeta - * @brief A class representing a Univariate Matern Ddsigma Square Beta kernel. + * @brief A class represents a Univariate Matern Ddsigma Square Beta kernel. * @details This class represents a Univariate Matern Ddsigma Square Beta, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdsigmaSquareBeta object. * @details Initializes a new UnivariateMaternDdsigmaSquareBeta object with default values. + * */ UnivariateMaternDdsigmaSquareBeta(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareNu.hpp b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareNu.hpp index ae33506a..5092e4ae 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareNu.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDdsigmaSquareNu.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquareNu.hpp * @brief Defines the UnivariateMaternDdsigmaSquareNu class, a Univariate Matern Ddsigma Square Nu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDdsigmaSquareNu - * @brief A class representing a Univariate Matern Ddsigma Square Nu kernel. + * @brief A class represents a Univariate Matern Ddsigma Square Nu kernel. * @details This class represents a Univariate Matern Ddsigma Square Nu, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDdsigmaSquareNu object. * @details Initializes a new UnivariateMaternDdsigmaSquareNu object with default values. + * */ UnivariateMaternDdsigmaSquareNu(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDnu.hpp b/inst/include/kernels/concrete/UnivariateMaternDnu.hpp index f9eefb5a..6c830bc7 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDnu.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDnu.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDnu.hpp * @brief Defines the UnivariateMaternDnu class, a Univariate Matern Dnu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDnu - * @brief A class representing a Univariate Matern Dnu kernel. + * @brief A class represents a Univariate Matern Dnu kernel. * @details This class represents a Univariate Matern Dnu, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDnu object. * @details Initializes a new UnivariateMaternDnu object with default values. + * */ UnivariateMaternDnu(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternDsigmaSquare.hpp b/inst/include/kernels/concrete/UnivariateMaternDsigmaSquare.hpp index 1da69311..d1a3350b 100644 --- a/inst/include/kernels/concrete/UnivariateMaternDsigmaSquare.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternDsigmaSquare.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDsigmaSquare.hpp * @brief Defines the UnivariateMaternDsigmaSquare class, a Univariate Matern Dsigma Square kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternDsigmaSquare - * @brief A class representing a Univariate Matern Dsigma Square kernel. + * @brief A class represents a Univariate Matern Dsigma Square kernel. * @details This class represents a Univariate Matern Dsigma Square, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternDsigmaSquare object. * @details Initializes a new UnivariateMaternDsigmaSquare object with default values. + * */ UnivariateMaternDsigmaSquare(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternNonGaussian.hpp b/inst/include/kernels/concrete/UnivariateMaternNonGaussian.hpp index 1ee3a74e..203c4c6e 100644 --- a/inst/include/kernels/concrete/UnivariateMaternNonGaussian.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternNonGaussian.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternNonGaussian.hpp * @brief Defines the UnivariateMaternNonGaussian class, a Univariate Matern Non Gaussian kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternNonGaussian - * @brief A class representing a Univariate Matern Non Gaussian kernel. + * @brief A class represents a Univariate Matern Non Gaussian kernel. * @details This class represents a Univariate Matern Non Gaussian, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternNonGaussian object. * @details Initializes a new UnivariateMaternNonGaussian object with default values. + * */ UnivariateMaternNonGaussian(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternNonStat.hpp b/inst/include/kernels/concrete/UnivariateMaternNonStat.hpp deleted file mode 100644 index 4509c13f..00000000 --- a/inst/include/kernels/concrete/UnivariateMaternNonStat.hpp +++ /dev/null @@ -1,141 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file UnivariateMaternNonStat.hpp - * @brief Defines the UnivariateMaternNonStat class, a Univariate Matern Non Stat kernel. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @author Suhas Shankar - * @author Mary Lai Salvana - * @date 2023-04-14 -**/ - -#ifndef EXAGEOSTATCPP_UNIVARIATEMATERNNONSTAT_HPP -#define EXAGEOSTATCPP_UNIVARIATEMATERNNONSTAT_HPP - -#include - -namespace exageostat::kernels { - - /** - * @class UnivariateMaternNonStat - * @brief A class representing a Univariate Matern Non Stat kernel. - * @details This class represents a Univariate Matern Non Stat,which is a subclass of the Kernel class. - * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. - * - */ - template - class UnivariateMaternNonStat : public Kernel { - - public: - - /** - * @brief Constructs a new UnivariateMaternNonStat object. - * @details Initializes a new UnivariateMaternNonStat object with default values. - */ - UnivariateMaternNonStat(); - - /** - * @brief Virtual destructor to allow calls to the correct concrete destructor. - * - */ - ~UnivariateMaternNonStat() override = default; - - /** - * @brief Generates a covariance matrix using a set of locations and kernel parameters. - * @copydoc Kernel::GenerateCovarianceMatrix() - */ - void - GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, - const int &aColumnOffset, dataunits::Locations &aLocation1, - dataunits::Locations &aLocation2, dataunits::Locations &aLocation3, - T *apLocalTheta, const int &aDistanceMetric) override; - - /** - * @brief Creates a new UnivariateMaternNonStat object. - * @details This method creates a new UnivariateMaternNonStat object and returns a pointer to it. - * @return A pointer to the new UnivariateMaternNonStat object. - * - */ - static Kernel *Create(); - - /** - * Function for smoothness parameter - * @param[in] aX x co-ordinate - * @param[in] aY y co-ordinate - * @param[in] aG parameter for function - * @param[in] aH parameter for function - * @param[in] aTi parameter for function - * @return The function ge^(h(x+y)) + ti - * - */ - static double Neu(double aX, double aY, double aG, double aH, double aTi); - - /** - * Function for partial sill - * @param[in] aX x co-ordinate - * @param[in] aY y co-ordinate - * @param[in] aD parameter for function - * @param[in] aE parameter for function - * @param[in] aF parameter for function - * @return The function de^(e(x+y)) + f - * - */ - static double Sigma(double aX, double aY, double aD, double aE, double aF); - - /** - * Function for spatial range - * @param[in] aX x co-ordinate - * @param[in] aY y co-ordinate - * @param[in] aA parameter for function - * @param[in] aB parameter for function - * @return The function ae^(sin bx + sin by) - * - */ - static double Lambda(double aX, double aY, double aA, double aB); - - /** - * Returns the Mahalanobis distance between two points to account for anisotropy - * @param[in] aX1 x co-ordinate of first point - * @param[in] aY1 y co-ordinate of first point - * @param[in] aX2 x co-ordinate of second point - * @param[in] aY2 y co-ordinate of second point - * @param[in] aA11 First element of the positive definite matrix that defines the Mahalanobis Distance - * @param[in] aA12 Second element of the positive definite matrix that defines the Mahalanobis Distance - * @param[in] aA21 Third element of the positive definite matrix that defines the Mahalanobis Distance - * @param[in] aA22 Fourth element of the positive definite matrix that defines the Mahalanobis Distance - * @return The Mahalanobis Distance - * - */ - static double - CalculateMahalanobisDistanceSquared(double aX1, double aY1, double aX2, double aY2, double aA11, double aA12, - double aA21, double aA22); - - /** - * Utility function that evaluates the matern. Similar to (https://www.rdocumentation.org/packages/PrevMap/versions/1.5.3/topics/matern.kernel) in R - * @param[in] aRange Spatial Range parameter (Also known as rho) - * @param[in] aSmoothness Smoothness parameter (Also known as neu) - * @param[in] aDistance Distance between the two locations - * @return Matern function evaluation - * - */ - static double MaternUtil(double aRange, double aSmoothness, double aDistance); - - private: - //// Used plugin name for static registration - static bool plugin_name; - }; - - /** - * @brief Instantiates the Data Generator class for float and double types. - * @tparam T Data Type: float or double - * - */ - EXAGEOSTAT_INSTANTIATE_CLASS(UnivariateMaternNonStat) -}//namespace exageostat - -#endif //EXAGEOSTATCPP_UNIVARIATEMATERNNONSTAT_HPP diff --git a/inst/include/kernels/concrete/UnivariateMaternNonStationary.hpp b/inst/include/kernels/concrete/UnivariateMaternNonStationary.hpp deleted file mode 100644 index e2422f59..00000000 --- a/inst/include/kernels/concrete/UnivariateMaternNonStationary.hpp +++ /dev/null @@ -1,72 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file UnivariateMaternNonStationary.hpp - * @brief Defines the UnivariateMaternNonStationary class, a Univariate Matern Non Stationary kernel. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @author Suhas Shankar - * @author Mary Lai Salvana - * @date 2023-04-13 -**/ - -#ifndef EXAGEOSTATCPP_UNIVARIATEMATERNNONSTATIONARY_HPP -#define EXAGEOSTATCPP_UNIVARIATEMATERNNONSTATIONARY_HPP - -#include - -namespace exageostat::kernels { - - /** - * @class UnivariateMaternNonStationary - * @brief A class representing a Univariate Matern Non Stationary kernel. - * @details This class represents a Univariate Matern Non Stationary, which is a subclass of the Kernel class. - * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. - * - */ - template - class UnivariateMaternNonStationary : public Kernel { - - public: - - /** - * @brief Constructs a new UnivariateMaternNonStationary object. - * @details Initializes a new UnivariateMaternNonStationary object with default values. - */ - UnivariateMaternNonStationary(); - - /** - * @brief Virtual destructor to allow calls to the correct concrete destructor. - * - */ - ~UnivariateMaternNonStationary() override = default; - - /** - * @brief Generates a covariance matrix using a set of locations and kernel parameters. - * @copydoc Kernel::GenerateCovarianceMatrix() - */ - void - GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, - const int &aColumnOffset, dataunits::Locations &aLocation1, - dataunits::Locations &aLocation2, dataunits::Locations &aLocation3, - T *apLocalTheta, const int &aDistanceMetric) override; - - /** - * @brief Creates a new UnivariateMaternNonStationary object. - * @details This method creates a new UnivariateMaternNonStationary object and returns a pointer to it. - * @return A pointer to the new UnivariateMaternNonStationary object. - * - */ - static Kernel *Create(); - - private: - //// Used plugin name for static registration - static bool plugin_name; - }; -}//namespace exageostat - -#endif //EXAGEOSTATCPP_UNIVARIATEMATERNNONSTATIONARY_HPP diff --git a/inst/include/kernels/concrete/UnivariateMaternNuggetsStationary.hpp b/inst/include/kernels/concrete/UnivariateMaternNuggetsStationary.hpp index 86e6cae9..3503ac44 100644 --- a/inst/include/kernels/concrete/UnivariateMaternNuggetsStationary.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternNuggetsStationary.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternNuggetsStationary.hpp * @brief Defines the UnivariateMaternNuggetsStationary class, a Univariate Matern Nuggets Stationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternNuggetsStationary - * @brief A class representing a Univariate Matern Nuggets Stationary kernel. + * @brief A class represents a Univariate Matern Nuggets Stationary kernel. * @details This class represents a Univariate Matern Nuggets Stationary, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternNuggetsStationary object. * @details Initializes a new UnivariateMaternNuggetsStationary object with default values. + * */ UnivariateMaternNuggetsStationary(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariateMaternStationary.hpp b/inst/include/kernels/concrete/UnivariateMaternStationary.hpp index ceb8cc7c..25db2fee 100644 --- a/inst/include/kernels/concrete/UnivariateMaternStationary.hpp +++ b/inst/include/kernels/concrete/UnivariateMaternStationary.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternStationary.hpp * @brief Defines the UnivariateMaternStationary class, a univariate stationary Matern kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -28,7 +28,7 @@ namespace exageostat::kernels { /** * @class UnivariateMaternStationary - * @brief A class representing a Univariate Matern Stationary kernel. + * @brief A class represents a Univariate Matern Stationary kernel. * @details This class represents a Univariate Matern Stationary, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -41,6 +41,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateMaternStationary object. * @details Initializes a new UnivariateMaternStationary object with default values. + * */ UnivariateMaternStationary(); @@ -53,6 +54,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/kernels/concrete/UnivariatePowExpStationary.hpp b/inst/include/kernels/concrete/UnivariatePowExpStationary.hpp new file mode 100644 index 00000000..e4a76c4b --- /dev/null +++ b/inst/include/kernels/concrete/UnivariatePowExpStationary.hpp @@ -0,0 +1,87 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file UnivariatePowExpStationary.hpp + * @brief Defines the UnivariatePowExpStationary class, a univariate stationary PowExp kernel. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @author Suhas Shankar + * @author Mary Lai Salvana + * @date 2024-11-22 + * + * This file provides the declaration of the UnivariatePowExpStationary class, which is a subclass of the Kernel class + * and represents a univariate stationary PowExp kernel. It provides a method for generating a covariance matrix + * using a set of input locations and kernel parameters. + * +**/ + +#ifndef EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP +#define EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP + +#include + +namespace exageostat::kernels { + + /** + * @class UnivariatePowExpStationary + * @brief A class represents a Univariate PowExp Stationary kernel. + * @details This class represents a Univariate PowExp Stationary, which is a subclass of the Kernel class. + * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. + * + */ + template + class UnivariatePowExpStationary : public Kernel { + + public: + + /** + * @brief Constructs a new UnivariatePowExpStationary object. + * @details Initializes a new UnivariatePowExpStationary object with default values. + * + */ + UnivariatePowExpStationary(); + + /** + * @brief Virtual destructor to allow calls to the correct concrete destructor. + * + */ + ~UnivariatePowExpStationary() override = default; + + /** + * @brief Generates a covariance matrix using a set of locations and kernel parameters. + * @copydoc Kernel::GenerateCovarianceMatrix() + * + */ + void + GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, + const int &aColumnOffset, dataunits::Locations &aLocation1, + dataunits::Locations &aLocation2, dataunits::Locations &aLocation3, + T *apLocalTheta, const int &aDistanceMetric) override; + + /** + * @brief Creates a new UnivariatePowExpStationary object. + * @details This method creates a new UnivariatePowExpStationary object and returns a pointer to it. + * @return A pointer to the new UnivariatePowExpStationary object. + * + */ + static Kernel *Create(); + + private: + //// Used plugin name for static registration + static bool plugin_name; + }; + + /** + * @brief Instantiates the Data Generator class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(UnivariatePowExpStationary) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_UNIVARIATEMATERNSTATIONARY_HPP diff --git a/inst/include/kernels/concrete/UnivariateSpacetimeMaternStationary.hpp b/inst/include/kernels/concrete/UnivariateSpacetimeMaternStationary.hpp index 35b52842..25ef5393 100644 --- a/inst/include/kernels/concrete/UnivariateSpacetimeMaternStationary.hpp +++ b/inst/include/kernels/concrete/UnivariateSpacetimeMaternStationary.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateSpacetimeMaternStationary.hpp * @brief Defines the UnivariateSpacetimeMaternStationary class, a Univariate Spacetime Matern Stationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -23,7 +23,7 @@ namespace exageostat::kernels { /** * @class UnivariateSpacetimeMaternStationary - * @brief A class representing a Univariate Spacetime Matern Stationary kernel. + * @brief A class represents a Univariate Spacetime Matern Stationary kernel. * @details This class represents a Univariate Spacetime Matern Stationary, which is a subclass of the Kernel class. * It provides a method for generating a covariance matrix using a set of input locations and kernel parameters. * @@ -36,6 +36,7 @@ namespace exageostat::kernels { /** * @brief Constructs a new UnivariateSpacetimeMaternStationary object. * @details Initializes a new UnivariateSpacetimeMaternStationary object with default values. + * */ UnivariateSpacetimeMaternStationary(); @@ -48,6 +49,7 @@ namespace exageostat::kernels { /** * @brief Generates a covariance matrix using a set of locations and kernel parameters. * @copydoc Kernel::GenerateCovarianceMatrix() + * */ void GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, const int &aRowOffset, diff --git a/inst/include/linear-algebra-solvers/LinearAlgebraFactory.hpp b/inst/include/linear-algebra-solvers/LinearAlgebraFactory.hpp index 68bf6729..fc789af8 100644 --- a/inst/include/linear-algebra-solvers/LinearAlgebraFactory.hpp +++ b/inst/include/linear-algebra-solvers/LinearAlgebraFactory.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file LinearAlgebraFactory.hpp * @brief Header file for the LinearAlgebraFactory class, which creates linear algebra solvers based on the input computation type. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-03-20 **/ diff --git a/inst/include/linear-algebra-solvers/LinearAlgebraMethods.hpp b/inst/include/linear-algebra-solvers/LinearAlgebraMethods.hpp index 9790b352..251d6319 100644 --- a/inst/include/linear-algebra-solvers/LinearAlgebraMethods.hpp +++ b/inst/include/linear-algebra-solvers/LinearAlgebraMethods.hpp @@ -1,15 +1,15 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file LinearAlgebraMethods.hpp * @brief Header file for the LinearAlgebraMethods class, which defines the interface for linear algebra solvers. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-03-20 + * @date 2024-02-25 * @details This header file defines the abstract class LinearAlgebraMethods, which provides an interface for linear algebra solvers. * The purpose of this interface is to allow different concrete linear algebra solvers to be interchangeable, * so that they can be used interchangeably by other parts of the software system that rely on linear algebra. @@ -25,10 +25,10 @@ extern "C" { #include } -#include -#include -#include +#include +#include #include +#include #include namespace exageostat::linearAlgebra { @@ -54,22 +54,26 @@ namespace exageostat::linearAlgebra { * @details This method initializes the descriptors necessary for the linear algebra solver. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in,out] aDescriptorData Descriptor Data object to be populated with descriptors and data. + * @param[in] aP the P value of the kernel multiplied by time slot. * @param[in] apMeasurementsMatrix Pointer to the measurement matrix. * @return void * */ void InitiateDescriptors(configurations::Configurations &aConfigurations, - dataunits::DescriptorData &aDescriptorData, T *apMeasurementsMatrix = nullptr); + dataunits::DescriptorData &aDescriptorData, + const int &aP, T *apMeasurementsMatrix = nullptr); /** * @brief Initializes the descriptors necessary for the Fisher prediction function. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in,out] aDescriptorData Descriptor Data object to be populated with descriptors and data. + * @return void + * */ void InitiateFisherDescriptors(configurations::Configurations &aConfigurations, dataunits::DescriptorData &aDescriptorData); - /** + /** * @brief Initializes the descriptors necessary for the Prediction. * @details This method initializes the descriptors necessary for the linear algebra solver. * @param[in] aConfigurations Configurations object containing relevant settings. @@ -78,62 +82,32 @@ namespace exageostat::linearAlgebra { * */ void InitiatePredictionDescriptors(configurations::Configurations &aConfigurations, - dataunits::ExaGeoStatData &aData); + std::unique_ptr> &aData); /** * @brief Initializes the descriptors necessary for the Prediction Auxiliary function MLE-MLOE-MMOM. * @details This method initializes the descriptors necessary for the linear algebra solver. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in,out] aData DescriptorData object to be populated with descriptors and data. + * @param[in] aP the P value of the kernel multiplied by time slot. * @return void * */ void InitiateMLOEMMOMDescriptors(configurations::Configurations &aConfigurations, - dataunits::ExaGeoStatData &aData); + std::unique_ptr> &aData, const int &aP); /** * @brief Generates synthetic data. * @param[in] aConfigurations The configurations object containing relevant settings. - * @param[in] aHardware ExaGeoStatHardware object representing the hardware. * @param[in,out] aData ExaGeoStatData object to be populated with synthetic data. * @param[in] aKernel Reference to the kernel object to use. - * @return None. + * @return void. * */ void GenerateSyntheticData(configurations::Configurations &aConfigurations, - const hardware::ExaGeoStatHardware &aHardware, dataunits::ExaGeoStatData &aData, + std::unique_ptr> &aData, const kernels::Kernel &aKernel); - /** - * @brief Computes the covariance matrix. - * @param[in] aDescriptorData pointer to the DescriptorData object holding descriptors and data. - * @param[out] apDescriptor Pointer to the descriptor for the covariance matrix. - * @param[in] aTriangularPart Specifies whether the upper or lower triangular part of the covariance matrix is stored. - * @param[in] apLocation1 Pointer to the first set of locations. - * @param[in] apLocation2 Pointer to the second set of locations. - * @param[in] apLocation3 Pointer to the third set of locations. - * @param[in] apLocalTheta Pointer to the local theta values. - * @param[in] aDistanceMetric Specifies the distance metric to use. - * @param[in] apKernel Pointer to the kernel object to use. - * @return void - * - */ - void CovarianceMatrixCodelet(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, - const int &aTriangularPart, dataunits::Locations *apLocation1, - dataunits::Locations *apLocation2, dataunits::Locations *apLocation3, - T *apLocalTheta, const int &aDistanceMetric, const kernels::Kernel *apKernel); - - /** - * @brief Copies the descriptor data to a double vector. - * @param[in] aDescriptorData pointer to the DescriptorData object holding descriptors and data. - * @param[in] apDescriptor Pointer to the descriptor data. - * @param[in,out] apDoubleVector Pointer to the double vector to copy the descriptor data to. - * @return void - * - */ - void - CopyDescriptorZ(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, T *apDoubleVector); - /** * @brief Generates the observations vector. * @param[in] aConfigurations Configurations object containing relevant settings. @@ -147,14 +121,14 @@ namespace exageostat::linearAlgebra { * */ void - GenerateObservationsVector(configurations::Configurations &aConfigurations, dataunits::ExaGeoStatData &aData, + GenerateObservationsVector(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, dataunits::Locations *apLocation1, dataunits::Locations *apLocation2, dataunits::Locations *apLocation3, const int &aDistanceMetric, const kernels::Kernel &aKernel); /** * @brief Calculates the log likelihood value of a given value theta. - * @param[in] aHardware ExaGeoStatHardware object representing the hardware. * @param[in,out] aData DescriptorData object to be populated with descriptors and data. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in] apTheta Optimization parameter used by NLOPT. @@ -163,18 +137,10 @@ namespace exageostat::linearAlgebra { * @return log likelihood value * */ - virtual T ExaGeoStatMLETile(const hardware::ExaGeoStatHardware &aHardware, dataunits::ExaGeoStatData &aData, + virtual T ExaGeoStatMLETile(std::unique_ptr> &aData, configurations::Configurations &aConfigurations, const double *apTheta, T *apMeasurementsMatrix, const kernels::Kernel &aKernel) = 0; - /** - * @brief Converts a Gaussian descriptor to a non-tiled descriptor. - * @param[in] aDescriptorData DescriptorData struct with the Gaussian descriptor. - * @param[in] apDesc Pointer to the non-tiled descriptor. - * @param[in] apTheta Theta vector. - * @return void - */ - void ExaGeoStatGaussianToNonTileAsync(dataunits::DescriptorData &aDescriptorData, void *apDesc, T *apTheta); /** * @brief Copies a matrix in the tile layout from source to destination @@ -186,33 +152,6 @@ namespace exageostat::linearAlgebra { */ virtual void ExaGeoStatLapackCopyTile(const common::UpperLower &aUpperLower, void *apA, void *apB) = 0; - /** - * @brief Initialize the runtime option structure for either HiCMA or CHAMELEON. - * @param[in, out] apOptions The options structure that needs to be initialized. - * @param[in] apContext The runtime context in which to initialize the runtime support. - * @param[in] apSequence The sequence structure to associate in the options. - * @param[in] apRequest The request structure to associate in the options. - * @return void - */ - virtual void - ExaGeoStatOptionsInit(void *apOptions, void *apContext, void *apSequence, void *apRequest) = 0; - - /** - * @brief Submit the release of the workspaces associated to the options structure. - * @param[in,out] apOptions The options structure for which to workspaces will be released - * @return void - */ - virtual void ExaGeoStatOptionsFree(void *apOptions) = 0; - - /** - * @brief Finalize the runtime option structure for either HiCMA or CHAMELEON. - * @param[in,out] apOptions The options structure that needs to be finalized. - * @param[in] apContext The runtime context in which to finalize the runtime support. - * @return void - * - */ - virtual void ExaGeoStatOptionsFinalize(void *apOptions, void *apContext) = 0; - /** * @brief Wait for the completion of a sequence. * @param[in] apSequence apSequence A pointer to either CHAMELEON or HiCMA sequence. @@ -240,6 +179,7 @@ namespace exageostat::linearAlgebra { * @param[in] aMaxRank Maximum rank parameter. * @param[in] aAcc Accuracy parameter. * @return void + * */ virtual void ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, void *apCD, void *apCrk, @@ -258,35 +198,12 @@ namespace exageostat::linearAlgebra { * @param[in, out] apZ The matrix B of dimension, on exit is overwritten by the solution matrix X. * @param[in] aMaxRank Maximum rank parameter. * @return void + * */ virtual void ExaGeoStatTrsmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, const common::Trans &aTrans, const common::Diag &aDiag, const T &aAlpha, void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) = 0; - /** - * @brief Calculate determinant for triangular matrix. - * @param[in] apDescA Pointer to the descriptor of the matrix 'descA'. - * @param[in] apSequence Pointer to a sequence structure for managing asynchronous execution. - * @param[in] apRequest Pointer to a request structure for tracking the operation's status. - * @param[out] apDescNum Pointer to the descriptor of the matrix to store the sum of elements. - * @param[out] apDescTrace Pointer to the descriptor of the matrix to store the trace. - * @return void - */ - void - ExaGeoStatMLETraceTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescNum, - void *apDescTrace); - - /** - * @brief Calculate determinant for triangular matrix. - * @param[in] apDescA Exageostat descriptor. - * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. - * @param[in] apRequest Identifies this function call (for exception handling purposes). - * @param[in] apDescDet determinant value - * @return Returns 0 for success, error code otherwise. - * - */ - virtual int - ExaGeoStatMeasureDetTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescDet) = 0; /** * @brief Solve a positive definite linear system of equations AX = B using tiled algorithms. @@ -294,23 +211,36 @@ namespace exageostat::linearAlgebra { * @param [in] apA coefficient matrix of the system of linear equations. This matrix is expected to be positive definite. * @param [in] apB Pointer to coefficient matrix of the system of linear equations. This matrix is expected to be positive definite. * @return void + * */ void ExaGeoStatPosvTile(const common::UpperLower &aUpperLower, void *apA, void *apB); /** - * @brief Calculate mean square prediction error (MSPE) scalar value of the prediction. - * @param[in] apDescZPredict Observed measurements. - * @param[in] apDescZMiss Missing measurements. - * @param[out] apDescError Mean Square Prediction Error (MSPE). - * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. - * @param[out] apRequest Identifies this function call (for exception handling purposes). - * @return Returns 0 for success, error code otherwise. + * @brief Predict missing values base on a set of given values and covariance matrix/ + * @param[in] aData Reference to Data containing different MLE inputs. + * @param[in] apTheta theta Vector with three parameter (Variance, Range, Smoothness) that is used to to generate the Covariance Matrix. + * @param[in] aZMissNumber number of missing values (unknown observations). + * @param[in] aZObsNumber number of observed values (known observations). + * @param[in] apZObs observed values vector (known observations). + * @param[in] apZActual actual missing values vector (in the case of testing MSPE). + * @param[in] apZMiss missing values vector (unknown observations). + * @param[in] aConfigurations Configurations object containing relevant settings. + * @param[in] aMissLocations Reference to Locations object containing missed locations. + * @param[in] aObsLocations Reference to Locations object containing observed locations. + * @param[in] aKernel Reference to the kernel object to use. + * @return the prediction Mean Square Error (MSPE). + * */ - int ExaGeoStatMLEMSPETileAsync(void *apDescZPredict, void *apDescZMiss, void *apDescError, void *apSequence, - void *apRequest); + T *ExaGeoStatMLEPredictTile(std::unique_ptr> &aData, T *apTheta, + const int &aZMissNumber, + const int &aZObsNumber, T *apZObs, T *apZActual, T *apZMiss, + configurations::Configurations &aConfiguration, + exageostat::dataunits::Locations &aMissLocations, + exageostat::dataunits::Locations &aObsLocations, + const kernels::Kernel &aKernel); /** - * Predict missing values base on a set of given values and covariance matrix/ + * @brief Predict missing values base on a set of given values and Non-Gaussian covariance matrix/ * @param[in] aData Reference to Data containing different MLE inputs. * @param[in] apTheta theta Vector with three parameter (Variance, Range, Smoothness) that is used to to generate the Covariance Matrix. * @param[in] aZMissNumber number of missing values (unknown observations). @@ -318,19 +248,20 @@ namespace exageostat::linearAlgebra { * @param[in] apZObs observed values vector (known observations). * @param[in] apZActual actual missing values vector (in the case of testing MSPE). * @param[in] apZMiss missing values vector (unknown observations). - * @param[in] aHardware ExaGeoStatHardware object representing the hardware. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in] aMissLocations Reference to Locations object containing missed locations. * @param[in] aObsLocations Reference to Locations object containing observed locations. * @param[in] aKernel Reference to the kernel object to use. * @return the prediction Mean Square Error (MSPE). + * */ - T * ExaGeoStatMLEPredictTile(exageostat::dataunits::ExaGeoStatData &aData, T *apTheta, const int &aZMissNumber, - const int &aZObsNumber, T *apZObs, T *apZActual, T *apZMiss, - const hardware::ExaGeoStatHardware &aHardware, - configurations::Configurations &aConfiguration, - exageostat::dataunits::Locations &aMissLocations, - exageostat::dataunits::Locations &aObsLocations, const kernels::Kernel &aKernel); + T *ExaGeoStatMLENonGaussianPredictTile(std::unique_ptr> &aData, T *apTheta, + const int &aZMissNumber, + const int &aZObsNumber, T *apZObs, T *apZActual, T *apZMiss, + configurations::Configurations &aConfiguration, + exageostat::dataunits::Locations &aMissLocations, + exageostat::dataunits::Locations &aObsLocations, + const kernels::Kernel &aKernel); /** * @brief Copy Lapack matrix to Descriptor Matrix. @@ -339,9 +270,9 @@ namespace exageostat::linearAlgebra { * @param[out] apDescA Matrix Descriptor. * @param[in] aUpperLower Specifies Specifies whether the upper or lower triangular part of the covariance matrix is stored. * @return void + * */ - virtual void - ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const common::UpperLower &aUpperLower) = 0; + void ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const common::UpperLower &aUpperLower); /** * @brief Copy Descriptor Matrix to Lapack matrix. @@ -350,9 +281,26 @@ namespace exageostat::linearAlgebra { * @param[in] apDescA Matrix Descriptor * @param[in] aUpperLower Specifies whether the upper or lower triangular part of the covariance matrix is stored. * @return void + * */ void ExaGeoStatDesc2Lap(T *apA, const int &aLDA, void *apDescA, const common::UpperLower &aUpperLower); +#ifdef USE_HICMA + + /** + * @brief Copy Descriptor Matrix to another Descriptor matrix. + * @param[out] apSourceDesc Descriptor matrix to be copied + * @param[out] apDestinationDesc Descriptor matrix to be copied to. + * @param[in] aSize Size of matrix to be copied. + * @param[in] aDirection Specifies the type of Descriptors to be copied. + * @return void + * + */ + void CopyDescriptors(void *apSourceDesc, void *apDestinationDesc, const int &aSize, + const common::CopyDirection &aDirection); + +#endif + /** * @brief Sets the values of all or part of a two-dimensional Tile. * @param[in] aUpperLower Specifies Specifies whether the upper or lower triangular part of the covariance matrix is stored. @@ -360,6 +308,7 @@ namespace exageostat::linearAlgebra { * @param[in] aBeta All the diagonal array elements are set to aBeta. * @param[out] apDescriptor Pointer to matrix descriptor to be set with aAlpha and aBeta. * @return void + * */ void ExaGeoStatLaSetTile(const common::UpperLower &aUpperLower, T aAlpha, T aBeta, void *apDescriptor); @@ -368,9 +317,13 @@ namespace exageostat::linearAlgebra { * @param[out] apZ Pointer to an array to copy Z matrix into. * @param[in] aSize Size of the matrix. * @param[in] aDescData Descriptor data containing required Z matrix Descriptor. + * @param[in] aP the P value of the kernel multiplied by time slot. + * @return void + * */ - void ExaGeoStatGetZObs(exageostat::configurations::Configurations &aConfigurations, T *apZ, const int &aSize, - exageostat::dataunits::DescriptorData &aDescData, T *apMeasurementsMatrix); + void ExaGeoStatGetZObs(configurations::Configurations &aConfigurations, T *apZ, const int &aSize, + exageostat::dataunits::DescriptorData &aDescData, T *apMeasurementsMatrix, + const int &aP); /** * @brief Predict missing values based on a set of given values and covariance matrix. @@ -378,50 +331,32 @@ namespace exageostat::linearAlgebra { * maximum likelihood on the empirical orthogonal functions (MLOE), and method of moments (MMOM). * @param[in] aConfigurations Configurations for the prediction. * @param[in, out] aData Data for prediction (input and output). - * @param[in] aHardware Hardware specifications for the prediction. * @param[in] apTruthTheta Pointer to the true theta values. * @param[in] apEstimatedTheta Pointer to the estimated theta values. * @param[in] aMissLocations Locations of missing values. * @param[in] aObsLocations Locations of observed values. * @param[in] aKernel Reference to the kernel object to use. * @return void + * */ - void ExaGeoStatMLETileMLOEMMOM(exageostat::configurations::Configurations &aConfigurations, - exageostat::dataunits::ExaGeoStatData &aData, - const exageostat::hardware::ExaGeoStatHardware &aHardware, T *apTruthTheta, - T *apEstimatedTheta, dataunits::Locations &aMissLocations, + void ExaGeoStatMLETileMLOEMMOM(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, + T *apTruthTheta, T *apEstimatedTheta, dataunits::Locations &aMissLocations, dataunits::Locations &aObsLocations, const kernels::Kernel &aKernel); /** * @brief Maximum Likelihood Evaluation (MLE) Fisher method. * @param[in] aConfigurations Configurations object containing relevant settings. * @param[in,out] aData Descriptor Data object to be populated with descriptors and data. - * @param[in] aHardware ExaGeoStatHardware object representing the hardware. * @param[in] apTheta Pointer containing three parameter (Variance, Range, Smoothness) that is used to to generate the Covariance Matrix. * @param[in] aKernel Reference to the kernel object to use. * @return Fisher Matrix + * */ T * - ExaGeoStatFisherTile(configurations::Configurations &aConfigurations, dataunits::ExaGeoStatData &aData, - const hardware::ExaGeoStatHardware &aHardware, T *apTheta, - const kernels::Kernel &aKernel); - - /** - * @brief Perform an asynchronous computation of MLE, MLOE, and MMOM for a tile. - * @details his function performs the computation of Maximum Likelihood Estimation (MLE), - * Maximum Likelihood on the Empirical Orthogonal Functions (MLOE), and - * Method of Moments (MMOM) for a tile asynchronously. - * @param[in] apDescExpr2 Descriptor for expression 2. - * @param[in] apDescExpr3 Descriptor for expression 3. - * @param[in] apDescExpr4 Descriptor for expression 4. - * @param[in] apDescMLOE Descriptor for MLOE. - * @param[in] apDescMMOM Descriptor for MMOM. - * @param[in] apSequence Sequence for the computation. - * @param[in] apRequest Request for the computation. - * @return Result of the asynchronous operation. - */ - int ExaGeoStatMLETileAsyncMLOEMMOM(void *apDescExpr2, void *apDescExpr3, void *apDescExpr4, void *apDescMLOE, - void *apDescMMOM, void *apSequence, void *apRequest); + ExaGeoStatFisherTile(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, + T *apTheta, const kernels::Kernel &aKernel); /** * @brief Perform a matrix addition with scaling. @@ -432,6 +367,7 @@ namespace exageostat::linearAlgebra { * @param[in] aBeta Scaling factor for matrix B. * @param[in] apDescB Descriptor for matrix B. * @return void + * */ void ExaGeoStatGeaddTile(const common::Trans &aTrans, const T &aAlpha, void *apDescA, const T &aBeta, void *apDescB); @@ -446,396 +382,23 @@ namespace exageostat::linearAlgebra { * @param[in] alpha Scaling factor for the multiplication. * @param[in] apDescA Descriptor for matrix A. * @param[in] apDescB Descriptor for matrix B. + * */ void ExaGeoStatTrmmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, const common::Trans &aTrans, const common::Diag &aDiag, const T &alpha, void *apDescA, void *apDescB); /** - * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. - * @param[in] apA The descriptor to which belongs the piece of data - * @param[in] aAm The row coordinate of the piece of data in the matrix - * @param[in] aAn he column coordinate of the piece of data in the matrix - * @return The runtime handler address of the piece of data. - */ - virtual void *ExaGeoStatDataGetAddr(void *apA, int aAm, int aAn) = 0; - - /** - * @brief Sets the context. - * @param[in] apContext The context. + * @brief Recovers theta and log-likelihood from a file. + * @param[in] apPath A pointer to the path of the file from which to recover the data. + * @param[in] aIterationCount The iteration count to look for in the file. + * @param[in,out] apTheta A pointer to the array where the theta values will be stored. + * @param[in,out] apLogLik A pointer to the variable where the log-likelihood value will be stored. + * @param[in] aNumParams The number of parameters (elements) in the theta array. + * @return bool `true` if the specified iteration count is found and successfully parsed, `false` otherwise. * */ - void SetContext(void *apContext) { - this->mpContext = apContext; - } - - //// TODO: Create a Factory for Runtime system. This is a solution fix for now - struct starpu_codelet cl_gaussian_to_non = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_gaussian_to_non_starpu}, - .nbuffers = 1, - .modes = {STARPU_RW}, - .name = "gaussian_to_non" - }; - - struct starpu_codelet cl_dzcpy = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dzcpy_Starpu}, - .nbuffers = 1, - .modes = {STARPU_W}, - .name = "dzcpy" - }; - - struct starpu_codelet cl_dmdet = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dmdet_starpu}, - .nbuffers = 2, - .modes = {STARPU_R, STARPU_RW}, - .name = "dmdet" - }; - - struct starpu_codelet cl_stride_vec = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_stride_vector_starpu}, - .nbuffers = 3, - .modes = {STARPU_R, STARPU_W, STARPU_W}, - .name = "stride_vec" - }; - - struct starpu_codelet cl_tri_stride_vec = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_tri_stride_vector_starpu}, - .nbuffers = 4, - .modes = {STARPU_R, STARPU_W, STARPU_W, STARPU_W}, - .name = "tri_stride_vec" - }; - - struct starpu_codelet cl_dmse = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dmse_starpu}, - .nbuffers = 3, - .modes = {STARPU_RW, STARPU_R, STARPU_R}, - .name = "dmse" - }; - - struct starpu_codelet cl_dmloe_mmom = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dmloe_mmom_starpu}, - .nbuffers = 5, - .modes = {STARPU_R, STARPU_R, STARPU_R, STARPU_RW, STARPU_RW}, - .name = "dmloe_mmom" - }; - - struct starpu_codelet cl_dcmg = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dcmg_starpu}, - .nbuffers = 1, - .modes = {STARPU_W}, - .name = "dcmg" - }; - - struct starpu_codelet cl_dtrace = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_dtrace_starpu}, - .nbuffers = 3, - .modes = {STARPU_R, STARPU_RW, STARPU_W}, - .name = "dtrace" - }; - - struct starpu_codelet cl_ddotp = - { - .where = STARPU_CPU, - .cpu_funcs = {CORE_ddotp_starpu}, - .nbuffers = 2, - .modes = {STARPU_RW,STARPU_R}, - .name = "ddotp" - }; - - - - static void CORE_dcmg_starpu(void *apBuffers[], void *apCodeletArguments) { - int m, n, m0, n0; - exageostat::dataunits::Locations *location1; - exageostat::dataunits::Locations *location2; - exageostat::dataunits::Locations *location3; - T *theta; - T *A; - int distance_metric; - kernels::Kernel *kernel; - - A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - starpu_codelet_unpack_args(apCodeletArguments, &m, &n, &m0, &n0, &location1, &location2, &location3, &theta, - &distance_metric, &kernel); - kernel->GenerateCovarianceMatrix(A, m, n, m0, n0, *location1, *location2, *location3, theta, - distance_metric); - } - - static void CORE_gaussian_to_non_starpu(void *apBuffers[], void *apCodeletArguments) { - int m, m0; - T *z; - T *theta; - theta = new T[6]; - z = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - - starpu_codelet_unpack_args(apCodeletArguments, &m, &m0, &theta[0], &theta[1], &theta[2], &theta[3], - &theta[4], &theta[5]); - //core function to convert Z tile from Gaussian to non-Gaussian. - core_gaussian_to_non(z, theta, m); - delete[] theta; - } - - static void core_gaussian_to_non(T *Z, T *apLocalTheta, int aSize) { - - double xi = apLocalTheta[2]; - double omega = apLocalTheta[3]; - double g = apLocalTheta[4]; - double h = apLocalTheta[5]; - - int i; - if (h < 0) { - LOGGER("The kurtosis parameter cannot be negative") - return; - } - if (g == 0) { - for (i = 0; i < aSize; i++) - Z[i] = xi + omega * Z[i] * (exp(0.5 * h * pow(Z[i], 2))); - } else { - for (i = 0; i < aSize; i++) - Z[i] = xi + omega * (exp(g * Z[i]) - 1) * (exp(0.5 * h * pow(Z[i], 2))) / g; - } - } - - static void CORE_dzcpy_Starpu(void *apBuffers[], void *apCodeletArguments) { - int m; - T *A; - int m0; - T *r; - - A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - starpu_codelet_unpack_args(apCodeletArguments, &m, &m0, &r); - memcpy(A, &r[m0], m * sizeof(T)); - } - - static void CORE_dmdet_starpu(void *apBuffers[], void *apCodeletArguments) { - int m; - int n; - T *A; - int m0; - int n0; - T det = 0; - T *determinant = &det; - - *determinant = 0; - A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - determinant = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); - starpu_codelet_unpack_args(apCodeletArguments, &m, &n, &m0, &n0); - T local_det = Core_dmdet(A, m); - *determinant += local_det; - } - - static T Core_dmdet(T *apA, int aSize) { - - int i; - T res = 0.0; - for (i = 0; i < aSize; i++) { - if (apA[i + i * aSize] > 0) - res += log(apA[i + i * aSize]); - } - return res; - } - - static void CORE_stride_vector_starpu(void *apBuffers[], void *apCodeletArguments) { - int m; - int temp; - T *A; - T *B; - T *C; - int m0; - int i; - int j = 0; - - A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - B = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); - C = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); - starpu_codelet_unpack_args(apCodeletArguments, &temp, &m0, &m); - - for (i = 0; i < temp - 1; i += 2) { - B[j] = A[i]; - C[j] = A[i + 1]; - j++; - } - } - - static void CORE_tri_stride_vector_starpu(void *apBuffers[], void *apCodeletArguments) { - int m; - int temp; - double *A; - double *B; - double *C; - double *D; - int m0; - int i; - int j; - - A = (double *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - B = (double *) STARPU_MATRIX_GET_PTR(apBuffers[1]); - C = (double *) STARPU_MATRIX_GET_PTR(apBuffers[2]); - D = (double *) STARPU_MATRIX_GET_PTR(apBuffers[3]); - - starpu_codelet_unpack_args(apCodeletArguments, &temp, &m0, &m); - - //accept only temp divided by three (should be optimized) - j = 0; - for (i = 0; i < temp - 1; i += 3) { - B[j] = A[i]; - C[j] = A[i + 1]; - D[j] = A[i + 2]; - j++; - } - } - - static void CORE_dmse_starpu(void *apBuffers[], void *apCodeletArguments) { - int m, m0, i; - double *pZPredict; - double *pZMiss; - double *pError; - double local_error = 0.0; - - pError = (double *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - pZPredict = (double *) STARPU_MATRIX_GET_PTR(apBuffers[1]); - pZMiss = (double *) STARPU_MATRIX_GET_PTR(apBuffers[2]); - - starpu_codelet_unpack_args(apCodeletArguments, &m, &m0); - for (i = 0; i < m; i++) { - local_error += pow((pZPredict[i] - pZMiss[i]), 2); - } - *pError += local_error; - } - - static void CORE_dmloe_mmom_starpu(void *apBuffers[], void *apCodeletArguments) { - int m; - int n; - int i; - double *expr2; - double *expr3; - double *expr4; - double *mloe; - double *mmom; - int m0; - int n0; - - expr2 = (double *) STARPU_MATRIX_GET_PTR(apBuffers[0]); - expr3 = (double *) STARPU_MATRIX_GET_PTR(apBuffers[1]); - expr4 = (double *) STARPU_MATRIX_GET_PTR(apBuffers[2]); - mloe = (double *) STARPU_MATRIX_GET_PTR(apBuffers[3]); - mmom = (double *) STARPU_MATRIX_GET_PTR(apBuffers[4]); - starpu_codelet_unpack_args(apCodeletArguments, &m, &n, &m0, &n0); - double expr2_ = 0, expr3_ = 0, expr4_ = 0; - for (i = 0; i < m * n; i += 2) { - expr2_ += expr2[i]; - expr3_ += expr3[i]; - expr4_ += expr4[i]; - } - - if (expr3_ == 0.0) { - *mloe -= 1.0; - } else { - *mloe += (expr2_ / expr3_) - 1.0; - } - - if (expr2_ == 0.0) { - *mmom -= 1.0; - } else { - *mmom += (expr4_ / expr2_) - 1.0; - } - } - - static void CORE_dtrace_starpu(void *buffers[], void *cl_arg) { - int m; - double *A; - double s = 0; - double *sum = &s; - double *trace; - - *sum = 0; - A = (double *) STARPU_MATRIX_GET_PTR(buffers[0]); - sum = (double *) STARPU_MATRIX_GET_PTR(buffers[1]); - trace = (double *) STARPU_MATRIX_GET_PTR(buffers[2]); - starpu_codelet_unpack_args(cl_arg, &m); - - double local_s = core_dtrace(A, m, trace); - *sum+= local_s; - } - - static double core_dtrace (double *A, int m, double* trace) { - int i; - double res = 0.0; - for (i = 0; i < m; i++) - { - res += A[i + i * m]; - trace[i] = A[i + i * m]; - } - return res; - } - - static void CORE_ddotp_starpu(void *buffers[], void *cl_arg){ - int m, m0; - double * A; - double * dotproduct; - - dotproduct = (double *)STARPU_MATRIX_GET_PTR(buffers[0]); - A = (double *)STARPU_MATRIX_GET_PTR(buffers[1]); - starpu_codelet_unpack_args(cl_arg, &m, &m0); - double local_dot=cblas_ddot(m, A, 1, A, 1); - *dotproduct += local_dot; - } - - bool recover(char *apPath, int aIterationCount, T *apTheta, T *apLogLik, int aNumParams) { - - FILE *fp; - char *line = nullptr; - size_t len = 0; - int count; - int i; - char *pch; - fp = fopen(apPath, "r"); - if (fp == nullptr) { - LOGGER("cannot open observations file\n") - exit(EXIT_FAILURE); - } - while (getline(&line, &len, fp) != -1) { - pch = strtok(line, " "); - count = (int) strtol(pch, nullptr, 10); - if (count == aIterationCount) { - pch = strtok(nullptr, " "); - for (i = 0; i < aNumParams; i++) { - apTheta[i] = strtol(pch, nullptr, 10); - pch = strtok(nullptr, " "); - } - *apLogLik = strtol(pch, nullptr, 10); - fclose(fp); - free(line); - return true; - } - } - - fclose(fp); - free(line); - return false; - } - - protected: - /// Used Context. - void *mpContext = nullptr; + bool Recover(char *apPath, const int &aIterationCount, T *apTheta, T *apLogLik, const int &aNumParams); }; /** diff --git a/inst/include/linear-algebra-solvers/concrete/ChameleonHeaders.hpp b/inst/include/linear-algebra-solvers/concrete/ChameleonHeaders.hpp index d851e510..ece6a56a 100644 --- a/inst/include/linear-algebra-solvers/concrete/ChameleonHeaders.hpp +++ b/inst/include/linear-algebra-solvers/concrete/ChameleonHeaders.hpp @@ -1,7 +1,7 @@ /** * @file ChameleonHeaders.hpp * @brief This file contains the necessary includes for using the Chameleon library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-08-24 **/ diff --git a/inst/include/linear-algebra-solvers/concrete/HicmaHeaders.hpp b/inst/include/linear-algebra-solvers/concrete/HicmaHeaders.hpp index 159c9c87..2093821b 100644 --- a/inst/include/linear-algebra-solvers/concrete/HicmaHeaders.hpp +++ b/inst/include/linear-algebra-solvers/concrete/HicmaHeaders.hpp @@ -1,7 +1,7 @@ /** * @file HicmaHeaders.hpp * @brief This file contains the necessary includes for using the Chameleon library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-08-24 **/ @@ -9,7 +9,7 @@ #ifndef EXAGEOSTATCPP_HICMAHEADERS_HPP #define EXAGEOSTATCPP_HICMAHEADERS_HPP -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA extern "C" { #include #include diff --git a/inst/include/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.hpp b/inst/include/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.hpp index 99ebf86e..8653bfc5 100644 --- a/inst/include/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.hpp +++ b/inst/include/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,7 +7,7 @@ * @file ChameleonImplementation.hpp * @brief This file contains the declaration of ChameleonImplementation class. * @details ChameleonImplementation is a concrete implementation of the LinearAlgebraMethods class for the common functionality implementation shared between dense and diagonal-super tile matrices. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-20 @@ -32,47 +32,32 @@ namespace exageostat::linearAlgebra { /** * @brief Calculates the log likelihood value of a given value theta. * @copydoc LinearAlgebraMethods::ExaGeoStatMLETile() + * */ - T ExaGeoStatMLETile(const hardware::ExaGeoStatHardware &aHardware, dataunits::ExaGeoStatData &aData, + T ExaGeoStatMLETile(std::unique_ptr> &aData, configurations::Configurations &aConfigurations, const double *theta, T *apMeasurementsMatrix, const kernels::Kernel &aKernel) override; - /** - * @brief Copy Lapack matrix to Descriptor Matrix - * @copydoc LinearAlgebraMethods::ExaGeoStatLap2Desc() - */ - void ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const common::UpperLower &aUpperLower) override; - /** * @brief Copies a matrix in the tile layout from source to destination * @copydoc LinearAlgebraMethods::ExaGeoStatLapackCopyTile() + * */ void ExaGeoStatLapackCopyTile(const common::UpperLower &aUpperLower, void *apA, void *apB) override; - /** - * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. - * @copydoc LinearAlgebraMethods::ExaGeoStatDataGetAddr() - */ - void *ExaGeoStatDataGetAddr(void *apA, int aAm, int aAn) override; - /** * @brief Solves one of the matrix equations op( A )*X = alpha*B, or X*op( A ) = alpha*B. * @copydoc LinearAlgebraMethods::ExaGeoStatTrsmTile() + * */ void ExaGeoStatTrsmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, const common::Trans &aTrans, const common::Diag &aDiag, const T &aAlpha, void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) override; - /** - * @brief Calculate determinant for triangular matrix. - * @copydoc LinearAlgebraMethods::ExaGeoStatMeasureDetTileAsync() - */ - int - ExaGeoStatMeasureDetTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescDet) override; - /** * @brief Wait for the completion of a sequence. * @copydoc LinearAlgebraMethods::ExaGeoStatSequenceWait() + * */ void ExaGeoStatSequenceWait(void *apSequence) override; @@ -80,69 +65,10 @@ namespace exageostat::linearAlgebra { /** * @brief Create CHAMELEON Sequence. * @copydoc LinearAlgebraMethods::ExaGeoStatCreateSequence() + * */ void ExaGeoStatCreateSequence(void *apSequence) override; - - /** - * @brief Initialize the runtime option structure for CHAMELEON - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsInit() - */ - void - ExaGeoStatOptionsInit(void *apOptions, void *apContext, void *apSequence, void *apRequest) override; - - /** - * @brief Submit the release of the workspaces associated to the options structure. - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsFree() - */ - void - ExaGeoStatOptionsFree(void *apOptions) override; - - /** - * @brief Finalize the runtime option structure for CHAMELEON. - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsFinalize() - */ - void - ExaGeoStatOptionsFinalize(void *apOptions, void *apContext) override; - - /** - * @brief copy Chameleon descriptor to vector float*. - * @param[in] apDescA Exageostat descriptor A. - * @param[in] apDescB Exageostat descriptor B. - * @param[in] apDescC Exageostat descriptor C. - * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. - * @param[in] apRequest Identifies this function call (for exception handling purposes). - * @return Returns 0 for success, error code otherwise. - * - */ - int - ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apSequence, void *apRequest); - - /** - * @brief Copy Chameleon descriptor to vector float*. - * @param[in] apDescA Exageostat descriptor A. - * @param[in] apDescB Exageostat descriptor B. - * @param[in] apDescC Exageostat descriptor C. - * @param[in] apDescD Exageostat descriptor D. - * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. - * @param[in] apRequest Identifies this function call (for exception handling purposes). - * @return Returns 0 for success, error code otherwise. - */ - int - ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apDescD, void *apSequence, - void *apRequest); - - /** - * @brief Computes dot product of A.A. - * @param[in] apDescA A Descriptor - * @param[out] apDescProduct Stores the result of A.A. - * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. - * @param[in] apRequest Identifies this function call (for exception handling purposes). - * @return Returns 0 for success, error code otherwise. - */ - int - ExaGeoStatDoubleDotProduct(void *apDescA, void *apDescProduct, void *apSequence, void *apRequest); - }; EXAGEOSTAT_INSTANTIATE_CLASS(ChameleonImplementation) diff --git a/inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.hpp b/inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.hpp similarity index 75% rename from inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.hpp rename to inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.hpp index 8b3edb18..81a3c05e 100644 --- a/inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.hpp +++ b/inst/include/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,14 +7,14 @@ * @file ChameleonImplementationDense.hpp * @brief This file contains the declaration of ChameleonImplementationDense class. * @details ChameleonImplementationDense is a concrete implementation of ChameleonImplementation class for dense matrices. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-20 **/ -#ifndef EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDENSE_HPP -#define EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDENSE_HPP +#ifndef EXAGEOSTATCPP_CHAMELEONDENSE_HPP +#define EXAGEOSTATCPP_CHAMELEONDENSE_HPP #include @@ -26,22 +26,25 @@ namespace exageostat::linearAlgebra::dense { * */ template - class ChameleonImplementationDense : public ChameleonImplementation { + class ChameleonDense : public ChameleonImplementation { public: /** * @brief Default constructor. + * */ - explicit ChameleonImplementationDense() = default; + explicit ChameleonDense() = default; /** * @brief Virtual destructor to allow calls to the correct concrete destructor. + * */ - ~ChameleonImplementationDense() override = default; + ~ChameleonDense() override = default; /** * @brief Computes the Cholesky factorization of a symmetric positive definite or Symmetric positive definite matrix. * @copydoc LinearAlgebraMethods::ExaGeoStatPotrfTile() + * */ void ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, void *apCD, void *apCrk, @@ -54,8 +57,8 @@ namespace exageostat::linearAlgebra::dense { * @tparam T Data Type: float or double * */ - EXAGEOSTAT_INSTANTIATE_CLASS(ChameleonImplementationDense) + EXAGEOSTAT_INSTANTIATE_CLASS(ChameleonDense) }//namespace exageostat -#endif //EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDENSE_HPP \ No newline at end of file +#endif //EXAGEOSTATCPP_CHAMELEONDENSE_HPP \ No newline at end of file diff --git a/inst/include/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.hpp b/inst/include/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.hpp similarity index 86% rename from inst/include/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.hpp rename to inst/include/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.hpp index a7991f3b..f8e96954 100644 --- a/inst/include/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.hpp +++ b/inst/include/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,14 +7,14 @@ * @file ChameleonImplementationDST.hpp * @brief This file contains the declaration of ChameleonImplementationDST class. * @details ChameleonImplementationDST is a concrete implementation of LinearAlgebraMethods class for diagonal super tile matrices. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-26 **/ -#ifndef EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDST_HPP -#define EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDST_HPP +#ifndef EXAGEOSTATCPP_CHAMELEONDST_HPP +#define EXAGEOSTATCPP_CHAMELEONDST_HPP #include @@ -26,19 +26,19 @@ namespace exageostat::linearAlgebra::diagonalSuperTile { * */ template - class ChameleonImplementationDST : public ChameleonImplementation { + class ChameleonDST : public ChameleonImplementation { public: /** * @brief Default constructor. */ - explicit ChameleonImplementationDST() = default; + explicit ChameleonDST() = default; /** * @brief Virtual destructor to allow calls to the correct concrete destructor. */ - ~ChameleonImplementationDST() override = default; + ~ChameleonDST() override = default; /** * @brief Computes the Cholesky factorization of a symmetric positive definite or Symmetric positive definite matrix. @@ -79,8 +79,8 @@ namespace exageostat::linearAlgebra::diagonalSuperTile { * @tparam T Data Type: float or double * */ - EXAGEOSTAT_INSTANTIATE_CLASS(ChameleonImplementationDST) + EXAGEOSTAT_INSTANTIATE_CLASS(ChameleonDST) }//namespace exageostat -#endif //EXAGEOSTATCPP_CHAMELEONIMPLEMENTATIONDST_HPP \ No newline at end of file +#endif //EXAGEOSTATCPP_CHAMELEONDST_HPP \ No newline at end of file diff --git a/inst/include/linear-algebra-solvers/concrete/hicma/tile-low-rank/HicmaImplementation.hpp b/inst/include/linear-algebra-solvers/concrete/hicma/tlr/HicmaImplementation.hpp similarity index 65% rename from inst/include/linear-algebra-solvers/concrete/hicma/tile-low-rank/HicmaImplementation.hpp rename to inst/include/linear-algebra-solvers/concrete/hicma/tlr/HicmaImplementation.hpp index 4520a807..4c488a3d 100644 --- a/inst/include/linear-algebra-solvers/concrete/hicma/tile-low-rank/HicmaImplementation.hpp +++ b/inst/include/linear-algebra-solvers/concrete/hicma/tlr/HicmaImplementation.hpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,7 +7,7 @@ * @file HicmaImplementation.hpp * @brief This file contains the declaration of HicmaImplementation class. * @details HicmaImplementation is a concrete implementation of LinearAlgebraMethods class for tile low-rank matrices. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-26 @@ -43,15 +43,16 @@ namespace exageostat::linearAlgebra::tileLowRank { * @brief Set the modeling descriptors for HiCMA implementation. * @param[in,out] aData Reference to the ExaGeoStatData object. * @param[in] aConfigurations Reference to the Configurations object. + * @param[in] aP the P value of the kernel multiplied by time slot. */ - void - SetModelingDescriptors(dataunits::ExaGeoStatData &aData, configurations::Configurations &aConfigurations); + void SetModelingDescriptors(std::unique_ptr> &aData, + configurations::Configurations &aConfigurations, const int &aP); /** * @brief Calculates the log likelihood value of a given value theta. * @copydoc LinearAlgebraMethods::ExaGeoStatMLETile() */ - T ExaGeoStatMLETile(const hardware::ExaGeoStatHardware &apHardware, dataunits::ExaGeoStatData &aData, + T ExaGeoStatMLETile(std::unique_ptr> &aData, configurations::Configurations &aConfigurations, const double *theta, T *apMeasurementsMatrix, const kernels::Kernel &aKernel) override; @@ -61,25 +62,6 @@ namespace exageostat::linearAlgebra::tileLowRank { */ void ExaGeoStatLapackCopyTile(const common::UpperLower &aUpperLower, void *apA, void *apB) override; - /** - * @brief Initialize the runtime option structure for HiCMA - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsInit() - */ - void - ExaGeoStatOptionsInit(void *apOptions, void *apContext, void *apSequence, void *apRequest) override; - - /** - * @brief Submit the release of the workspaces associated to the options structure. - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsFree() - */ - void ExaGeoStatOptionsFree(void *apOptions) override; - - /** - * @brief Finalize the runtime option structure for HiCMA. - * @copydoc LinearAlgebraMethods::ExaGeoStatOptionsFinalize() - */ - void ExaGeoStatOptionsFinalize(void *apOptions, void *apContext) override; - /** * @brief Wait for the completion of a sequence. * @copydoc LinearAlgebraMethods::ExaGeoStatSequenceWait() @@ -109,23 +91,6 @@ namespace exageostat::linearAlgebra::tileLowRank { const common::Trans &aTrans, const common::Diag &aDiag, const T &aAlpha, void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) override; - /** - * @brief Calculate determinant for triangular matrix. - * @copydoc LinearAlgebraMethods::ExaGeoStatMeasureDetTileAsync() - */ - int ExaGeoStatMeasureDetTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescDet) override; - - /** - * @brief Copy Lapack matrix to Descriptor Matrix - * @copydoc LinearAlgebraMethods::ExaGeoStatLap2Desc() - */ - void ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const common::UpperLower &aUpperLower) override; - - /** - * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. - * @copydoc LinearAlgebraMethods::ExaGeoStatDataGetAddr() - */ - void *ExaGeoStatDataGetAddr(void *apA, int aAm, int aAn) override; }; /** diff --git a/inst/include/prediction/Prediction.hpp b/inst/include/prediction/Prediction.hpp index 87b33f16..280a2396 100644 --- a/inst/include/prediction/Prediction.hpp +++ b/inst/include/prediction/Prediction.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Prediction.hpp * @brief Contains the definition of the Prediction class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -23,35 +23,28 @@ namespace exageostat::prediction { * @Class Prediction * @brief Class to handle different Prediction Module calls. * @tparam T Data Type: float or double. + * */ - template class Prediction { public: - /** - * @brief Default constructor for Prediction class. - */ - Prediction() = default; - - /** - * @brief Default destructor for Prediction class. - */ - ~Prediction() = default; - /** * @brief Takes care of calling the MSPE function, and the appropriate auxiliary function. - * @param[in] aHardware Reference to Hardware configuration for the ExaGeoStat solver. * @param[in, out] aData Reference to an ExaGeoStatData object containing needed descriptors, and locations. * @param[in] aConfigurations Reference to Configurations object containing user input data. * @param[in] apMeasurementsMatrix Pointer to the user input measurements matrix. * @param[in] aKernel Reference to the kernel object to use. - * @return + * @param[in] apTrainLocations (Optional) Pointer to Locations represents training locations. these are used in training phase. + * @param[in] apTestLocations (Optional) Pointer to Locations represents test locations. These are used in prediction phase. + * @return void + * */ - void PredictMissingData(const exageostat::hardware::ExaGeoStatHardware &aHardware, - exageostat::dataunits::ExaGeoStatData &aData, - exageostat::configurations::Configurations &aConfigurations, T *apMeasurementsMatrix, - const kernels::Kernel &aKernel); + static void + PredictMissingData(std::unique_ptr> &aData, configurations::Configurations &aConfigurations, + T *apMeasurementsMatrix, const kernels::Kernel &aKernel, + dataunits::Locations *apTrainLocations = nullptr, + dataunits::Locations *apTestLocations = nullptr); /** * @brief Initializes needed pointers for prediction. @@ -63,13 +56,20 @@ namespace exageostat::prediction { * @param[out] aMissLocation Location object to be filled with missed locations. * @param[out] aObsLocation Location object to be filled with missed locations. * @param[in] apMeasurementsMatrix Pointer to the user input measurements matrix. + * @param[in] aP the P value of the kernel multiplied by time slot. + * @param[in] apTrainLocations (Optional) Pointer to Locations represents training locations. these are used in training phase. + * @param[in] apTestLocations (Optional) Pointer to Locations represents test locations. These are used in prediction phase. * @return void + * */ - void InitializePredictionArguments(exageostat::configurations::Configurations &aConfigurations, - exageostat::dataunits::ExaGeoStatData &aData, - std::unique_ptr> &aLinearAlgebraSolver, - T *apZObs, T *apZActual, exageostat::dataunits::Locations &aMissLocation, - exageostat::dataunits::Locations &aObsLocation, T *apMeasurementsMatrix); + static void + InitializePredictionArguments(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, + std::unique_ptr> &aLinearAlgebraSolver, + T *apZObs, T *apZActual, exageostat::dataunits::Locations &aMissLocation, + exageostat::dataunits::Locations &aObsLocation, T *apMeasurementsMatrix, + const int &aP, dataunits::Locations *apTrainLocations, + dataunits::Locations *apTestLocations); }; diff --git a/inst/include/prediction/PredictionAuxiliaryFunctions.hpp b/inst/include/prediction/PredictionAuxiliaryFunctions.hpp index ad07828f..c8dc3b70 100644 --- a/inst/include/prediction/PredictionAuxiliaryFunctions.hpp +++ b/inst/include/prediction/PredictionAuxiliaryFunctions.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file PredictionAuxiliaryFunctions.hpp * @brief Contains the definition of the PredictionAuxiliaryFunctions.hpp class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -28,16 +28,6 @@ namespace exageostat::prediction { class PredictionAuxiliaryFunctions { public: - /** - * @brief Default constructor for PredictionAuxiliaryFunctions - */ - PredictionAuxiliaryFunctions() = default; - - /** - * @brief Default destructor for PredictionAuxiliaryFunctions - */ - ~PredictionAuxiliaryFunctions() = default; - /** * @brief implements the Inverse Distance Weighting (IDW) interpolation method * for predicting missing values based on available observed values. @@ -50,6 +40,7 @@ namespace exageostat::prediction { * @param[in] aObsLocation Reference to the observed locations. * @param[out] apMSPE Pointer to be filled with MSPE value. * @return T Array provides insight into the accuracy of the IDW-interpolated predictions for missing values + * */ static void PredictIDW(T *apZMiss, T *apZActual, T *apZObs, const int &aZMissNumber, const int &aZObsNumber, exageostat::dataunits::Locations &aMissLocation, diff --git a/inst/include/prediction/PredictionHelpers.hpp b/inst/include/prediction/PredictionHelpers.hpp index 7955357e..b4be1875 100644 --- a/inst/include/prediction/PredictionHelpers.hpp +++ b/inst/include/prediction/PredictionHelpers.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file PredictionHelpers.hpp * @brief Contains the definition of the PredictionHelpers.hpp class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -29,6 +29,7 @@ namespace exageostat::prediction { template class PredictionHelpers { public: + /** * @brief Pick random Z points for prediction depending on p. * @param[in] aConfigurations Configurations object containing relevant settings. @@ -38,12 +39,14 @@ namespace exageostat::prediction { * @param[in] apZ Pointer to a copy of the measurements matrix. * @param[out] aMissLocation Location object to be filled with missed locations. * @param[out] aObsLocation Location object to be filled with missed locations. + * @param[in] aP the P value of the kernel multiplied by time slot. * @return void + * */ - static void PickRandomPoints(exageostat::configurations::Configurations &aConfigurations, - exageostat::dataunits::ExaGeoStatData &aData, T *apZObs, T *apZActual, T *apZ, + static void PickRandomPoints(configurations::Configurations &aConfigurations, + std::unique_ptr> &aData, T *apZObs, T *apZActual, T *apZ, exageostat::dataunits::Locations &aMissLocation, - exageostat::dataunits::Locations &aObsLocation); + exageostat::dataunits::Locations &aObsLocation, const int &aP); /** * @brief Shuffle array. @@ -51,6 +54,7 @@ namespace exageostat::prediction { * @param[in, out] aLocations Locations to be shuffled. * @param[out] aSize Size of data. * @return void + * */ static void Shuffle(T *apArray, exageostat::dataunits::Locations &aLocations, int aSize); @@ -61,6 +65,7 @@ namespace exageostat::prediction { * @param[in, out] aLocations Locations to be shuffled. * @param[out] aSize Size of data. * @return void + * */ static void Shuffle(T *apArray1, T *apArray2, exageostat::dataunits::Locations &aLocations, int aSize); @@ -72,6 +77,7 @@ namespace exageostat::prediction { * @param[in, out] aLocations Locations to be shuffled. * @param[out] aSize Size of data. * @return void + * */ static void Shuffle(T *apArray1, T *apArray2, T *apArray3, exageostat::dataunits::Locations &aLocations, int aSize); @@ -82,6 +88,7 @@ namespace exageostat::prediction { * @param aCount[in] Number of elements in the input array. * @param aDimension[in] Dimension of the input data. * @return void + * */ static void SortArray(uint32_t *aData, int aCount); @@ -92,6 +99,7 @@ namespace exageostat::prediction { * @param[in,out] aLocations Reference to the Locations object containing X and Y coordinates (input/output). * @param[in,out] apZ Pointer to the array containing observation values (input/output). * @return 0 if the sorting is successful. + * */ static int SortInplace(int aN, exageostat::dataunits::Locations &aLocations, T *apZ); diff --git a/inst/include/results/Results.hpp b/inst/include/results/Results.hpp index b112284c..1f21c6b9 100644 --- a/inst/include/results/Results.hpp +++ b/inst/include/results/Results.hpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Results.hpp * @brief Defines the Results class for storing and accessing result data. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-09-14 **/ @@ -26,197 +26,265 @@ namespace exageostat::results { /** * @brief Get a pointer to the singleton instance of the Results class. * @return A pointer to the instance of the Results class. + * */ static Results *GetInstance(); /** * @brief Set the flag indicating whether the results are synthetic or not. * @param[in] aIsSynthetic True if the results are synthetic, false otherwise. + * */ void SetIsSynthetic(bool aIsSynthetic); /** * @brief Set the number of generated locations. * @param[in] aNumLocations The number of generated locations. + * */ void SetGeneratedLocationsNumber(int aNumLocations); /** * @brief Set the flag indicating whether the logger is active or not. * @param[in] aIsLogger True if the logger is active, false otherwise. + * */ void SetIsLogger(bool aIsLogger); /** * @brief Set the path for the logger. * @param[in] aLoggerPath The path for the logger. + * */ void SetLoggerPath(const std::string &aLoggerPath); /** * @brief Set the Total Data Generation execution time. * @param[in] aTime The execution time. + * */ void SetTotalDataGenerationExecutionTime(double aTime); /** * @brief Set the Data Generation floating-point operations (FLOPs). * @param[in] aFlops The number of FLOPs. + * */ void SetTotalDataGenerationFlops(double aFlops); /** * @brief Set the log-likelihood value. * @param[in] aLogLikValue The log-likelihood value. + * */ void SetLogLikValue(double aLogLikValue); /** * @brief Set the number of maximum likelihood estimation (MLE) iterations. * @param[in] aIterationsNumber The number of MLE iterations. + * */ void SetMLEIterations(int aIterationsNumber); /** * @brief Set the vector of maximum theta values. * @param[in] aMaximumTheta The vector of maximum theta values. + * */ void SetMaximumTheta(const std::vector &aMaximumTheta); /** * @brief Set the total modeling execution time. * @param[in] aTime The total execution time for data modeling. + * */ void SetTotalModelingExecutionTime(double aTime); /** * @brief Get the total modeling execution time. * @return The total execution time for data modeling. + * */ [[nodiscard]] double GetTotalModelingExecutionTime() const; + /** + * @brief Get the MLOE. + * @return The MLOE. + * + */ + [[nodiscard]] double GetMLOE() const; + + /** + * @brief Get the MSPEError. + * @return The MSPEError. + * + */ + [[nodiscard]] double GetMSPEError() const; + + /** + * @brief Get the IDW error. + * @return The the IDW error vector. + * + */ + [[nodiscard]] std::vector GetIDWError() const; + + /** + * @brief Get the MMOM. + * @return The MMOM. + * + */ + [[nodiscard]] double GetMMOM() const; + + /** + * @brief Get the Fisher matrix elements. + * @return the Fisher matrix. + * + */ + [[nodiscard]] std::vector GetFisherMatrix() const; + + /** + * @brief Get the Predicted Missed Z matrix elements. + * @return the Z Predicted matrix. + * + */ + [[nodiscard]] std::vector GetPredictedMissedValues() const; + /** * @brief Set the total modeling FLOPs. * @param[in] aTime The total number of FLOPs for data modeling. + * */ void SetTotalModelingFlops(double aTime); /** * @brief Get the total modeling FLOPs. * @return The total number of FLOPs for data modeling. + * */ [[nodiscard]] double GetTotalModelingFlops() const; /** * @brief Get the average modeling execution time. * @return The average execution time for data modeling. + * */ [[nodiscard]] double GetAverageModelingExecutionTime() const; /** * @brief Get the average modeling FLOPs. * @return The average number of FLOPs for data modeling. + * */ [[nodiscard]] double GetAverageModelingFlops() const; /** * @brief Set the value of ZMiss. * @param[in] aZMiss The value of ZMiss. + * */ void SetZMiss(int aZMiss); /** * @brief Set the value of MSPEError. * @param[in] aMSPEError The value of MSPEError. + * */ void SetMSPEError(double aMSPEError); /** * @brief Set the MSPE execution time. * @param[in] aTime The execution time. + * */ void SetMSPEExecutionTime(double aTime); /** * @brief Set the MSPE number of floating-point operations (FLOPs). * @param[in] aFlops The number of FLOPs. + * */ void SetMSPEFlops(double aFlops); /** * @brief Set the vector of IDW errors. * @param[in] aIDWError The vector of IDW errors. + * */ void SetIDWError(const std::vector &aIDWError); /** * @brief Set the value of MLOE. * @param[in] aMLOE The value of MLOE. + * */ void SetMLOE(double aMLOE); /** * @brief Set the value of MMOM. * @param[in] aMMOM The value of MMOM. + * */ void SetMMOM(double aMMOM); /** * @brief Set the MLOE-MMOM execution time. * @param[in] aTime The execution time. + * */ void SetExecutionTimeMLOEMMOM(double aTime); /** * @brief Set the MLOE-MMOM matrix generation time. * @param[in] aTime The execution time. + * */ void SetMatrixGenerationTimeMLOEMMOM(double aTime); /** * @brief Set the MLOE-MMOM cholesky factorization time. * @param[in] aTime The execution time. + * */ void SetFactoTimeMLOEMMOM(double aTime); /** * @brief Set the MLOE-MMOM loop time. * @param[in] aTime The execution time. + * */ void SetLoopTimeMLOEMMOM(double aTime); /** * @brief Set the MLOE-MMOM number of floating-point operations (FLOPs). * @param[in] aFlops The number of FLOPs. + * */ void SetFlopsMLOEMMOM(double aFlops); /** * @brief Set The total execution time of the fisher tile computation. * @param[in] aTime The total execution time for fisher tile computation. + * */ - void SetTotalFisherTime (double aTime); - - /** - * @brief Set the element 00 of the fisher matrix. - * @param aFisher00 Element 00 of the fisher matrix. - */ - void SetFisher00(double aFisher00); + void SetTotalFisherTime(double aTime); /** - * @brief Set the element 11 of the fisher matrix. - * @param aFisher11 element 11 of the fisher matrix. + * @brief Set the elements of the fisher matrix. + * @param aFisherMatrix Elements of the fisher matrix. + * */ - void SetFisher11(double aFisher11); + void SetFisherMatrix(std::vector aFisherMatrix); /** - * @brief Set the element 22 of the fisher matrix. - * @param aFisher22 element 22 of the fisher matrix. + * @brief Set the elements of the Z missed matrix. + * @param aPredictedValues Elements of the Predicted Z missed matrix. + * */ - void SetFisher22(double aFisher22); + void SetPredictedMissedValues(std::vector aPredictedValues); /** * @brief Print the end summary of the results. + * */ void PrintEndSummary(); @@ -273,12 +341,10 @@ namespace exageostat::results { double mTotalModelingFlops = 0; /// Used Total Fisher Time. double mTotalFisherTime = 0; - /// Fisher matrix element 00. - double mFisher00 = 0; - /// Fisher matrix element 11. - double mFisher11 = 0; - /// Fisher matrix element 22. - double mFisher22 = 0; + /// Fisher matrix + std::vector mFisherMatrix; + /// Z miss values + std::vector mPredictedMissedValues; }; }//namespace exageostat diff --git a/inst/include/runtime/RuntimeFunctions.hpp b/inst/include/runtime/RuntimeFunctions.hpp new file mode 100644 index 00000000..83cbdbe8 --- /dev/null +++ b/inst/include/runtime/RuntimeFunctions.hpp @@ -0,0 +1,230 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file RuntimeFunctions.hpp + * @brief A class for runtime static functions. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-03-10 +**/ + +#ifndef EXAGEOSTATCPP_RUNTIMEFUNCTIONS_HPP +#define EXAGEOSTATCPP_RUNTIMEFUNCTIONS_HPP + +#include +#include + +namespace exageostat::runtime { + + /** + * @class RuntimeFunctions + * @brief A class that defines runtime static functions. + * @tparam T Data Type: float or double. + * + */ + template + class RuntimeFunctions { + + public: + + /** + * @brief Computes the covariance matrix. + * @param[in] aDescriptorData pointer to the DescriptorData object holding descriptors and data. + * @param[out] apDescriptor Pointer to the descriptor for the covariance matrix. + * @param[in] aTriangularPart Specifies whether the upper or lower triangular part of the covariance matrix is stored. + * @param[in] apLocation1 Pointer to the first set of locations. + * @param[in] apLocation2 Pointer to the second set of locations. + * @param[in] apLocation3 Pointer to the third set of locations. + * @param[in] apLocalTheta Pointer to the local theta values. + * @param[in] aDistanceMetric Specifies the distance metric to use. + * @param[in] apKernel Pointer to the kernel object to use. + * @return void + * + */ + static void + CovarianceMatrix(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, const int &aTriangularPart, + dataunits::Locations *apLocation1, dataunits::Locations *apLocation2, + dataunits::Locations *apLocation3, T *apLocalTheta, const int &aDistanceMetric, + const kernels::Kernel *apKernel); + + /** + * @brief Perform an asynchronous computation of MLE, MLOE, and MMOM for a tile. + * @details his function performs the computation of Maximum Likelihood Estimation (MLE), + * Maximum Likelihood on the Empirical Orthogonal Functions (MLOE), and + * Method of Moments (MMOM) for a tile asynchronously. + * @param[in] apDescExpr2 Descriptor for expression 2. + * @param[in] apDescExpr3 Descriptor for expression 3. + * @param[in] apDescExpr4 Descriptor for expression 4. + * @param[in] apDescMLOE Descriptor for MLOE. + * @param[in] apDescMMOM Descriptor for MMOM. + * @param[in] apSequence Sequence for the computation. + * @param[in] apRequest Request for the computation. + * @return void + * + */ + static void + ExaGeoStatMLETileAsyncMLOEMMOM(void *apDescExpr2, void *apDescExpr3, void *apDescExpr4, void *apDescMLOE, + void *apDescMMOM, void *apSequence, void *apRequest); + + /** + * @brief Calculate mean square prediction error (MSPE) scalar value of the prediction. + * @param[in] apDescZPredict Observed measurements. + * @param[in] apDescZMiss Missing measurements. + * @param[out] apDescError Mean Square Prediction Error (MSPE). + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[out] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void + ExaGeoStatMLEMSPETileAsync(void *apDescZPredict, void *apDescZMiss, void *apDescError, void *apSequence, + void *apRequest); + + /** + * @brief Copies the descriptor data to a double vector. + * @param[in] aComputation computation used in configuration. + * @param[in] aDescriptorData pointer to the DescriptorData object holding descriptors and data. + * @param[in] apDescriptor Pointer to the descriptor data. + * @param[in,out] apDoubleVector Pointer to the double vector to copy the descriptor data to. + * @return void + * + */ + static void + CopyDescriptorZ(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, T *apDoubleVector); + + /** + * @brief Converts a Gaussian descriptor to a non-tiled descriptor. + * @param[in] aDescriptorData DescriptorData struct with the Gaussian descriptor. + * @param[in] apDesc Pointer to the non-tiled descriptor. + * @param[in] apTheta Theta vector. + * @return void + * + */ + static void + ExaGeoStatGaussianToNonTileAsync(dataunits::DescriptorData &aDescriptorData, void *apDesc, T *apTheta); + + /** + * @brief copy Chameleon descriptor to vector float*. + * @param[in] apDescA Exageostat descriptor A. + * @param[in] apDescB Exageostat descriptor B. + * @param[in] apDescC Exageostat descriptor C. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[in] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void + ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apSequence, void *apRequest); + + /** + * @brief Copy Chameleon descriptor to vector float*. + * @param[in] apDescA Exageostat descriptor A. + * @param[in] apDescB Exageostat descriptor B. + * @param[in] apDescC Exageostat descriptor C. + * @param[in] apDescD Exageostat descriptor D. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[in] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void + ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apDescD, void *apSequence, + void *apRequest); + + /** + * @brief Calculate determinant for triangular matrix. + * @param[in] aComputation computation used in configuration. + * @param[in] apDescA Exageostat descriptor. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[in] apRequest Identifies this function call (for exception handling purposes). + * @param[in] apDescDet determinant value + * @return void + * + */ + static void + ExaGeoStatMeasureDetTileAsync(const common::Computation &aComputation, void *apDescA, void *apSequence, + void *apRequest, void *apDescDet); + + /** + * @brief Calculate determinant for triangular matrix. + * @param[in] apDescA Pointer to the descriptor of the matrix 'descA'. + * @param[in] apSequence Pointer to a sequence structure for managing asynchronous execution. + * @param[in] apRequest Pointer to a request structure for tracking the operation's status. + * @param[out] apDescNum Pointer to the descriptor of the matrix to store the sum of elements. + * @param[out] apDescTrace Pointer to the descriptor of the matrix to store the trace. + * @return void + * + */ + static void ExaGeoStatMLETraceTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescNum, + void *apDescTrace); + + /** + * @brief Computes dot product of A.A. + * @param[in] apDescA A Descriptor + * @param[out] apDescProduct Stores the result of A.A. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[in] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void ExaGeoStatDoubleDotProduct(void *apDescA, void *apDescProduct, void *apSequence, void *apRequest); + + /** + * @brief Calculate mean square error (MSE) scalar value for Bivariate kernels. + * @param[in] apDescZPre Observed measurements descZpre. + * @param[in] apDescZMiss Missing measurements descZpre + * @param[out] apDescError1 Mean Square Error (MSE) 1. + * @param[out] apDescError2 Mean Square Error (MSE) 2. + * @param[out] apDescError Mean Square Error (MSE). + * @param[in] apSequence Sequence for the computation. + * @param[in] apRequest Request for the computation. + * @return void + * + */ + static void + ExaGeoStatMLEMSPEBivariateTileAsync(void *apDescZPre, void *apDescZMiss, void *apDescError1, void *apDescError2, + void *apDescError, void *apSequence, void *apRequest); + + /** + * @brief Calculate the log likelihood of non-Gaussian MLE. + * @param[in] aComputation computation used in configuration. + * @param[in] apDescZ pointer to the Observed Measurements descriptor. + * @param[in] apDescSum The log-likelihood Sum of descriptor Z. + * @param[in] apTheta Pointer to Model parameters. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[out] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void + ExaGeoStatNonGaussianLogLikeTileAsync(const common::Computation &aComputation, void *apDescZ, void *apDescSum, + const T *apTheta, void *apSequence, void *apRequest); + + /** + * @brief Transform the measurements vector inside the non-Gaussian MLE function. + * @param[in] aComputation computation used in configuration. + * @param[in] apDescZ pointer to the Observed Measurements descriptor. + * @param[in] apTheta Pointer to Model parameters. + * @param[in] apSequence Identifies the sequence of function calls that this call belongs to. + * @param[in] apRequest Identifies this function call (for exception handling purposes). + * @return void + * + */ + static void + ExaGeoStatNonGaussianTransformTileAsync(const common::Computation &aComputation, void *apDescZ, + const T *apTheta, void *apSequence, void *apRequest); + }; + + /** + * @brief Instantiates the Runtime Functions class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(RuntimeFunctions) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_RUNTIMEFUNCTIONS_HPP diff --git a/inst/include/runtime/starpu/StarPuCodeletsHeaders.hpp b/inst/include/runtime/starpu/StarPuCodeletsHeaders.hpp new file mode 100644 index 00000000..caacc019 --- /dev/null +++ b/inst/include/runtime/starpu/StarPuCodeletsHeaders.hpp @@ -0,0 +1,26 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuCodelets.hpp + * @brief Header file to include all codelet classes. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/inst/include/runtime/starpu/concrete/dcmg-codelet.hpp b/inst/include/runtime/starpu/concrete/dcmg-codelet.hpp new file mode 100644 index 00000000..6c45b139 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dcmg-codelet.hpp @@ -0,0 +1,87 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dcmg-codelet.hpp + * @brief A class for starpu codelet dcmg. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-19 +**/ + +#ifndef EXAGEOSTATCPP_DCMG_CODELET_HPP +#define EXAGEOSTATCPP_DCMG_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DCMG Codelet + * @brief A class for starpu codelet dcmg. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dcmg and its CPU functions. + * + */ + template + class DCMGCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DCMGCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DCMGCodelet() = default; + + /** + * @brief Inserts a task for DCMG codelet processing. + * @param[in,out] apDescriptor A pointer to the descriptor containing task information. + * @param[in] aTriangularPart An integer specifying the triangular part of the matrix (upper or lower). + * @param[in] apLocation1 A pointer to the first location object for the matrix elements. + * @param[in] apLocation2 A pointer to the second location object for the matrix elements. + * @param[in] apLocation3 A pointer to the third location object for the matrix elements. + * @param[in] apLocalTheta A pointer to the local theta value. + * @param[in] aDistanceMetric An integer specifying the distance metric to be used. + * @param[in] apKernel A pointer to the kernel function to be applied during the task execution. + * @return void + * + */ + void InsertTask(void *apDescriptor, const int &aTriangularPart, dataunits::Locations *apLocation1, + dataunits::Locations *apLocation2, dataunits::Locations *apLocation3, T *apLocalTheta, + const int &aDistanceMetric, const kernels::Kernel *apKernel); + + private: + + /** + * @brief CPU Function used by starpu_codelet struct + * @param[in] apBuffers An array of pointers to the buffers containing the matrix data. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure + * @return void + * + */ + static void cl_dcmg_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_dcmg; + }; + + /** + * @brief Instantiates the dcmg codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DCMGCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DCMG_CODELET_HPP \ No newline at end of file diff --git a/inst/include/runtime/starpu/concrete/ddotp-codelet.hpp b/inst/include/runtime/starpu/concrete/ddotp-codelet.hpp new file mode 100644 index 00000000..45061fd8 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/ddotp-codelet.hpp @@ -0,0 +1,80 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ddotp-codelet.hpp + * @brief A class for starpu codelet ddotp. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_DDOTP_CODELET_HPP +#define EXAGEOSTATCPP_DDOTP_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DDOTP Codelet + * @brief A class for starpu codelet ddotp. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_ddotp and its CPU functions. + * + */ + template + class DDOTPCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DDOTPCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DDOTPCodelet() = default; + + /** + * @brief Inserts a task for DDOTP codelet processing. + * @param[in] apDescA A pointer to the descriptor for the vector. + * @param[in,out] apDescProduct A pointer to the descriptor for the dot product. + * @return void + * + */ + void InsertTask(void *apDescA, void *apDescProduct); + + private: + + /** + * @brief Executes the DDOTP codelet function for dot product calculation. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size (m) and the offset (m0). + * @return void + * + */ + static void cl_ddotp_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_ddotp; + + }; + + /** + * @brief Instantiates the ddotp codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DDOTPCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DDOTP_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/dmdet-codelet.hpp b/inst/include/runtime/starpu/concrete/dmdet-codelet.hpp new file mode 100644 index 00000000..8fa47e0d --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dmdet-codelet.hpp @@ -0,0 +1,92 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmdet-codelet.hpp + * @brief A class for starpu codelet dmdet. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-21 +**/ + +#ifndef EXAGEOSTATCPP_DMDET_CODELET_HPP +#define EXAGEOSTATCPP_DMDET_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DMDET Codelet + * @brief A class for starpu codelet dmdet. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dmdet and its CPU functions. + * + */ + template + class DMDETCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DMDETCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DMDETCodelet() = default; + + /** + * @brief Inserts a task for DMDET codelet processing. + * @param[in] aComputation The type of computation to be performed, such as diagonal approximation or exact dense computation. + * @param[in] apDescA A pointer to the descriptor for matrix A. + * @param[in,out] apDescDet A pointer to the descriptor for the determinant. + * @param[in] aStarPuHelpers A reference to a unique pointer of StarPuHelpers, used for accessing and managing data. + * @return void + * + */ + void InsertTask(const common::Computation &aComputation, void *apDescA, void *apDescDet, + std::unique_ptr &aStarPuHelpers); + + private: + + /** + * @brief Executes the DMDET codelet function for matrix determinant calculation. + * @param[in] apBuffers An array of pointers to the buffers containing the matrix data and the determinant. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the matrix size. + * @return void + * + */ + static void cl_dmdet_function(void **apBuffers, void *apCodeletArguments); + + /** + * @brief Calculates the determinant of a matrix. + * @param[in] apDescriptor A pointer to the matrix data. + * @param[in] aSize The size of the matrix (assumed to be square). + * @return T The calculated determinant of the matrix. + * + */ + static T core_dmdet(const T *apDescriptor, const int &aSize); + + /// starpu_codelet struct + static struct starpu_codelet cl_dmdet; + + }; + + /** + * @brief Instantiates the dmdet codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DMDETCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DMDET_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/dmloe-mmom-codelet.hpp b/inst/include/runtime/starpu/concrete/dmloe-mmom-codelet.hpp new file mode 100644 index 00000000..b995843c --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dmloe-mmom-codelet.hpp @@ -0,0 +1,83 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmloe-mmom-codelet.hpp + * @brief A class for starpu codelet dmloe-mmom. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-19 +**/ + +#ifndef EXAGEOSTATCPP_DMLOE_MMOM_HPP +#define EXAGEOSTATCPP_DMLOE_MMOM_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class Dmloe-Mmom Codelet + * @brief A class for starpu codelet dmloe-mmom. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dmloe_mmom and its CPU functions. + * + */ + template + class DmloeMmomCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DmloeMmomCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DmloeMmomCodelet() = default; + + /** + * @brief Inserts a task for DmloeMmom codelet processing. + * @param[in] apDescExpr1 A pointer to the descriptor for the first expression. + * @param[in] apDescExpr2 A pointer to the descriptor for the second expression. + * @param[in] apDescExpr3 A pointer to the descriptor for the third expression. + * @param[in,out] apDescMLOE A pointer to the descriptor for the MLOE result. + * @param[in,out] apDescMMOM A pointer to the descriptor for the MMOM result. + * @return void + * + */ + void InsertTask(void *apDescExpr1, void *apDescExpr2, void *apDescExpr3, void *apDescMLOE, + void *apDescMMOM); + + private: + + /** + * @brief Executes the DmloeMmom codelet function for MLOE and MMOM calculations. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the matrix dimensions and offsets. + * @return void + * + */ + static void cl_dmloe_mmom_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_dmloe_mmom; + }; + + /** + * @brief Instantiates the dmloe-mmom codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DmloeMmomCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DMLOE_MMOM_HPP diff --git a/inst/include/runtime/starpu/concrete/dmse-bivariate-codelet.hpp b/inst/include/runtime/starpu/concrete/dmse-bivariate-codelet.hpp new file mode 100644 index 00000000..8a0043eb --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dmse-bivariate-codelet.hpp @@ -0,0 +1,83 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmse-bivariate-codelet.hpp + * @brief A class for starpu codelet dmse-bivariate. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_DMSE_BIVARIATE_CODELET_HPP +#define EXAGEOSTATCPP_DMSE_BIVARIATE_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DMSE Bivariate Codelet + * @brief A class for starpu codelet dmse-bivariate. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dmse_bivariate and its CPU functions. + * + */ + template + class DMSEBivariateCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DMSEBivariateCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DMSEBivariateCodelet() = default; + + /** + * @brief Inserts a task for DMSEBivariate codelet processing. + * @param[in] apDescZMiss A pointer to the descriptor for the observed values. + * @param[in] apDescZPre A pointer to the descriptor for the predicted values. + * @param[in,out] apDescsError A pointer to the descriptor for the total error sum. + * @param[in,out] apDescsError1 A pointer to the descriptor for the error sum for the first variable. + * @param[in,out] apDescsError2 A pointer to the descriptor for the error sum for the second variable. + * @return void + * + */ + void + InsertTask(void *apDescZMiss, void *apDescZPre, void *apDescsError, void *apDescsError1, void *apDescsError2); + + private: + + /** + * @brief Executes the DMSEBivariate codelet function for bivariate error calculation. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size and offset. + * @return void + * + */ + static void cl_dmse_bivariate_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_dmse_bivariate; + }; + + /** + * @brief Instantiates the dmse-bivariate codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DMSEBivariateCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DMSE_BIVARIATE_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/dmse-codelet.hpp b/inst/include/runtime/starpu/concrete/dmse-codelet.hpp new file mode 100644 index 00000000..4e30408c --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dmse-codelet.hpp @@ -0,0 +1,80 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmse-codelet.hpp + * @brief A class for starpu codelet dmse. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-21 +**/ + +#ifndef EXAGEOSTATCPP_DMSE_CODELET_HPP +#define EXAGEOSTATCPP_DMSE_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DMSE Codelet + * @brief A class for starpu codelet dmse. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dmse and its CPU functions. + * + */ + template + class DMSECodelet { + + public: + + /** + * @brief Constructor for DMSE codelet + * + */ + DMSECodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DMSECodelet() = default; + + /** + * @brief Inserts a task for DMSE codelet processing. + * @param[in,out] apDescError A pointer to the descriptor for the error sum. + * @param[in] apDescZPredict A pointer to the descriptor for the predicted values. + * @param[in] apDescZMiss A pointer to the descriptor for the observed values. + * @return void + * + */ + void InsertTask(void *apDescError, void *apDescZPredict, void *apDescZMiss); + + private: + + /** + * @brief Executes the DMSE codelet function for error calculation. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size and offset. + * @retur void + * + */ + static void cl_dmse_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_dmse; + }; + + /** + * @brief Instantiates the dmse codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DMSECodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DMSE_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/dtrace-codelet.hpp b/inst/include/runtime/starpu/concrete/dtrace-codelet.hpp new file mode 100644 index 00000000..d10ce526 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dtrace-codelet.hpp @@ -0,0 +1,91 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dtrace-codelet.hpp + * @brief A class for starpu codelet dtrace. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_DTRACE_CODELET_HPP +#define EXAGEOSTATCPP_DTRACE_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DTRACE Codelet + * @brief A class for starpu codelet dtrace. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dtrace and its CPU functions. + * + */ + template + class DTRACECodelet { + + public: + + /** + * @brief Default constructor + * + */ + DTRACECodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DTRACECodelet() = default; + + /** + * @brief Inserts a task for DTRACE codelet processing. + * @param[in] apDescA A pointer to the descriptor for the matrix. + * @param[in,out] apDescNum A pointer to the descriptor for the sum. + * @param[in,out] apDescTrace A pointer to the descriptor for the trace. + * @return void + * + */ + void InsertTask(void *apDescA, void *apDescNum, void *apDescTrace); + + private: + + /** + * @brief Executes the DTRACE codelet function for matrix trace calculation. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the matrix size. + * @return void + * + */ + static void cl_dtrace_function(void **apBuffers, void *apCodeletArguments); + + /** + * @brief Calculates the trace of a matrix. + * @param[in] pDescriptor A pointer to the matrix data. + * @param[in] aSize The size of the matrix (assumed to be square). + * @param[in,out] pTrace A pointer to the buffer where the trace value will be stored. + * @return The calculated trace of the matrix. + * + */ + static double core_dtrace(const T *pDescriptor, const int &aSize, T *pTrace); + + /// starpu_codelet struct + static struct starpu_codelet cl_dtrace; + + }; + + /** + * @brief Instantiates the dtrace codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DTRACECodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DTRACE_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/dzcpy-codelet.hpp b/inst/include/runtime/starpu/concrete/dzcpy-codelet.hpp new file mode 100644 index 00000000..c8980eee --- /dev/null +++ b/inst/include/runtime/starpu/concrete/dzcpy-codelet.hpp @@ -0,0 +1,82 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dzcpy-codelet.hpp + * @brief A class for starpu codelet dzcpy. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_DZCPY_CODELET_HPP +#define EXAGEOSTATCPP_DZCPY_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class DZCPY Codelet + * @brief A class for starpu codelet dzcpy. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_dzcpy and its CPU functions. + * + */ + template + class DZCPYCodelet { + + public: + + /** + * @brief Default constructor + * + */ + DZCPYCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~DZCPYCodelet() = default; + + /** + * @brief Inserts a task for DZCPY codelet processing. + * @param[in,out] apDescriptor A pointer to the descriptor for the vector. + * @param[in] apDoubleVector A pointer to the double vector to be copied. + * @return void + * + */ + void InsertTask(void *apDescriptor, void *apDoubleVector); + + private: + + /** + * @brief Executes the DZCPY codelet function for copying a double vector. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size, + * offset, and the pointer to the destination vector. + * @return void + * + */ + static void cl_dzcpy_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_dzcpy; + }; + + /** + * @brief Instantiates the dzcpy codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(DZCPYCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_DZCPY_CODELET_HPP + + diff --git a/inst/include/runtime/starpu/concrete/gaussian-to-non-codelet.hpp b/inst/include/runtime/starpu/concrete/gaussian-to-non-codelet.hpp new file mode 100644 index 00000000..932e1dd2 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/gaussian-to-non-codelet.hpp @@ -0,0 +1,92 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file gaussian-to-non-codelet.hpp + * @brief A class for starpu codelet gaussian-to-non. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_GAUSSIAN_TO_NON_CODELET_H +#define EXAGEOSTATCPP_GAUSSIAN_TO_NON_CODELET_H + +#include + +namespace exageostat::runtime { + + /** + * @class Gaussian-To-Non Codelet + * @brief A class for starpu codelet gaussian-to-non. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_gaussian_to_non and its CPU functions. + * + */ + template + class GaussianCodelet { + + public: + + /** + * @brief Default constructor + * + */ + GaussianCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~GaussianCodelet() = default; + + /** + * @brief Inserts a task for Gaussian to non-Gaussian conversion codelet processing. + * @param[in,out] apDesc A pointer to the descriptor for the matrix tile. + * @param[in] apTheta A pointer to the transformation parameters. + * @return void + * + */ + void InsertTask(void *apDesc, T *apTheta); + + private: + + /** + * @brief Executes the Gaussian to non-Gaussian conversion codelet function. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the matrix size, + * offset, and the transformation parameters. + * @return void + * + */ + static void cl_gaussian_to_non_function(void **apBuffers, void *apCodeletArguments); + + /** + * @brief Transforms data from a Gaussian distribution to a non-Gaussian distribution. + * @param[in,out] apDescriptorZ A pointer to the array of data to be transformed. This array is modified in place. + * @param[in] apLocalTheta A pointer to the array of transformation parameters. The first element is the mean (`xi`), + * the second element is the scale (`omega`), the third element is the skewness (`g`), and the fourth element is the kurtosis (`h`). + * @param[in] aSize The size of the data array (`pZ`) and the transformation parameters array (`apLocalTheta`). + * @throws std::runtime_error If the kurtosis parameter (`h`) is negative, indicating an invalid transformation parameter. + * @return void + * + */ + static void core_gaussian_to_non(T *apDescriptorZ, const T *apLocalTheta, const int &aSize); + + /// starpu_codelet struct + static struct starpu_codelet cl_gaussian_to_non; + }; + + /** + * @brief Instantiates the gaussian-to-non codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(GaussianCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_GAUSSIAN_TO_NON_CODELET_H diff --git a/inst/include/runtime/starpu/concrete/non-gaussian-loglike-codelet.hpp b/inst/include/runtime/starpu/concrete/non-gaussian-loglike-codelet.hpp new file mode 100644 index 00000000..cc103f24 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/non-gaussian-loglike-codelet.hpp @@ -0,0 +1,93 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file non-gaussian-loglike-codelet.hpp + * @brief A class for starpu codelet non-gaussian-loglike. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-26 +**/ + +#ifndef EXAGEOSTATCPP_NON_GAUSSIAN_LOGLIKE_CODELET_HPP +#define EXAGEOSTATCPP_NON_GAUSSIAN_LOGLIKE_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class NonGaussianLoglike + * @brief A class for starpu codelet non gaussian loglike. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_non_gaussian_loglike and its CPU functions. + * + */ + template + class NonGaussianLoglike { + + public: + + /** + * @brief Constructor for NonGaussianLoglike + * + */ + NonGaussianLoglike() = default; + + /** + * @brief Default destructor + * + */ + ~NonGaussianLoglike() = default; + + /** + * @brief Inserts a task for Non-Gaussian log-likelihood codelet processing. + * @param[in] apDescZ A pointer to the descriptor for the dataset. + * @param[in,out] apDescSum A pointer to the descriptor for the sum. + * @param[in] apTheta A pointer to the transformation parameters. + * @param[in] aStarPuHelpers A reference to a unique pointer of StarPuHelpers, used for accessing and managing data. + * @return void + * + */ + void + InsertTask(void *apDescZ, void *apDescSum, const T *apTheta, std::unique_ptr &aStarPuHelper); + + private: + + /** + * @brief Executes the Non-Gaussian log-likelihood codelet function. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the dataset size, + * offset, and the transformation parameters. + * @return void + * + */ + static void cl_non_gaussian_loglike_function(void **apBuffers, void *apCodeletArguments); + + /** + * @brief Helper function for calculating the log-likelihood under a non-Gaussian distribution. + * @param[in] apDescriptorZ A pointer to the dataset. + * @param[in] apLocalTheta A pointer to the transformation parameters. + * @param[in] aSize The size of the dataset. + * @return T The calculated log-likelihood of the dataset under a non-Gaussian distribution. + * + */ + static double core_non_gaussian_loglike_helper(const T *apDescriptorZ, const T *apLocalTheta, const int &aSize); + + /// starpu_codelet struct + static struct starpu_codelet cl_non_gaussian_loglike; + }; + + /** + * @brief Instantiates the non-gaussian-loglike class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(NonGaussianLoglike) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_NON_GAUSSIAN_LOGLIKE_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/non-gaussian-transform-codelet.hpp b/inst/include/runtime/starpu/concrete/non-gaussian-transform-codelet.hpp new file mode 100644 index 00000000..c79fd79a --- /dev/null +++ b/inst/include/runtime/starpu/concrete/non-gaussian-transform-codelet.hpp @@ -0,0 +1,132 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file non-gaussian-transform-codelet.hpp + * @brief A class for starpu codelet non-gaussian-transform. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-26 +**/ + +#ifndef EXAGEOSTATCPP_NON_GAUSSIAN_TRANSFORM_CODELET_HPP +#define EXAGEOSTATCPP_NON_GAUSSIAN_TRANSFORM_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class NonGaussianTransform Codelet + * @brief A class for starpu codelet non gaussian transform. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_non_gaussian_transform and its CPU functions. + * + */ + template + class NonGaussianTransform { + + public: + + /** + * @brief Default constructor + * + */ + NonGaussianTransform() = default; + + /** + * @brief Default destructor + * + */ + ~NonGaussianTransform() = default; + + /** + * @brief Inserts a task for Non-Gaussian transformation codelet processing. + * @param[in,out] apDescZ A pointer to the descriptor for the dataset. + * @param[in] apTheta A pointer to the transformation parameters. + * @param[in] apStarPuHelpers A reference to a unique pointer of StarPuHelpers, used for accessing and managing data. + * @return void + * + */ + void InsertTask(void *apDescZ, const T *apTheta, std::unique_ptr &apStarPuHelpers); + + private: + + /** + * @brief Executes the Non-Gaussian transformation codelet function. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the dataset size, + * offset, and the transformation parameters. + * @return void + * + */ + static void cl_non_gaussian_transform_function(void **apBuffers, void *apCodeletArguments); + + /** + * @brief Helper function for transforming a dataset to a non-Gaussian representation. It applies + * the Non-Gaussian transformation to each element of a dataset using the + * Newton-Raphson method for finding the root of a function. + * @param[in,out] apDescripZ A pointer to the dataset to be transformed. + * @param[in] apLocalTheta A pointer to the transformation parameters. + * @param[in] aSize The size of the dataset. + * @return void + * + */ + static void core_non_gaussian_transform_helper(T *apDescripZ, const T *apLocalTheta, const int &aSize); + + /** + * @brief Implements the Newton-Raphson method for finding the root of a function. + * @param[in] apDescriptorZ The initial guess for the root. + * @param[in] aTransLocation The location parameter of the transformation. + * @param[in] aTransScale The scale parameter of the transformation. + * @param[in] aTransShape The shape parameter of the transformation. + * @param[in] aTransKurtosis The kurtosis parameter of the transformation. + * @param[in] aEpsilon The error threshold for the root-finding process. + * @return T The calculated root of the function. + * + */ + static double + newton_raphson(T apDescriptorZ, T aTransLocation, T aTransScale, T aTransShape, T aTransKurtosis, T aEpsilon); + + /** + * @brief Calculates the Non-Gaussian transformation of a value. + * @param[in] aOriginalValue The original value to be transformed. + * @param[in] aCurrentValue The current value of the transformation variable. + * @param[in] aTransLocation The location parameter of the transformation. + * @param[in] aTransScale The scale parameter of the transformation. + * @param[in] aTransShape The shape parameter of the transformation. + * @param[in] aTransKurtosis The kurtosis parameter of the transformation. + * @return T The transformed value. + * + */ + static double tukeyGHTransfor(T aOriginalValue, T aCurrentValue, T aTransLocation, T aTransScale, T aTransShape, + T aTransKurtosis); + + /** + * @brief Calculates the derivative of the Non-Gaussian transformation. + * @param[in] aCurrentValue The current value of the transformation variable. + * @param[in] aTransScale The scale parameter of the transformation. + * @param[in] aTransShape The shape parameter of the transformation. + * @param[in] aTransKurtosis The kurtosis parameter of the transformation. + * @return T The derivative of the transformation at the given value. + * + */ + static double tukeyGHDiferencial(T aCurrentValue, T aTransScale, T aTransShape, T aTransKurtosis); + + /// starpu_codelet struct + static struct starpu_codelet cl_non_gaussian_transform; + }; + + /** + * @brief Instantiates the non-gaussian-transform codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(NonGaussianTransform) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_NON_GAUSSIAN_TRANSFORM_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/stride-vec-codelet.hpp b/inst/include/runtime/starpu/concrete/stride-vec-codelet.hpp new file mode 100644 index 00000000..687c4a17 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/stride-vec-codelet.hpp @@ -0,0 +1,81 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file stride-vec-codelet.hpp + * @brief A class for starpu codelet stride-vec. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_STRIDE_VEC_CODELET_HPP +#define EXAGEOSTATCPP_STRIDE_VEC_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class stride-vec Codelet + * @brief A class for starpu codelet stride-vec. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_stride_vec and its CPU functions. + * + */ + template + class STRIDEVECCodelet { + + public: + + /** + * @brief Default constructor + * + */ + STRIDEVECCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~STRIDEVECCodelet() = default; + + /** + * @brief Inserts a task for STRIDE vector operation codelet processing. + * @param[in] apDescA A pointer to the descriptor for the source vector. + * @param[in,out] apDescB A pointer to the descriptor for the first destination vector. + * @param[in,out] apDescC A pointer to the descriptor for the second destination vector. + * @return void + * + */ + void InsertTask(const void *apDescA, void *apDescB, void *apDescC); + + private: + + /** + * @brief Executes the STRIDE vector operation codelet function. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size, + * offset, and the stride factor. + * @return void + * + */ + static void cl_stride_vec_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_stride_vec; + }; + + /** + * @brief Instantiates the stride-vec codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(STRIDEVECCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_STRIDE_VEC_CODELET_HPP diff --git a/inst/include/runtime/starpu/concrete/tri-stride-vec-codelet.hpp b/inst/include/runtime/starpu/concrete/tri-stride-vec-codelet.hpp new file mode 100644 index 00000000..ae26f348 --- /dev/null +++ b/inst/include/runtime/starpu/concrete/tri-stride-vec-codelet.hpp @@ -0,0 +1,82 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file tri-stride-vec-codelet.hpp + * @brief A class for starpu codelet tri-stride-vec. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_TRI_STRIDE_VEC_CODELET_HPP +#define EXAGEOSTATCPP_TRI_STRIDE_VEC_CODELET_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class TriStrideVecCodelet Codelet + * @brief A class for starpu codelet tri_stride_vec. + * @tparam T Data Type: float or double + * @details This class encapsulates the struct cl_tri_stride_vec and its CPU functions. + * + */ + template + class TriStrideVecCodelet { + + public: + + /** + * @brief Default constructor + * + */ + TriStrideVecCodelet() = default; + + /** + * @brief Default destructor + * + */ + ~TriStrideVecCodelet() = default; + + /** + * @brief Inserts a task for TriStride vector operation codelet processing. + * @param[in] apDescA A pointer to the descriptor for the source vector. + * @param[in,out] apDescB A pointer to the descriptor for the first destination vector. + * @param[in,out] apDescC A pointer to the descriptor for the second destination vector. + * @param[in,out] apDescD A pointer to the descriptor for the third destination vector. + * @return void + * + */ + void InsertTask(const void *apDescA, void *apDescB, void *apDescC, void *apDescD); + + private: + + /** + * @brief Executes the TriStride vector operation codelet function. + * @param[in] apBuffers An array of pointers to the buffers. + * @param[in] apCodeletArguments A pointer to the codelet arguments structure, which includes the vector size, + * offset, and the stride factor. + * @return void + * + */ + static void cl_tri_stride_vec_function(void **apBuffers, void *apCodeletArguments); + + /// starpu_codelet struct + static struct starpu_codelet cl_tri_stride_vec; + }; + + /** + * @brief Instantiates the tri-stride-vec codelet class for float and double types. + * @tparam T Data Type: float or double + * + */ + EXAGEOSTAT_INSTANTIATE_CLASS(TriStrideVecCodelet) + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_TRI_STRIDE_VEC_CODELET_HPP diff --git a/inst/include/runtime/starpu/helpers/StarPuHelpers.hpp b/inst/include/runtime/starpu/helpers/StarPuHelpers.hpp new file mode 100644 index 00000000..cfaa98f5 --- /dev/null +++ b/inst/include/runtime/starpu/helpers/StarPuHelpers.hpp @@ -0,0 +1,114 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuHelpers.hpp + * @brief An interface for StarPu helpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_STARPUHELPERS_HPP +#define EXAGEOSTATCPP_STARPUHELPERS_HPP + +#include + +#include +#include + +namespace exageostat::runtime { + + /** + * @class StarPuHelpers + * @brief A class that defines the interface for StarPu helpers. + * @tparam T Data Type: float or double. + * + */ + class StarPuHelpers { + public: + + /** + * @brief Initialize the runtime option structure for either HiCMA or CHAMELEON. + * @param[in, out] apOptions The options structure that needs to be initialized. + * @param[in] apSequence The sequence structure to associate in the options. + * @param[in] apRequest The request structure to associate in the options. + * @return void + * + */ + virtual void + ExaGeoStatOptionsInit(void *apOptions, void *apSequence, void *apRequest) = 0; + + /** + * @brief Submit the release of the workspaces associated to the options structure. + * @param[in,out] apOptions The options structure for which to workspaces will be released + * @return void + * + */ + virtual void ExaGeoStatOptionsFree(void *apOptions) = 0; + + /** + * @brief Finalize the runtime option structure for either HiCMA or CHAMELEON. + * @param[in,out] apOptions The options structure that needs to be finalized. + * @return void + * + */ + virtual void ExaGeoStatOptionsFinalize(void *apOptions) = 0; + + /** + * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. + * @param[in] apDescriptor The descriptor to which belongs the piece of data + * @param[in] aDescRow The row coordinate of the piece of data in the matrix + * @param[in] aDescCol The column coordinate of the piece of data in the matrix + * @return void + * + */ + virtual void *ExaGeoStatDataGetAddr(void *apDescriptor, const int &aDescRow, const int &aDescCol) = 0; + + /** + * @brief Get the number of tile rows of the sub-matrix + * @param[in] apDescriptor + * @return int + * + */ + virtual int GetMT(void *apDescriptor) = 0; + + /** + * @brief Get the descriptor number of rows + * @param[in] apDescriptor + * @return int + * + */ + virtual int GetM(void *apDescriptor) = 0; + + /** + * @brief Get the descriptor number of rows in a tile + * @param[in] apDescriptor + * @return int + * + */ + virtual int GetMB(void *apDescriptor) = 0; + + /** + * @brief Get the descriptor options + * @return void pointer to descriptor_option + * @return void + * + */ + virtual void *GetOptions() = 0; + + /** + * @brief Delete the options object + * @param apOptions + * @return void + * + */ + virtual void DeleteOptions(void *apOptions) = 0; + + }; + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_STARPUHELPERS_HPP diff --git a/inst/include/runtime/starpu/helpers/StarPuHelpersFactory.hpp b/inst/include/runtime/starpu/helpers/StarPuHelpersFactory.hpp new file mode 100644 index 00000000..e8d9656c --- /dev/null +++ b/inst/include/runtime/starpu/helpers/StarPuHelpersFactory.hpp @@ -0,0 +1,42 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuHelpersFactory.hpp + * @brief Factory for StarPu helpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_STARPUHELPERSFACTORY_HPP +#define EXAGEOSTATCPP_STARPUHELPERSFACTORY_HPP + +#include + +namespace exageostat::runtime { + + /** + * @class StarPuHelpersFactory + * @brief A class that creates StarPu helpers based on the input computation type. + * + */ + class StarPuHelpersFactory { + + public: + + /** + * @brief Creates a StarPu helper. + * @param[in] aComputation The computation type to create the solver for. + * @return Unique pointer to the created StarPu helper. + * + */ + static std::unique_ptr CreateStarPuHelper(const common::Computation &aComputation); + + }; + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_STARPUHELPERSFACTORY_HPP diff --git a/inst/include/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.hpp b/inst/include/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.hpp new file mode 100644 index 00000000..ee597973 --- /dev/null +++ b/inst/include/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.hpp @@ -0,0 +1,108 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ChameleonStarPuHelpers.hpp + * @brief A class for Chameleon implementation of StarPu helpers interface StarPuHelpers.hpp. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_CHAMELEONSTARPUHELPERS_HPP +#define EXAGEOSTATCPP_CHAMELEONSTARPUHELPERS_HPP + +#include + +namespace exageostat::runtime { + + /** + * @brief ChameleonStarPuHelpers is a concrete implementation of StarPuHelpers interface for Chameleon library. + * + */ + class ChameleonStarPuHelpers : public StarPuHelpers { + public: + + /** + * @brief Default constructor. + */ + ChameleonStarPuHelpers() = default; + + /** + * @brief Default destructor. + */ + ~ChameleonStarPuHelpers() = default; + + /** + * @brief Initialize the runtime option structure for CHAMELEON + * @copydoc StarPuHelpers::ExaGeoStatOptionsInit() + * + */ + void + ExaGeoStatOptionsInit(void *apOptions, void *apSequence, void *apRequest) override; + + /** + * @brief Submit the release of the workspaces associated to the options structure. + * @copydoc StarPuHelpers::ExaGeoStatOptionsFree() + * + */ + void + ExaGeoStatOptionsFree(void *apOptions) override; + + /** + * @brief Finalize the runtime option structure for CHAMELEON. + * @copydoc StarPuHelpers::ExaGeoStatOptionsFinalize() + * + */ + void + ExaGeoStatOptionsFinalize(void *apOptions) override; + + /** + * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. + * @copydoc StarPuHelpers::ExaGeoStatDataGetAddr() + * + */ + void *ExaGeoStatDataGetAddr(void *apDescriptor, const int &aDescRow, const int &aDescCol) override; + + /** + * @brief Get the number of tile rows of the sub-matrix + * @copydoc StarPuHelpers::GetMT() + * + */ + int GetMT(void *apDescriptor) override; + + /** + * @brief Get the descriptor number of rows + * @copydoc StarPuHelpers::GetM() + * + */ + int GetM(void *apDescriptor) override; + + /** + * @brief Get the descriptor number of rows in a tile + * @copydoc StarPuHelpers::GetMB() + * + */ + int GetMB(void *apDescriptor) override; + + /** + * @brief Get the descriptor options + * @copydoc StarPuHelpers::GetOptions() + * + */ + void *GetOptions() override; + + /** + * @brief Delete the options object + * @copydoc StarPuHelpers::DeleteOptions() + * + */ + void DeleteOptions(void *apOptions) override; + + }; + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_CHAMELEONSTARPUHELPERS_HPP diff --git a/inst/include/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.hpp b/inst/include/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.hpp new file mode 100644 index 00000000..c59d2ff3 --- /dev/null +++ b/inst/include/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.hpp @@ -0,0 +1,107 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file HicmaStarPuHelpers.hpp + * @brief A class for Hicma implementation of StarPu helpers interface StarPuHelpers.hpp. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#ifndef EXAGEOSTATCPP_HICMASTARPUHELPERS_HPP +#define EXAGEOSTATCPP_HICMASTARPUHELPERS_HPP + +#include + +namespace exageostat::runtime { + + /** + * @brief HicmaStarPuHelpers is a concrete implementation of StarPuHelpers interface for Hicma library. + * + */ + class HicmaStarPuHelpers : public StarPuHelpers { + public: + + /** + * @brief Default constructor. + * + */ + HicmaStarPuHelpers() = default; + + /** + * @brief Default destructor. + * + */ + ~HicmaStarPuHelpers() = default; + + /** + * @brief Initialize the runtime option structure for HiCMA + * @copydoc StarPuHelpers::ExaGeoStatOptionsInit() + * + */ + void ExaGeoStatOptionsInit(void *apOptions, void *apSequence, void *apRequest) override; + + /** + * @brief Submit the release of the workspaces associated to the options structure. + * @copydoc StarPuHelpers::ExaGeoStatOptionsFree() + * + */ + void ExaGeoStatOptionsFree(void *apOptions) override; + + /** + * @brief Finalize the runtime option structure for HiCMA. + * @copydoc StarPuHelpers::ExaGeoStatOptionsFinalize() + * + */ + void ExaGeoStatOptionsFinalize(void *apOptions) override; + + /** + * @brief Get the pointer to the data or the runtime handler associated to the piece of data (m, n) in desc. + * @copydoc StarPuHelpers::ExaGeoStatDataGetAddr() + * + */ + void *ExaGeoStatDataGetAddr(void *apDescriptor, const int &aDescRow, const int &aDescCol) override; + + /** + * @brief Get the number of tile rows of the sub-matrix + * @copydoc StarPuHelpers::GetMT() + * + **/ + int GetMT(void *apDescriptor) override; + + /** + * @brief Get the descriptor number of rows + * @copydoc StarPuHelpers::GetM() + * + */ + int GetM(void *apDescriptor) override; + + /** + * @brief Get the descriptor number of rows in a tile + * @copydoc StarPuHelpers::GetMB() + * + */ + int GetMB(void *apDescriptor) override; + + /** + * @brief Get the descriptor options + * @copydoc StarPuHelpers::GetOptions) + * + */ + void *GetOptions() override; + + /** + * @brief Delete the options object + * @copydoc StarPuHelpers::DeleteOptions() + * + */ + void DeleteOptions(void *apOptions) override; + + }; + +}//namespace exageostat + +#endif //EXAGEOSTATCPP_HICMASTARPUHELPERS_HPP diff --git a/inst/include/utilities/EnumStringParser.hpp b/inst/include/utilities/EnumStringParser.hpp new file mode 100644 index 00000000..ee7201bb --- /dev/null +++ b/inst/include/utilities/EnumStringParser.hpp @@ -0,0 +1,64 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file EnumStringParser.hpp + * @brief Provides utility functions for parsing enumeration values from strings. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-20 +**/ + +#ifndef EXAGEOSTATCPP_ENUMSTRINGPARSER_HPP +#define EXAGEOSTATCPP_ENUMSTRINGPARSER_HPP + +#include + +#include +#include + +/** + * @brief Convert a string representation of computation mode to its corresponding enum value. + * @param[in] aComputation String representation of computation mode. + * @return Computation enum value. + */ +inline exageostat::common::Computation GetInputComputation(std::string aComputation) { + std::transform(aComputation.begin(), aComputation.end(), + aComputation.begin(), ::tolower); + + if (aComputation == "exact" || aComputation == "dense") { + return exageostat::common::EXACT_DENSE; + } else if (aComputation == "dst" || aComputation == "diag_approx") { + return exageostat::common::DIAGONAL_APPROX; + } else if (aComputation == "tlr" || aComputation == "tile_low_rank") { + return exageostat::common::TILE_LOW_RANK; + } else { + const std::string msg = "Error in Initialization : Unknown computation Value" + std::string(aComputation); + throw API_EXCEPTION(msg, INVALID_ARGUMENT_ERROR); + } +} + +/** + * @brief Converts string to dimension enum. + * @param[in] aDimension Dimension as a string. + * @return Dimension as an enum. + */ +inline exageostat::common::Dimension GetInputDimension(std::string aDimension) { + std::transform(aDimension.begin(), aDimension.end(), + aDimension.begin(), ::tolower); + + if (aDimension == "2d") { + return exageostat::common::Dimension2D; + } else if (aDimension == "3d") { + return exageostat::common::Dimension3D; + } else if (aDimension == "st") { + return exageostat::common::DimensionST; + } else { + const std::string msg = "Error in Initialization : Unknown computation Value" + std::string(aDimension); + throw API_EXCEPTION(msg, INVALID_ARGUMENT_ERROR); + } +} + +#endif //EXAGEOSTATCPP_ENUMSTRINGPARSER_HPP diff --git a/inst/include/utilities/ErrorHandler.hpp b/inst/include/utilities/ErrorHandler.hpp new file mode 100644 index 00000000..41b24628 --- /dev/null +++ b/inst/include/utilities/ErrorHandler.hpp @@ -0,0 +1,95 @@ +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ErrorHandler.hpp + * @version 1.1.0 + * @brief Provides error handling functionalities. + * @details Defines macros and functions for handling errors and warnings. + * @author Mahmoud ElKarargy + * @author David Helmy + * @date 2024-01-20 +**/ + +#ifndef EXAGEOSTATCPP_ERRORHANDLER_HPP +#define EXAGEOSTATCPP_ERRORHANDLER_HPP + +#ifdef USE_CUDA +#include +#endif + +/** + * @brief EXAGEOSTAT API Exceptions Macro to use for Errors and Warnings. + */ +#define API_EXCEPTION(MESSAGE, ERROR_TYPE) \ + APIException(MESSAGE, ERROR_TYPE) + +#ifdef USE_CUDA +/** + * @brief Useful macro wrapper for all cuda API calls to ensure correct returns, + * and error throwing on failures. + */ +#define GPU_ERROR_CHECK(ans) { APIException::AssertGPU((ans), __FILE__, __LINE__); } +#endif + +/** + * @brief Enumeration for error types. + */ +enum ErrorType : int { + RUNTIME_ERROR = 0, + RANGE_ERROR = 1, + INVALID_ARGUMENT_ERROR = 2, + WARNING = 3, +}; + +/** + * @class APIException + * @brief Custom exception class for handling API errors and warnings. + */ +class APIException : public std::exception { + +public: + + /** + * @brief Constructor for APIException. + * @param[in] aMessage The error or warning message. + * @param[in] aErrorCode The error type. + */ + APIException(const std::string &aMessage, const ErrorType &aErrorCode) { + + if (aErrorCode == RUNTIME_ERROR) { + throw std::runtime_error(aMessage); + } else if (aErrorCode == INVALID_ARGUMENT_ERROR) { + throw std::invalid_argument(aMessage); + } else if (aErrorCode == RANGE_ERROR) { + throw std::range_error(aMessage); + } + } + + /** + * @brief Destructor for APIException. + */ + ~APIException() override = default; + +#ifdef USE_CUDA + /** + * @brief Function to assert the return code of a CUDA API call and ensure it completed successfully. + * @param[in] aCode The code returned from the CUDA API call. + * @param[in] aFile The name of the file that the assertion was called from. + * @param[in] aLine The line number in the file that the assertion was called from. + */ + inline static void AssertGPU(cudaError_t aCode, const char *aFile, int aLine) + { + if (aCode != cudaSuccess) + { + char s[200]; + sprintf((char*)s,"GPU Assert: %s %s %d\n", cudaGetErrorString(aCode), aFile, aLine); + throw std::invalid_argument(s); + } + } +#endif + +}; + +#endif //EXAGEOSTATCPP_ERRORHANDLER_HPP \ No newline at end of file diff --git a/inst/include/utilities/Logger.hpp b/inst/include/utilities/Logger.hpp new file mode 100644 index 00000000..04fbb1c6 --- /dev/null +++ b/inst/include/utilities/Logger.hpp @@ -0,0 +1,130 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file Logger.hpp + * @brief Provides logging and timing macros for debugging and profiling. + * @details Defines macros for verbose logging, various levels of logging, and timing. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-04 +**/ + +#ifndef EXAGEOSTATCPP_LOGGER_HPP +#define EXAGEOSTATCPP_LOGGER_HPP + +#include +#include +#include + +#include +#include +#include + +/** + * @def DEFAULT_PRECISION + * @brief The value of the default C++ std::std::cout number of precision. + */ +#define DEFAULT_PRECISION 6 + +/** + * @def VERBOSE(msg) + * @brief Verbose macro for logging and debugging mode. + */ +#define VERBOSE(msg) \ + if(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::DETAILED_MODE && \ + !exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) { \ + std::ostringstream oss; \ + oss << "\t\t\t " << msg << std::endl; \ + std::cout << oss.str(); \ + } + +/** + * @def LOGGER_1(msg) + * @brief LOGGER_1 macro for logging outputs with double taps and new line at the end. + */ +#define LOGGER_1(msg) \ + if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && !exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()){ \ + std::ostringstream oss; \ + oss << "\t\t " << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg << std::endl; \ + std::cout << oss.str(); \ + } + +/** + * @def LOGGER_2(msg, A) + * @brief LOGGER_2 macro for logging outputs with double taps and without new line at the end. + */ +#define LOGGER_2(msg, A) \ + if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && !exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()){ \ + std::ostringstream oss; \ + oss << "\t\t " << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg; \ + std::cout << oss.str(); \ +} +/** + * @def LOGGER_CONTROL(x, A, B, FUNC, ...) + * @brief LOGGER_CONTROL is The internal macro that simply strips the excess and ends up with the required macro + */ +#define LOGGER_CONTROL(x, A, B, FUNC, ...) FUNC + +/** + * @def LOGGER(...) + * @brief LOGGER macro that's called, Used to logging outputs. + */ +#define LOGGER(...) LOGGER_CONTROL(,##__VA_ARGS__, \ + LOGGER_2(__VA_ARGS__), \ + LOGGER_1(__VA_ARGS__), \ + ) + +/** + * @def LOGGER_PRECISION_1(msg, precision) + * @brief LOGGER_PRECISION_1 macro for logging outputs without any taps, without new line at the end, and with customized precision. + */ +#define LOGGER_PRECISION_1(msg, precision) \ + if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && !exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()){ \ + std::ostringstream oss; \ + oss << std::fixed << std::setprecision(precision) << msg; \ + std::cout << oss.str(); \ + } + +/** + * @def LOGGER_PRECISION_2(msg) + * @brief LOGGER_PRECISION_2 macro for logging outputs without any taps, without new line at the end, and with default C++ precision. + */ +#define LOGGER_PRECISION_2(msg) \ + if(!(exageostat::configurations::Configurations::GetVerbosity() == exageostat::common::Verbose::QUIET_MODE) && !exageostat::helpers::CommunicatorMPI::GetInstance()->GetRank()) {\ + std::ostringstream oss; \ + oss << std::fixed << std::setprecision(DEFAULT_PRECISION) << msg; \ + std::cout << oss.str(); \ + } +/** + * @def LOGGER_PRECISION_CONTROL + * @brief is The internal macro that simply strips the excess and ends up with the required macro + */ +#define LOGGER_PRECISION_CONTROL(x, A, B, FUNC, ...) FUNC + +/** + * @def LOGGER_PRECISION(...) + * @brief LOGGER_PRECISION macro that's called, Used for logging outputs with precision. + */ +#define LOGGER_PRECISION(...) LOGGER_PRECISION_CONTROL(,##__VA_ARGS__, \ + LOGGER_PRECISION_1(__VA_ARGS__), \ + LOGGER_PRECISION_2(__VA_ARGS__), \ + ) + +/** + * @def START_TIMING(t) + * @brief Timing macro to start timing. + */ +#define START_TIMING(t) auto t##_start = std::chrono::high_resolution_clock::now() + +/** + * @def STOP_TIMING(t) + * @brief Timing macro to stop timing. + */ +#define STOP_TIMING(t) auto t##_end = std::chrono::high_resolution_clock::now(); \ + t = std::chrono::duration_cast>(t##_end - t##_start).count() + +#endif //EXAGEOSTATCPP_LOGGER_HPP diff --git a/man/Data.Rd b/man/Data.Rd new file mode 100644 index 00000000..7a42007f --- /dev/null +++ b/man/Data.Rd @@ -0,0 +1,45 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file Data.Rd +% @brief roxygen2 documentation for the R Interface of ExaGeoStatData class +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{ExaGeoStatData} +\alias{ExaGeoStatData} +\title{ExaGeoStatData Class} + +\description{ +The \code{ExaGeoStatData} class is designed to facilitate the handling and manipulation of geospatial statistics data within the ExaGeoStat framework. +It provides a structured way to store and manage data points based on their dimensions. +Instances of this class can hold a specified number of location points, and support different data dimensions including two-dimensional (2D), three-dimensional (3D), and spatiotemporal (ST) configurations. +} + +\section{Constructor}{ + \code{\link{ExaGeoStatData}} Creates a new instance of the + \code{ExaGeoStatData} class by calling: + \preformatted{ + new(ExaGeoStatData, problem_size, dimension) + } + \describe{ + \item{\code{size}}{An integer represents the size of the locations data.} + \item{\code{dimension}}{A string represents the dimensions of the data. + Available dimensions are "2D", "3D", and "ST".} + } +} + +\value{ +An object of class \code{ExaGeoStatData} represents a data component with the specified size and dimension. +} + +\examples{ +problem_size <- 4 +dimension = "3D" +empty_data <- new(Data, problem_size, dimension) +} + +\keyword{S4 class} diff --git a/man/Hardware.Rd b/man/Hardware.Rd new file mode 100644 index 00000000..4b85582f --- /dev/null +++ b/man/Hardware.Rd @@ -0,0 +1,56 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file Hardware.Rd +% @brief roxygen2 documentation for the R Interface of ExaGeoStatHardware class. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{ExaGeoStatHardware} +\alias{ExaGeoStatHardware} +\title{ExaGeoStatHardware Class} + +\description{ +The ExaGeoStatHardware class represents a hardware component in the ExaGeoStat system. +It is initialized with computation mode, and two integers represents number of CPU cores and number of GPU cores. +} + +\section{Constructor}{ + \code{\link{ExaGeoStatHardware}} Creates a new instance of the + \code{ExaGeoStatHardware} class by calling: + \preformatted{ + new(Hardware, computation, ncores, ngpus, p, q) + } + \describe{ + \item{\code{computation}}{A string specifies the computation method, either "exact" or "dst" or "tlr".} + \item{\code{ncores}}{An integer represents number of CPU cores.} + \item{\code{ngpus}}{An integer represents number of GPU cores.} + \item{\code{p}}{An integer represents P grid dimension.} + \item{\code{q}}{An integer represents Q grid dimension.} +} +} + +\section{Methods}{ +\subsection{finalize_hardware}{ +\code{finalize_hardware()} manually finalizes the hardware by resetting the context. +} +} + +\value{ +An object of class \code{ExaGeoStatHardware} represents a hardware component with the specified component and number of CPU cores and GPU cores. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +p <- 2 +q <- 2 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, p, q) +hardware$finalize_hardware() +} + +\keyword{S4 class} diff --git a/man/fisher.Rd b/man/fisher.Rd new file mode 100644 index 00000000..a0fc0b7a --- /dev/null +++ b/man/fisher.Rd @@ -0,0 +1,83 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file fisher.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatFisher function. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{fisher} +\alias{fisher } +\title{Fisher function} + +\usage{ +fisher(kernel, distance_matrix = "euclidean", estimated_theta, dts, +lts = 0, dimension = "2D", train_data, test_data) +} + +\arguments{ +\item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } +\item{distance_matrix}{ A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} +\item{estimated_theta}{A list of estimated theta parameters.} +\item{dts}{A numeric value represents the time step size.} +\item{lts}{A numeric value represents the length step size. Default is 0.} +\item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} +\item{train_data}{ A numeric vector contains the locations and z measurements for training.} +\item{test_data}{ A numeric vector contains the locations for testing.} +} + +\value{A vector contains the Fisher information matrix elements.} + +\description{This function computes the Fisher information matrix for a given dataset and theta vector, +using a specified kernel and distance metric. It also allows for the inclusion of missing values and the specification of data dimensions.} + +\examples{ +dimension = "2D" +ncores <- 1 +ngpus <- 0 +dts <- 2 +kernel <- "univariate_matern_stationary" +estimated_theta <- c(1,0.1,0.5) +computation <- "exact" +p <- 1 +q <- 1 +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +z_value <- c(-1.272336140360187606, -2.590699695867695773, + 0.512142584178685967, -0.163880452049749520) +locations_x <- c(0.092042420080872822, 0.193041886015106440, + 0.330556191348134576, 0.181612878614480805) +locations_y <- c(0.928648813611047563, 0.103883421072709245, + 0.135790035858701447, 0.434683756771190977) + +test_x <- c(0.347951, 0.62768) +test_y <- c(0.806332, 0.105196) + +fisher_matrix <- fisher(train_data=list(locations_x, locations_y, z_value), +test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) +} diff --git a/man/get_Z_measurement_vector.Rd b/man/get_Z_measurement_vector.Rd new file mode 100644 index 00000000..5dc60933 --- /dev/null +++ b/man/get_Z_measurement_vector.Rd @@ -0,0 +1,51 @@ +// TODO: dots +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file get_Z_measurement_vector.Rd +% @brief roxygen2 documentation for the R Interface of get_Z_measurment_vector function. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{get_Z_measurement_vector} +\alias{get_Z_measurement_vector} +\title{Get descriptive Z values function} + +\description{ +Retrieves descriptive Z values from ExaGeoStat data based on type. +} + +\usage{ +get_Z_measurement_vector(data,type) +} + +\arguments{ +\item{data}{A list of ExaGeoStatData that contains the locations.} +\item{type}{A string specifies the type of descriptor value to retrieve (e.g., "Chameleon", "HiCMA").} +} + +\value{ +A numeric vector of descriptive Z values. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +computation <- "exact" +p <- 1 +q <- 1 +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +dimension = "3D" +problem_size <- 4 +empty_data <- new(Data, problem_size, dimension) + +dts <- 2 +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, +problem_size=problem_size, dts=dts, dimension=dimension) +Z <- get_Z_measurement_vector(data=exageostat_data, type="chameleon") +} diff --git a/man/get_locations.Rd b/man/get_locations.Rd new file mode 100644 index 00000000..42eb4153 --- /dev/null +++ b/man/get_locations.Rd @@ -0,0 +1,49 @@ +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file get_locations.Rd +% @brief roxygen2 documentation for the R Interface of get_locations function for all coordinates. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{get_locations} +\alias{get_locations} +\title{Get Locations function} + +\description{ +Retrieves all the coordinates of locations from ExaGeoStatData object. +} + +\usage{ +get_locations(data) +} + +\arguments{ +\item{data}{A list of ExaGeoStatData that contains the locations.} +} + +\value{ +A numeric vector of locations. +} + +\examples{ +ncores <- 1 +ngpus <- 0 +computation <- "exact" +p <- 1 +q <- 1 +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +dimension = "2D" +problem_size <- 4 +empty_data <- new(Data, problem_size, dimension) + +dts <- 2 +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, +problem_size=problem_size, dts=dts, dimension=dimension) +locs <- get_locations(data=exageostat_data) +} diff --git a/man/idw.Rd b/man/idw.Rd new file mode 100644 index 00000000..a102bab0 --- /dev/null +++ b/man/idw.Rd @@ -0,0 +1,88 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file idw.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatIDW function. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{idw} +\alias{idw} +\title{IDW function} + +\usage{ +idw(kernel, distance_matrix = "euclidean", estimated_theta, dts, lts = 0, +dimension = "2D", train_data, test_data, test_measurements) +} + +\arguments{ +\item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } + \item{distance_matrix}{ A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} + \item{estimated_theta}{A list of estimated theta parameters.} + \item{dts}{A numeric value represents the time step size.} + \item{lts}{A numeric value represents the length step size. Default is 0.} + \item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} + \item{train_data}{ A numeric vector contains the locations and z measurements for training.} + \item{test_data}{ A numeric vector contains the locations for testing.} + \item{test_measurements}{ A numeric vector contains the z measurements for testing.} +} + +\value{ + A vector contains the IDW error. +} + +\description{ +This function performs Inverse Distance Weighting (IDW) interpolation for a given dataset and theta vector. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) + +problem_size <- 4 +dimension = "2D" +dts <- 2 +kernel <- "univariate_matern_stationary" +estimated_theta <- c(1,0.1,0.5) + +z_value <- c( -1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520) +locations_x <- c(0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440) +locations_y <- c(0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537) +test_x <- c(0.347951, 0.62768) +test_y <- c(0.806332, 0.105196) +test_measurements = c(-1.05428, -1.47441) + +idw_error = idw(kernel=kernel, estimated_theta=estimated_theta, dts=dts, +train_data=list(locations_x, locations_y, z_value), +test_data=list(test_x, test_y), test_measurements=test_measurements) +} diff --git a/man/mloe_mmom.Rd b/man/mloe_mmom.Rd new file mode 100644 index 00000000..eed7afcb --- /dev/null +++ b/man/mloe_mmom.Rd @@ -0,0 +1,89 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file mloe_mmom.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatMLOE_MMOM function +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{mloe_mmom} +\alias{mloe_mmom} +\title{MLOE MMOM function} + +\usage{ +mloe_mmom(kernel, distance_matrix="euclidean", estimated_theta, true_theta, +dts, lts=0, dimension="2D", train_data, test_data) +} + +\arguments{ + \item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } +\item{distance_matrix}{ A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} +\item{estimated_theta}{A list of estimated theta parameters.} +\item{true_theta}{A list of truth theta parameters.} +\item{dts}{A numeric value represents the time step size.} +\item{lts}{A numeric value represents the length step size. Default is 0.} +\item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} +\item{train_data}{ A numeric vector contains the locations and z measurements for training.} +\item{test_data}{ A numeric vector contains the locations for testing.} +} + +\value{ +A vector of MLOE/MMOM values +} + +\description{ +This function calculates Mean Misspecification of the Mean Square Error (MMOM) and Mean Loss of Efficiency (MLOE). +} + +\examples{ +ncores <- 2 +ngpus <- 0 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) + +problem_size <- 4 +dimension = "2D" +dts <- 2 +kernel <- "univariate_matern_stationary" +estimated_theta <- c(1,0.1,0.5) +true_theta <- c(1.1,0.2,0.5) + +z_value <- c(-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520) +locations_x <- c(0.092042420080872822, 0.193041886015106440, 0.330556191348134576, + 0.181612878614480805) +locations_y <- c(0.928648813611047563, 0.103883421072709245, 0.135790035858701447, + 0.434683756771190977) + +test_x <- c(0.347951, 0.62768) +test_y <- c(0.806332, 0.105196) + +result_mloe_mmom = mloe_mmom(train_data=list(locations_x, locations_y, z_value), +test_data=list(test_x, test_y), kernel=kernel, dts=dts, +estimated_theta=estimated_theta, true_theta=true_theta) +} diff --git a/man/model_data.Rd b/man/model_data.Rd new file mode 100644 index 00000000..b49a3665 --- /dev/null +++ b/man/model_data.Rd @@ -0,0 +1,96 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file model_data.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatModelData function. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{model_data} +\alias{model_data} +\title{Model Data function} + +\usage{ +model_data(computation = "exact", kernel, distance_matrix = "euclidean", lb, +ub, tol = 4, mle_itr, dts, lts = 0, dimension = "2D", band = 0, max_rank = 500, +data = NULL, matrix = NULL, x = NULL, y = NULL, z = NULL) +} + +\arguments{ +\item{computation}{A string specifies the computation method, either "exact" or "dst" or "tlr". Default is "exact".} + \item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } +\item{distance_matrix}{A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} +\item{lb}{A numeric value represents the lower bound for the computation.} +\item{ub}{A numeric value represents the upper bound for the computation.} +\item{tol}{A numeric value specifies the tolerance for the computation. Default is 4.} +\item{mle_itr}{A numeric value specifies the maximum number of iterations for the computation.} +\item{dts}{A numeric value represents the time step size.} +\item{lts}{A numeric value represents the length step size. Default is 0.} +\item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} +\item{band}{A numeric value Bandwidth for band matrices, applicable in certain computational kernels, Default is 0.} +\item{max_rank}{A numeric value specifies the Maximum rank for low-rank approximations, Default is 500.} +\item{data}{A list of data vectors. Default is `R_NilValue`.} +\item{matrix}{A matrix object. Default is `R_NilValue`.} +\item{x}{A numeric vector. Default is `R_NilValue`.} +\item{y}{A numeric vector. Default is `R_NilValue`.} +\item{z}{A numeric vector. Default is `R_NilValue`.} +} + +\value{ +A vector contains the starting theta. +} + +\description{ +This function models data based on the provided computation method, kernel, distance matrix, and other parameters. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) + +dimension = "2D" +problem_size <- 4 +empty_data <- new(Data, problem_size, dimension) + +dts <- 2 +kernel <- "univariate_matern_stationary" +lower_bound <- c(0.1,0.1,0.1) +upper_bound <- c(5,5,5) + +z_value <- c( -1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520) +locations_x <- c(0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440) +locations_y <- c(0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537) + +theta <- model_data(kernel=kernel, lb=lower_bound, ub=upper_bound, +mle_itr=10, dts=dts, matrix=z_value, x=locations_x, y=locations_y) +} diff --git a/man/predict_data.Rd b/man/predict_data.Rd new file mode 100644 index 00000000..217bf2f2 --- /dev/null +++ b/man/predict_data.Rd @@ -0,0 +1,84 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file predict_data.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatPredictData function. +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{predict_data} +\alias{predict_data} +\title{Predict Data function} + +\usage{ +predict_data(kernel, distance_matrix = "euclidean", estimated_theta, +dts, lts = 0, dimension = "2D", train_data, test_data) +} + +\arguments{ + \item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } + \item{distance_matrix}{ A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} + \item{estimated_theta}{A list of estimated theta parameters.} + \item{dts}{A numeric value represents the time step size.} + \item{lts}{A numeric value represents the length step size. Default is 0.} + \item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} + \item{train_data}{ A numeric vector contains the locations and z measurements for training.} + \item{test_data}{ A numeric vector contains the locations for testing.} +} + +\value{ + A vector of predicted z values +} + +\description{ +This function predicts data based on the provided kernel, distance matrix, estimated theta, and other parameters. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +problem_size <- 4 +dts <- 2 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) +kernel <- "univariate_matern_stationary" +estimated_theta <- c(1,0.1,0.5) + +z_value <- c( -1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520) +locations_x <- c(0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440) +locations_y <- c(0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537) +test_x <- c(0.347951, 0.62768) +test_y <- c(0.806332, 0.105196) + +predict_data(train_data=list(locations_x, locations_y, z_value), +test_data=list(test_x, test_y), kernel=kernel, dts=dts, +estimated_theta=estimated_theta) +} diff --git a/man/simulate_data.Rd b/man/simulate_data.Rd new file mode 100644 index 00000000..c9f40a2f --- /dev/null +++ b/man/simulate_data.Rd @@ -0,0 +1,83 @@ + +% Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +% All rights reserved. +% ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +% @file simulate_data.Rd +% @brief roxygen2 documentation for the R Interface of R_ExaGeoStatLoadData function +% @version 1.1.0 +% @author Mahmoud ElKarargy +% @date 2024-03-17 + +\name{simulate_data} +\alias{simulate_data} +\title{Simulate Data function} + +\usage{ +simulate_data(kernel, initial_theta, distance_matrix = "euclidean", problem_size, +seed = 0, dts, lts = 0, dimension = "2D", log_path = "", data_path = "", +observations_file = "", recovery_file = "") +} + +\arguments{ + \item{kernel}{A string specifies the kernel to use. Available kernels include: + \itemize{ + \item "BivariateMaternFlexible" + \item "BivariateMaternParsimonious" + \item "BivariateSpacetimeMaternStationary" + \item "TrivariateMaternParsimonious" + \item "UnivariateExpNonGaussian" + \item "UnivariateMaternDbeta" + \item "UnivariateMaternDdbetaBeta" + \item "UnivariateMaternDdbetaNu" + \item "UnivariateMaternDdnuNu" + \item "UnivariateMaternDdsigmaSquare" + \item "UnivariateMaternDdsigmaSquareBeta" + \item "UnivariateMaternDdsigmaSquareNu" + \item "UnivariateMaternDnu" + \item "UnivariateMaternDsigmaSquare" + \item "UnivariateMaternNonGaussian" + \item "UnivariateMaternNuggetsStationary" + \item "UnivariateMaternStationary" + \item "UnivariatePowExpStationary" + \item "UnivariateSpacetimeMaternStationary" + } + } +\item{initial_theta}{A list of initial theta parameters.} +\item{distance_matrix}{A string specifies the distance metric, either "euclidean" or "great_circle". Default is "euclidean".} +\item{problem_size}{A numeric value represents the size of the problem to simulate.} +\item{seed}{ A numeric value specifies the seed for random number generation. Default is 0.} +\item{dts}{ A numeric value represents the time step size.} +\item{lts}{ A numeric value represents the length step size. Default is 0.} +\item{dimension}{A string specifies the data dimension, either "2D" or "3D". Default is "2D".} +\item{log_path}{A string specifies the path for logging.} +\item{data_path}{A string specifies the path for data storage.} +\item{observations_file}{A string specifies the file name for observations.} +\item{recovery_file}{A string specifies the file name for recovery.} +} + +\value{ +A pointer to ExaGeoStatData object that contains the loaded data. +} + +\description{ +This function loads data into an ExaGeoStatData object using the provided configuration and computational settings. +} + +\examples{ +ncores <- 2 +ngpus <- 0 +computation <- "exact" +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) + +dimension = "2D" +problem_size <- 4 +empty_data <- new(Data, problem_size, dimension) + +dts <- 2 +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) + +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, +problem_size=problem_size, dts=dts, dimension=dimension) +} diff --git a/package.pc.in b/package.pc.in index 014e8173..86ccc3b5 100644 --- a/package.pc.in +++ b/package.pc.in @@ -8,4 +8,4 @@ Description: @CMAKE_PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ Cflags: -I${includedir} Libs: -L${libdir} -l@PROJECT_NAME@ -URL: http://github.com/ecrc/exageostat-cpp \ No newline at end of file +URL: https://github.com/ecrc/ExaGeoStatCPP \ No newline at end of file diff --git a/scripts/Benchmarking.sh b/scripts/Benchmarking.sh new file mode 100644 index 00000000..ac72b5f6 --- /dev/null +++ b/scripts/Benchmarking.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file Benchmarking.sh +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-10-10 + +# Set the output file name +output_file="40CORE_EXACT.csv" + +# Create or truncate the output file +echo "N,computation,kernel,ncores,ngpus,dts,Zmiss,maximum_likelihood,maximum_theta,mspe_value,time_generation,time_modeling,time_prediction,time_modeling_per_iter,Gflops_data_generation,Gflops_data_modeling,Gflops_data_modeling_iter,Gflops_data_mspe" > "$output_file" + +CORES=40 +GPUS=0 +MLE_ITERATIONS=1 +DTS=960 + +# Define the desired values for N +desired_N=(55225 63001 71289 79524 87616 96100 104329 112225 120081 130889 150000 200000) + +# Loop over N values +for N in "${desired_N[@]}"; do + # Repeat each iteration 10 times + for iteration in {1..10}; do + # Run the command and capture the output + command_output=$(./bin/examples/end-to-end/Example_Data_Generation_Modeling_and_Prediction --ncores=$CORES --gpus=$GPUS --computation=exact --itheta=1:0.1:0.5 --etheta=1:0.1:\? --olb=0.1:0.1:0.1 --oub=5:5:5 --dts="$DTS" --verbose=detailed --N="$N" --max_mle_iterations=$MLE_ITERATIONS --kernel=univariate_matern_stationary --tolerance=4 --Zmiss="$(($N/10))" --mspe) + # Extract the desired values from the command output + COMPUTATION=$(echo "$command_output" | awk -F "#Computation:" '{print $2}' | awk -F "," '{print $1}') + COMPUTATION=$(echo "$COMPUTATION" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + KERNEL=$(echo "$command_output" | awk -F "#Kernel:" '{print $2}' | awk -F "," '{print $1}') + KERNEL=$(echo "$KERNEL" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + logli_result=$(echo "$command_output" | awk -F "#Final Log Likelihood value: " '{print $2}' | awk -F "," '{print $1}') + logli_result=$(echo "$logli_result" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + maximum_theta=$(echo "$command_output" | awk -F "#Found Maximum Theta at: " '{print $2}' | awk -F "," '{print $1}') + maximum_theta=$(echo "$maximum_theta" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + mspe_value=$(echo "$command_output" | awk -F "#Mean Square Error MSPE: " '{print $2}' | awk -F "," '{print $1}') + mspe_value=$(echo "$mspe_value" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + time_generation=$(echo "$command_output" | awk -F "#Total Data Generation Execution Time: " '{print $2}' | awk -F "," '{print $1}') + time_generation=$(echo "$time_generation" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + time_modeling=$(echo "$command_output" | awk -F "#Total MLE Execution time: " '{print $2}' | awk -F "," '{print $1}') + time_modeling=$(echo "$time_modeling" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + time_prediction=$(echo "$command_output" | awk -F "#MSPE Prediction Execution Time: " '{print $2}' | awk -F "," '{print $1}') + time_prediction=$(echo "$time_prediction" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + time_modeling_iteration=$(echo "$command_output" | awk -F "#Average Time Modeling per Iteration: " '{print $2}' | awk -F "," '{print $1}') + time_modeling_iteration=$(echo "$time_modeling_iteration" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + flops_generation=$(echo "$command_output" | awk -F "#Total Data Generation Gflop/s: " '{print $2}' | awk -F "," '{print $1}') + flops_generation=$(echo "$flops_generation" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + flops_modeling=$(echo "$command_output" | awk -F "#Total MLE Gflop/s: " '{print $2}' | awk -F "," '{print $1}') + flops_modeling=$(echo "$flops_modeling" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + flops_modeling_iteration=$(echo "$command_output" | awk -F "#Average Flops per Iteration: " '{print $2}' | awk -F "," '{print $1}') + flops_modeling_iteration=$(echo "$flops_modeling_iteration" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + flops_mspe=$(echo "$command_output" | awk -F "#MSPE Gflop/s: " '{print $2}' | awk -F "," '{print $1}') + flops_mspe=$(echo "$flops_mspe" | tr -d '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') + + echo "$command_output" + echo "Iteration number $iteration done." + # Append the values to the output file + echo '**Results**' + echo "$N,$COMPUTATION,$KERNEL,$CORES,$GPUS,$DTS,$((N/10)),$logli_result,$maximum_theta,$mspe_value,$time_generation,$time_modeling,$time_prediction,$time_modeling_iteration,$flops_generation,$flops_modeling,$flops_modeling_iteration,$flops_mspe" + echo '' + echo "$N,$COMPUTATION,$KERNEL,$CORES,$GPUS,$DTS,$((N/10)),$logli_result,$maximum_theta,$mspe_value,$time_generation,$time_modeling,$time_prediction,$time_modeling_iteration,$flops_generation,$flops_modeling,$flops_modeling_iteration,$flops_mspe" >> "$output_file" + done +done diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94d4645f..beb9378f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,37 +1,40 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief This file contains the CMake configuration for the ExaGeoStat library. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah -# @date 2023-01-30 +# @date 2024-02-04 # Add subdirectories for configurations, data-generators, data-units, and linear-algebra-solvers. -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/configurations) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/data-generators) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/data-units) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/linear-algebra-solvers) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/api) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/helpers) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hardware) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/prediction) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/results) +add_subdirectory(api) +add_subdirectory(configurations) +add_subdirectory(data-generators) +add_subdirectory(data-loader) +add_subdirectory(data-units) +add_subdirectory(hardware) +add_subdirectory(helpers) +add_subdirectory(kernels) +add_subdirectory(linear-algebra-solvers) +add_subdirectory(prediction) +add_subdirectory(results) +add_subdirectory(runtime) + +if (USE_R) + add_subdirectory(Rcpp-adapters) +endif () # Set the name of the library to be created. set(LIB_NAME ${PROJECT_NAME}) - # Create the library with the specified source files and linking libraries. -add_library(${LIB_NAME} - STATIC - ${SOURCES} - ) +add_library(${LIB_NAME} SHARED ${SOURCES}) + target_compile_definitions(${LIB_NAME} PUBLIC ${COMPILE_DEFINITIONS}) -target_link_libraries(${LIB_NAME} PUBLIC ${LIBS}) +target_link_libraries(${LIB_NAME} ${LIBS}) # Set the version of the library. set_target_properties(${LIB_NAME} @@ -46,7 +49,8 @@ target_include_directories(${LIB_NAME} ) install(TARGETS ${LIB_NAME} EXPORT ${LIB_NAME}CoreConfig - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib + ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib ) -install(EXPORT ${LIB_NAME}CoreConfig DESTINATION lib/cmake/${PROJECT_NAME}) \ No newline at end of file + +install(EXPORT ${LIB_NAME}CoreConfig DESTINATION ${CMAKE_INSTALL_PREFIX}/EXAGEOSTATCPP/lib/cmake/) \ No newline at end of file diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 00000000..af240108 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,14 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file Makefile +# @brief Makefile for custom building ExaGeoStat +# @version 1.1.0 +# @author David Helmy +# @date 2024-01-30 + +# this file is added to let R CMD build with Custom build configuration instead of using its +# main build system +all : diff --git a/src/Rcpp-adapters/CMakeLists.txt b/src/Rcpp-adapters/CMakeLists.txt new file mode 100644 index 00000000..d161a223 --- /dev/null +++ b/src/Rcpp-adapters/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-01-29 + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/FunctionsAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/RcppExports.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/RcppModules.cpp + ${SOURCES} + PARENT_SCOPE + ) \ No newline at end of file diff --git a/src/Rcpp-adapters/FunctionsAdapter.cpp b/src/Rcpp-adapters/FunctionsAdapter.cpp new file mode 100644 index 00000000..4d5407ae --- /dev/null +++ b/src/Rcpp-adapters/FunctionsAdapter.cpp @@ -0,0 +1,375 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file FunctionsAdapter.cpp + * @brief Header file for function adapters in the ExaGeoStat software. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-29 +**/ + +#include +#include +#include + +using namespace std; +using namespace Rcpp; + +using namespace exageostat::api; +using namespace exageostat::common; +using namespace exageostat::results; +using namespace exageostat::configurations; + +namespace exageostat::adapters { + + vector> R_GetLocations(ExaGeoStatData *apData) { + + // Number of points per each dimension + int length = apData->GetLocations()->GetSize(); + bool is3D = apData->GetLocations()->GetDimension() == Dimension3D; + + double *locationXArray = apData->GetLocations()->GetLocationX(); + double *locationYArray = apData->GetLocations()->GetLocationY(); + double *locationZArray = nullptr; + if (is3D) { + locationZArray = apData->GetLocations()->GetLocationZ(); + } + + vector> locations_matrix; + for (int i = 0; i < length; ++i) { + vector point; + point.push_back(locationXArray[i]); + point.push_back(locationYArray[i]); + if (is3D) { + point.push_back(locationZArray[i]); + } + locations_matrix.push_back(point); + } + return locations_matrix; + } + + NumericVector R_GetDescZValues(ExaGeoStatData *apData, const string &aType) { + + DescriptorType descriptorType; + void *pDescriptor; + + if (aType == "chameleon" || aType == "Chameleon") { + descriptorType = CHAMELEON_DESCRIPTOR; + } else if (aType == "hicma" || aType == "Hicma" || aType == "HICMA") { +#ifdef USE_HICMA + descriptorType = HICMA_DESCRIPTOR; +#else + throw runtime_error("Please enable HiCMA to use HiCMA descriptors."); +#endif + } else { + throw domain_error("Invalid type of descriptor, please use chameleon or hicma."); + } + + // Obtain the pointer to the array of doubles + double *data = apData->GetDescriptorData()->GetDescriptorMatrix(descriptorType, DESCRIPTOR_Z); + int length = apData->GetLocations()->GetSize(); + // Create an empty NumericVector of the appropriate length + NumericVector vec(length); + // Copy data from the double array to the NumericVector + copy(data, data + length, vec.begin()); + return vec; + } + + ExaGeoStatData * + R_ExaGeoStatLoadData(const string &aKernelName, const vector &aInitialTheta, const string &aDistanceMatrix, + const int &aProblemSize, const int &aSeed, const int &aDenseTileSize, const int &aLowTileSize, + const string &aDimension, const string &aLogPath, const string &aDataPath, + const string &aRecoveryFilePath, const string &aObservationsFilePath) { + + // manually set the configurations values with the user input from R. + Configurations configurations; + configurations.SetProblemSize(aProblemSize); + configurations.CheckKernelValue(aKernelName); + configurations.ParseDistanceMetric(aDistanceMatrix); + configurations.SetSeed(aSeed); + configurations.SetDenseTileSize(aDenseTileSize); + configurations.SetLowTileSize(aLowTileSize); + configurations.SetComputation(EXACT_DENSE); + configurations.SetInitialTheta(aInitialTheta); + configurations.SetDimension(Configurations::CheckDimensionValue(aDimension)); + + if (!aLogPath.empty()) { + configurations.SetLogger(true); + configurations.SetLoggerPath(aLogPath); + } + if (!aDataPath.empty()) { + configurations.SetDataPath(aDataPath); + configurations.SetIsSynthetic(false); + } + configurations.SetRecoveryFile(aRecoveryFilePath); + configurations.SetActualObservationsFilePath(aObservationsFilePath); + + unique_ptr> data; + ExaGeoStat::ExaGeoStatLoadData(configurations, data); + + // We can safely return the raw pointer, but we need to release it from data to avoid deletion. + return data.release(); + } + + vector + R_ExaGeoStatModelData(const string &aComputation, const string &aKernelName, const string &aDistanceMatrix, + const vector &aLowerBound, const vector &aUpperBound, const int &aTolerance, + const int &aMleIterations, const int &aDenseTileSize, const int &aLowTileSize, + const string &aDimension, const int &aBand, const int &aMaxRank, SEXP apData, + Nullable aMeasurementsVector, Nullable aLocationsX, + Nullable aLocationsY, Nullable aLocationsZ) { + + Configurations configurations; + bool is_initialized = ((SEXP) apData == R_NilValue); + unique_ptr> data; + if (!is_initialized) { + auto temp_data = (ExaGeoStatData *) Rcpp::internal::as_module_object_internal(apData); + // Set the unique_ptr to manage the ExaGeoStatData pointer + data.reset(temp_data); + } else { + NumericVector z_values(aMeasurementsVector.get()); + + // Create a new ExaGeoStatData object with configurations and manage it with unique_ptr + data = make_unique>(z_values.size(), configurations.GetDimension()); + } + double *pMeasurementsVectorPtr = GetDataFromArguments(aMeasurementsVector, aLocationsX, aLocationsY, + aLocationsZ, data, configurations, aKernelName, + aDistanceMatrix, aDenseTileSize, aLowTileSize, aDimension, + Configurations::CheckComputationValue(aComputation)); + + configurations.SetLowerBounds(aLowerBound); + configurations.SetUpperBounds(aUpperBound); + configurations.SetMaxMleIterations(aMleIterations); + configurations.SetTolerance(aTolerance); + configurations.SetBand(aBand); + configurations.SetMaxRank(aMaxRank); + + ExaGeoStat::ExaGeoStatDataModeling(configurations, data, pMeasurementsVectorPtr); + // Take back ownership, to avoid deleting apData when the unique_ptr goes out of scope. + apData = (SEXP) data.release(); + return configurations.GetStartingTheta(); + } + + vector R_ExaGeoStatPredictData(const string &aKernelName, const string &aDistanceMatrix, + const vector &aEstimatedTheta, const int &aDenseTileSize, + const int &aLowTileSize, const string &aDimension, + vector > &aTrainData, vector > &aTestData) { + + Configurations configurations; + configurations.SetIsMSPE(TRUE); + configurations.SetEstimatedTheta(aEstimatedTheta); + vector empty_vector; + PredictionSetupHelper(configurations, aKernelName, aDistanceMatrix, aDenseTileSize, aLowTileSize, aDimension, + aTrainData, aTestData, aEstimatedTheta, empty_vector); + return Results::GetInstance()->GetPredictedMissedValues(); + } + + vector R_ExaGeoStatMLOE_MMOM(const string &aKernelName, const string &aDistanceMatrix, + const vector &aEstimatedTheta, const vector &aTrueTheta, + const int &aDenseTileSize, const int &aLowTileSize, const string &aDimension, + vector > &aTrainData, vector > &aTestData) { + + Configurations configurations; + configurations.SetEstimatedTheta(aEstimatedTheta); + configurations.SetInitialTheta(aTrueTheta); + configurations.SetIsMLOEMMOM(TRUE); + + vector empty_vector; + PredictionSetupHelper(configurations, aKernelName, aDistanceMatrix, aDenseTileSize, aLowTileSize, aDimension, + aTrainData, aTestData, aEstimatedTheta, empty_vector); + + vector mloe_mmom_values; + mloe_mmom_values.push_back(Results::GetInstance()->GetMLOE()); + mloe_mmom_values.push_back(Results::GetInstance()->GetMMOM()); + return mloe_mmom_values; + } + + vector + R_ExaGeoStatFisher(const string &aKernelName, const string &aDistanceMatrix, const vector &aEstimatedTheta, + const int &aDenseTileSize, const int &aLowTileSize, const string &aDimension, + vector > &aTrainData, vector > &aTestData) { + + Configurations configurations; + configurations.SetIsFisher(TRUE); + + vector empty_vector; + PredictionSetupHelper(configurations, aKernelName, aDistanceMatrix, aDenseTileSize, aLowTileSize, aDimension, + aTrainData, aTestData, aEstimatedTheta, empty_vector); + + return Results::GetInstance()->GetFisherMatrix(); + } + + vector + R_ExaGeoStatIDW(const string &aKernelName, const string &aDistanceMatrix, const vector &aEstimatedTheta, + const int &aDenseTileSize, const int &aLowTileSize, const string &aDimension, + vector > &aTrainData, vector > &aTestData, + vector &aTestMeasurementsValues) { + + Configurations configurations; + configurations.SetIsIDW(TRUE); + + PredictionSetupHelper(configurations, aKernelName, aDistanceMatrix, aDenseTileSize, aLowTileSize, aDimension, + aTrainData, aTestData, aEstimatedTheta, aTestMeasurementsValues); + + return Results::GetInstance()->GetIDWError(); + } + + double *GetDataFromArguments(Nullable aMeasurementsVector, Nullable aLocationsX, + Nullable aLocationsY, Nullable aLocationsZ, + unique_ptr > &aData, Configurations &aConfigurations, + const string &aKernelName, const string &aDistanceMatrix, const int &aDenseTileSize, + const int &aLowTileSize, const string &aDimension, const Computation &aComputation) { + + double *pMeasurementsVectorPtr = nullptr; + if (aMeasurementsVector == nullptr || aMeasurementsVector.isNull()) { + // This was the only way to pass C++ tests, if we checked for aMeasurementsVector != nullptr a seg fault occurs + } else { + NumericVector mat(aMeasurementsVector.get()); + pMeasurementsVectorPtr = &mat[0]; // Get the raw pointer to the matrix data + + if (!aLocationsX.isNull()) { + double *pLocationsXPtr; + NumericVector mat_location(aLocationsX.get()); + pLocationsXPtr = &mat_location[0]; // Get the raw pointer to the matrix data + // Check for overflow + if (mat_location.size() > numeric_limits::max()) { + // Handle the overflow by logging an error + throw runtime_error("Warning: Size exceeds the limit of int type for Locations X."); + } else { + // Safe to convert + int size = static_cast(mat_location.size()); + aData->GetLocations()->SetLocationX(*pLocationsXPtr, size); + } + } + + if (aLocationsY.isNotNull()) { + double *pLocationsYPtr; + NumericVector mat_location(aLocationsY.get()); + pLocationsYPtr = &mat_location[0]; // Get the raw pointer to the matrix data + // Check for overflow + if (mat_location.size() > numeric_limits::max()) { + // Handle the overflow by logging an error + throw runtime_error("Warning: Size exceeds the limit of int type for Locations Y."); + } else { + // Safe to convert + int size = static_cast(mat_location.size()); + aData->GetLocations()->SetLocationY(*pLocationsYPtr, size); + } + } + + if (aLocationsZ.isNotNull()) { + double *pLocationsZPtr; + NumericVector mat_location(aLocationsZ.get()); + pLocationsZPtr = &mat_location[0]; // Get the raw pointer to the matrix data + // Check for overflow + if (mat_location.size() > numeric_limits::max()) { + // Handle the overflow by logging an error + throw runtime_error("Warning: Size exceeds the limit of int type for Locations Z."); + } else { + // Safe to convert + int size = static_cast(mat_location.size()); + aData->GetLocations()->SetLocationZ(*pLocationsZPtr, size); + } + } + } + // Set common configurations. + aConfigurations.SetComputation(aComputation); + aConfigurations.CheckKernelValue(aKernelName); + aConfigurations.ParseDistanceMetric(aDistanceMatrix); + aConfigurations.SetDenseTileSize(aDenseTileSize); + aConfigurations.SetLowTileSize(aLowTileSize); + aConfigurations.SetDimension(Configurations::CheckDimensionValue(aDimension)); + aConfigurations.SetProblemSize(aData->GetLocations()->GetSize()); + return pMeasurementsVectorPtr; + } + + void ValidateDataDimensions(const vector > &aData, const string &aDataType) { + if (aData.empty() || aData.front().empty()) { + throw runtime_error("No " + aDataType + " data provided."); + } + + size_t expectedSize = aData.front().size(); + for (const auto &vec: aData) { + if (vec.size() != expectedSize) { + throw runtime_error("Inconsistent dimensions in " + aDataType + " data."); + } + } + } + + void + PredictionSetupHelper(Configurations &aConfigurations, const string &aKernelName, const string &aDistanceMatrix, + const int &aDenseTileSize, const int &aLowTileSize, const string &aDimension, + vector > &aTrainData, vector > &aTestData, + const vector &aEstimatedTheta, const vector &aTestMeasurementsValues) { + + aConfigurations.SetComputation(EXACT_DENSE); + + ValidateDataDimensions(aTrainData, "train"); + ValidateDataDimensions(aTestData, "test"); + + size_t potential_train_data_size = aTrainData[0].size(); + if (potential_train_data_size > static_cast(numeric_limits::max())) { + throw runtime_error("Train data size exceeds the maximum size for int type."); + } + int train_data_size = static_cast(potential_train_data_size); + + size_t potential_test_data_size = aTestData[0].size(); + if (potential_test_data_size > static_cast(numeric_limits::max())) { + throw runtime_error("Test data size exceeds the maximum size for int type."); + } + int test_data_size = static_cast(potential_test_data_size); + + auto data = make_unique>(train_data_size, aConfigurations.GetDimension()); + dataunits::Locations train_locations(train_data_size, aConfigurations.GetDimension()); + dataunits::Locations test_locations(test_data_size, aConfigurations.GetDimension()); + + // Allocate memory for z_values to hold elements from both sources + auto *z_values = new double[aTrainData.back().size() + aTestMeasurementsValues.size()]; + + for (int i = 0; i < train_data_size; i++) { + train_locations.SetLocationX(*aTrainData[0].data(), train_data_size); + train_locations.SetLocationY(*aTrainData[1].data(), train_data_size); + data->GetLocations()->SetLocationX(*aTrainData[0].data(), train_data_size); + data->GetLocations()->SetLocationY(*aTrainData[1].data(), train_data_size); + if (aTrainData.size() > 3) { + train_locations.SetLocationZ(*aTrainData[2].data(), train_data_size); + data->GetLocations()->SetLocationZ(*aTrainData[2].data(), train_data_size); + } + } + memcpy(z_values, aTrainData.back().data(), aTrainData.back().size() * sizeof(double)); + // Calculate the starting position for the next part of the data in z_values + auto *destination = z_values + aTrainData.back().size(); + // Copy data from aTestMeasurementsValues to the next part of z_values, after the previously copied data + memcpy(destination, aTestMeasurementsValues.data(), aTestMeasurementsValues.size() * sizeof(double)); + + for (int i = 0; i < test_data_size; i++) { + test_locations.SetLocationX(*aTestData[0].data(), test_data_size); + test_locations.SetLocationY(*aTestData[1].data(), test_data_size); + if (aTestData.size() > 2) { + test_locations.SetLocationZ(*aTestData[2].data(), test_data_size); + } + } + + // Set common configurations. + aConfigurations.CheckKernelValue(aKernelName); + aConfigurations.ParseDistanceMetric(aDistanceMatrix); + aConfigurations.SetDenseTileSize(aDenseTileSize); + aConfigurations.SetLowTileSize(aLowTileSize); + aConfigurations.SetDimension(Configurations::CheckDimensionValue(aDimension)); + aConfigurations.SetProblemSize(data->GetLocations()->GetSize()); + aConfigurations.SetEstimatedTheta(aEstimatedTheta); + + // Temporarily release ownership to pass to the function. + ExaGeoStatData *tempData = data.release(); + ExaGeoStat::ExaGeoStatPrediction(aConfigurations, + reinterpret_cast> &>(tempData), + z_values, &train_locations, &test_locations); + // Take back ownership + data.reset(tempData); + + delete[] z_values; + } +} \ No newline at end of file diff --git a/src/Rcpp-adapters/RcppExports.cpp b/src/Rcpp-adapters/RcppExports.cpp new file mode 100644 index 00000000..2b1fbbab --- /dev/null +++ b/src/Rcpp-adapters/RcppExports.cpp @@ -0,0 +1,45 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file RcppExports.cpp + * @brief Rcpp export definitions for ExaGeoStatCPP module. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author David Helmy + * @date 2023-01-20 +**/ + +#include + +using namespace Rcpp; + +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + +/** + * @brief Rcpp module boot function for ExaGeoStatCPP. + * @return A SEXP represents the Rcpp module. + */ +RcppExport SEXP _rcpp_module_boot_ExaGeoStatCPP(); + +/** + * @brief Array of R function call entries. + */ +static const R_CallMethodDef CallEntries[] = { + {"_rcpp_module_boot_ExaGeoStatCPP", (DL_FUNC) &_rcpp_module_boot_ExaGeoStatCPP, 0}, + {nullptr, nullptr, 0} +}; + +/** + * @brief R initialization function for ExaGeoStatCPP module. + * @param dll The DllInfo structure. + */ +RcppExport void R_init_ExaGeoStatCPP(DllInfo *dll) { + R_registerRoutines(dll, nullptr, CallEntries, nullptr, nullptr); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/src/Rcpp-adapters/RcppModules.cpp b/src/Rcpp-adapters/RcppModules.cpp new file mode 100644 index 00000000..b56b3154 --- /dev/null +++ b/src/Rcpp-adapters/RcppModules.cpp @@ -0,0 +1,73 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file RcppModules.cpp + * @brief Rcpp module definitions for ExaGeoStatCPP. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author David Helmy + * @date 2023-01-20 +**/ + +#include + +#include +#include +#include + +/** Expose C++ class to R to be able to use Wrap and As + * Allows C++ to Send and Receive Class object from R + **/ +RCPP_EXPOSED_CLASS(ExaGeoStatHardware) +RCPP_EXPOSED_CLASS_NODECL(ExaGeoStatData) + +/** Expose C++ Object With the Given functions **/ +RCPP_MODULE(ExaGeoStatCPP) { + + /** ExaGeoStatCPP Class **/ + using namespace Rcpp; + + /** Hardware Class **/ + class_("Hardware") + .constructor() + .method("finalize_hardware", &ExaGeoStatHardware::FinalizeHardware, "Manually finalize the hardware"); + + /** Data Class **/ + class_>("Data") + .constructor(); + + function("simulate_data", &exageostat::adapters::R_ExaGeoStatLoadData, + List::create(_["kernel"], _["initial_theta"], _["distance_matrix"] = "euclidean", _["problem_size"], + _["seed"] = 0, _["dts"], _["lts"] = 0, _["dimension"] = "2D", _["log_path"] = "", + _["data_path"] = "", _["observations_file"] = "", _["recovery_file"] = "")); + + function("model_data", &exageostat::adapters::R_ExaGeoStatModelData, + List::create(_["computation"] = "exact", _["kernel"], _["distance_matrix"] = "euclidean", _["lb"], _["ub"], + _["tol"] = 4, _["mle_itr"], _["dts"], _["lts"] = 0, _["dimension"] = "2D", _["band"] = 0, + _["max_rank"] = 500, _["data"] = R_NilValue, _["matrix"] = R_NilValue, _["x"] = R_NilValue, + _["y"] = R_NilValue, _["z"] = R_NilValue)); + + function("predict_data", &exageostat::adapters::R_ExaGeoStatPredictData, + List::create(_["kernel"], _["distance_matrix"] = "euclidean", _["estimated_theta"], _["dts"], _["lts"] = 0, + _["dimension"] = "2D", _["train_data"], _["test_data"])); + + function("mloe_mmom", &exageostat::adapters::R_ExaGeoStatMLOE_MMOM, + List::create(_["kernel"], _["distance_matrix"] = "euclidean", _["estimated_theta"], _["true_theta"], + _["dts"], _["lts"] = 0, _["dimension"] = "2D", _["train_data"], _["test_data"])); + + function("fisher", &exageostat::adapters::R_ExaGeoStatFisher, + List::create(_["kernel"], _["distance_matrix"] = "euclidean", _["estimated_theta"], _["dts"], _["lts"] = 0, + _["dimension"] = "2D", _["train_data"], _["test_data"])); + + function("idw", &exageostat::adapters::R_ExaGeoStatIDW, + List::create(_["kernel"], _["distance_matrix"] = "euclidean", _["estimated_theta"], _["dts"], _["lts"] = 0, + _["dimension"] = "2D", _["train_data"], _["test_data"], _["test_measurements"])); + + function("get_locations", &exageostat::adapters::R_GetLocations, List::create(_["data"])); + + function("get_Z_measurement_vector", &exageostat::adapters::R_GetDescZValues, List::create(_["data"], _["type"])); + +} diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 9a434188..223513e0 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @brief CMake build script for the operators library, which includes the OperatorMethods base class and the OperatorFactory class for creating operators of different types. # @author Mahmoud ElKarargy # @date 2023-05-30 diff --git a/src/api/ExaGeoStat.cpp b/src/api/ExaGeoStat.cpp index 11cc407e..830aa481 100644 --- a/src/api/ExaGeoStat.cpp +++ b/src/api/ExaGeoStat.cpp @@ -1,14 +1,14 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStat.cpp * @brief High-Level Wrapper class containing the static API for ExaGeoStat operations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-05-30 + * @date 2024-02-04 **/ #include @@ -20,52 +20,56 @@ using namespace std; using namespace nlopt; using namespace exageostat::api; -using namespace exageostat::configurations; using namespace exageostat::generators; using namespace exageostat::dataunits; -using namespace exageostat::hardware; -using namespace exageostat::prediction; +using namespace exageostat::configurations; template -void ExaGeoStat::ExaGeoStatLoadData(const ExaGeoStatHardware &aHardware, - configurations::Configurations &aConfigurations, - dataunits::ExaGeoStatData &aData) { +void ExaGeoStat::ExaGeoStatLoadData(Configurations &aConfigurations, std::unique_ptr> &aData) { + + aConfigurations.PrintSummary(); + LOGGER("** ExaGeoStat data generation/loading **") // Register and create a kernel object - kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName()); + kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName(), + aConfigurations.GetTimeSlot()); // Add the data generation arguments. aConfigurations.InitializeDataGenerationArguments(); // Create a unique pointer to a DataGenerator object - //hehe unique_ptr> data_generator = DataGenerator::CreateGenerator(aConfigurations); - aData = *data_generator->CreateData(aConfigurations, aHardware, *pKernel); + aData = data_generator->CreateData(aConfigurations, *pKernel); delete pKernel; + LOGGER("\t*Data generation/loading finished*") } template -T ExaGeoStat::ExaGeoStatDataModeling(const ExaGeoStatHardware &aHardware, Configurations &aConfigurations, - ExaGeoStatData &aData, T *apMeasurementsMatrix) { +T ExaGeoStat::ExaGeoStatDataModeling(Configurations &aConfigurations, std::unique_ptr> &aData, + T *apMeasurementsMatrix) { + aConfigurations.PrintSummary(); + LOGGER("** ExaGeoStat data Modeling **") // Register and create a kernel object - kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName()); + kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName(), + aConfigurations.GetTimeSlot()); // Add the data modeling arguments. aConfigurations.InitializeDataModelingArguments(); int parameters_number = pKernel->GetParametersNumbers(); int max_number_of_iterations = aConfigurations.GetMaxMleIterations(); // Setting struct of data to pass to the modeling. - auto modeling_data = new mModelingData(aData, aConfigurations, aHardware, *apMeasurementsMatrix, *pKernel); + auto modeling_data = new mModelingData(aData, aConfigurations, *apMeasurementsMatrix, *pKernel); // Create nlopt double opt_f; opt optimizing_function(nlopt::LN_BOBYQA, parameters_number); // Initialize problem's bound. optimizing_function.set_lower_bounds(aConfigurations.GetLowerBounds()); optimizing_function.set_upper_bounds(aConfigurations.GetUpperBounds()); - optimizing_function.set_ftol_abs(pow(10, -1 * aConfigurations.GetTolerance())); + optimizing_function.set_ftol_abs(aConfigurations.GetTolerance()); // Set max iterations value. optimizing_function.set_maxeval(max_number_of_iterations); optimizing_function.set_max_objective(ExaGeoStatMLETileAPI, (void *) modeling_data); // Optimize mle using nlopt. optimizing_function.optimize(aConfigurations.GetStartingTheta(), opt_f); + aConfigurations.SetEstimatedTheta(aConfigurations.GetStartingTheta()); delete pKernel; delete modeling_data; @@ -75,28 +79,32 @@ T ExaGeoStat::ExaGeoStatDataModeling(const ExaGeoStatHardware &aHardware, Con template double ExaGeoStat::ExaGeoStatMLETileAPI(const std::vector &aTheta, std::vector &aGrad, void *apInfo) { + auto config = ((mModelingData *) apInfo)->mpConfiguration; auto data = ((mModelingData *) apInfo)->mpData; - auto hardware = ((mModelingData *) apInfo)->mpHardware; auto measurements = ((mModelingData *) apInfo)->mpMeasurementsMatrix; auto kernel = ((mModelingData *) apInfo)->mpKernel; // We do Date Modeling with any computation. auto linear_algebra_solver = linearAlgebra::LinearAlgebraFactory::CreateLinearAlgebraSolver( config->GetComputation()); - return linear_algebra_solver->ExaGeoStatMLETile(*hardware, *data, *config, aTheta.data(), measurements, *kernel); + return linear_algebra_solver->ExaGeoStatMLETile(*data, *config, aTheta.data(), measurements, *kernel); } template -void ExaGeoStat::ExaGeoStatPrediction(const ExaGeoStatHardware &aHardware, Configurations &aConfigurations, - ExaGeoStatData &aData, T *apMeasurementsMatrix) { +void ExaGeoStat::ExaGeoStatPrediction(Configurations &aConfigurations, std::unique_ptr> &aData, + T *apMeasurementsMatrix, Locations *apTrainLocations, + Locations *apTestLocations) { - Prediction predictor; + aConfigurations.PrintSummary(); + LOGGER("** ExaGeoStat data Prediction **") // Register and create a kernel object - kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName()); + kernels::Kernel *pKernel = plugins::PluginRegistry>::Create(aConfigurations.GetKernelName(), + aConfigurations.GetTimeSlot()); // Add the data prediction arguments. aConfigurations.InitializeDataPredictionArguments(); - predictor.PredictMissingData(aHardware, aData, aConfigurations, apMeasurementsMatrix, *pKernel); + prediction::Prediction::PredictMissingData(aData, aConfigurations, apMeasurementsMatrix, *pKernel, + apTrainLocations, apTestLocations); delete pKernel; } \ No newline at end of file diff --git a/src/configurations/CMakeLists.txt b/src/configurations/CMakeLists.txt index d0bee479..3575e1a3 100644 --- a/src/configurations/CMakeLists.txt +++ b/src/configurations/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief This file contains the CMake configuration for the data-units directory. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-01-31 diff --git a/src/configurations/Configurations.cpp b/src/configurations/Configurations.cpp index f7a0ada3..884f44f2 100644 --- a/src/configurations/Configurations.cpp +++ b/src/configurations/Configurations.cpp @@ -1,20 +1,20 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Configurations.cpp * @brief This file defines the Configurations class which stores the configuration parameters for ExaGeoStat. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-01-31 + * @date 2024-02-04 **/ #include #include -#include +#include using namespace std; @@ -23,11 +23,13 @@ using namespace exageostat::common; Verbose Configurations::mVerbosity = Verbose::STANDARD_MODE; bool Configurations::mIsThetaInit = false; +bool Configurations::mHeapAllocated = false; +bool Configurations::mFirstInit = false; Configurations::Configurations() { // Set default values for arguments! - SetComputation(common::EXACT_DENSE); + SetComputation(EXACT_DENSE); SetCoresNumber(1); SetGPUsNumbers(0); SetPGrid(1); @@ -35,50 +37,49 @@ Configurations::Configurations() { SetMaxRank(1); SetIsOOC(false); SetKernelName(""); - SetDimension(common::Dimension2D); + SetDimension(Dimension2D); SetTimeSlot(1); SetProblemSize(0); SetDenseTileSize(0); -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA SetLowTileSize(0); #endif SetBand(0); SetLoggerPath(""); SetIsSynthetic(true); - SetIsCSV(false); vector theta; SetInitialTheta(theta); SetLowerBounds(theta); SetUpperBounds(theta); SetEstimatedTheta(theta); - SetP(1); SetSeed(0); SetLogger(false); SetUnknownObservationsNb(0); - SetMeanSquareError(0.0); SetApproximationMode(1); SetActualObservationsFilePath(""); SetRecoveryFile(""); - SetPrecision(common::DOUBLE); + SetPrecision(DOUBLE); SetIsMSPE(false); SetIsFisher(false); SetIsIDW(false); SetIsMLOEMMOM(false); SetDataPath(""); - SetDistanceMetric(common::EUCLIDEAN_DISTANCE); + SetDistanceMetric(EUCLIDEAN_DISTANCE); SetAccuracy(0); + SetIsNonGaussian(false); + mIsThetaInit = false; } - -void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { +void Configurations::InitializeArguments(const int &aArgC, char **apArgV, const bool &aEnableR) { this->mArgC = aArgC; this->mpArgV = apArgV; + mHeapAllocated = aEnableR; + // Get the example name string example_name = apArgV[0]; // Remove the './' example_name.erase(0, 2); - LOGGER("Running " + example_name) string argument; string argument_name; string argument_value; @@ -103,6 +104,9 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { SetPGrid(CheckNumericalValue(argument_value)); } else if (argument_name == "--Q" || argument_name == "--q") { SetQGrid(CheckNumericalValue(argument_value)); + } else if (argument_name == "--Dimension" || argument_name == "--dimension" || argument_name == "--dim" || + argument_name == "--Dim") { + SetDimension(CheckDimensionValue(argument_value)); } else if (argument_name == "--TimeSlot" || argument_name == "--timeslot" || argument_name == "--time_slot") { SetTimeSlot(CheckNumericalValue(argument_value)); @@ -118,6 +122,8 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { SetGPUsNumbers(CheckNumericalValue(argument_value)); } else if (argument_name == "--DTS" || argument_name == "--dts" || argument_name == "--Dts") { SetDenseTileSize(CheckNumericalValue(argument_value)); + } else if (argument_name == "--LTS" || argument_name == "--lts" || argument_name == "--Lts") { + SetLowTileSize(CheckNumericalValue(argument_value)); } else if (argument_name == "--maxRank" || argument_name == "--maxrank" || argument_name == "--max_rank") { SetMaxRank(CheckNumericalValue(argument_value)); } else if (argument_name == "--initial_theta" || argument_name == "--itheta" || @@ -142,19 +148,20 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { SetSeed(CheckNumericalValue(argument_value)); } else if (argument_name == "--verbose" || argument_name == "--Verbose") { ParseVerbose(argument_value); + } else if (argument_name == "--distance_metric" || argument_name == "--distanceMetric") { + ParseDistanceMetric(argument_value); } else if (argument_name == "--logpath" || argument_name == "--log_path" || argument_name == "--logPath") { SetLoggerPath(argument_value); } else { - if (!(argument_name == "--Dimension" || argument_name == "--dimension" || argument_name == "--dim" || - argument_name == "--Dim" || argument_name == "--ZmissNumber" || argument_name == "--Zmiss" || + if (!(argument_name == "--ZmissNumber" || argument_name == "--Zmiss" || argument_name == "--ZMiss" || argument_name == "--predict" || argument_name == "--Predict" || argument_name == "--iterations" || argument_name == "--Iterations" || argument_name == "--max_mle_iterations" || - argument_name == "--maxMleIterations" || argument_name == "--tolerance" || + argument_name == "--maxMleIterations" || argument_name == "--opt_iters" || + argument_name == "--tolerance" || argument_name == "--opt_tol" || argument_name == "--distanceMetric" || argument_name == "--distance_metric" || argument_name == "--log_file_name" || argument_name == "--logFileName" || argument_name == "--Band" || argument_name == "--band" || - argument_name == "--LTS" || argument_name == "--lts" || argument_name == "--Lts" || argument_name == "--DataPath" || argument_name == "--dataPath" || argument_name == "--data_path" || argument_name == "--acc" || argument_name == "--Acc")) { @@ -167,7 +174,7 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { if (argument_name == "--help") { PrintUsage(); } - if (argument_name == "--OOC") { + if (argument_name == "--OOC" || argument_name == "--ooc") { SetIsOOC(true); } else if (argument_name == "--ApproximationMode" || argument_name == "--approximationmode" || argument_name == "--approximation_mode") { @@ -177,7 +184,7 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { } else { if (!(argument_name == "--mspe" || argument_name == "--MSPE" || argument_name == "--idw" || argument_name == "--IDW" || - argument_name == "--mloe-mmom" || argument_name == "--mloe-mmom" || argument_name == "--mloe_mmom" || + argument_name == "--mloe-mmom" || argument_name == "--mloe_mmom" || argument_name == "--fisher" || argument_name == "--Fisher")) { LOGGER("!! " << argument_name << " !!") throw invalid_argument( @@ -199,19 +206,27 @@ void Configurations::InitializeArguments(const int &aArgC, char **apArgV) { throw domain_error("You need to set the Kernel, before starting"); } - if (GetLogger()) { - //initlog - InitLog(); + size_t found = GetKernelName().find("NonGaussian"); + // Check if the substring was found + if (found != std::string::npos) { + SetIsNonGaussian(true); } - this->PrintSummary(); } void Configurations::InitializeAllTheta() { if (!mIsThetaInit) { + int parameters_number = kernels::KernelsConfigurations::GetParametersNumberKernelMap()[this->GetKernelName()]; InitTheta(GetInitialTheta(), parameters_number); SetInitialTheta(GetInitialTheta()); + + + if (this->GetIsNonGaussian()) { + GetInitialTheta()[GetInitialTheta().size() - 1] = 0.2; + GetInitialTheta()[GetInitialTheta().size() - 2] = 0.2; + } + InitTheta(GetLowerBounds(), parameters_number); SetLowerBounds(GetLowerBounds()); InitTheta(GetUpperBounds(), parameters_number); @@ -250,19 +265,15 @@ void Configurations::InitializeDataGenerationArguments() { argument_value = argument.substr(equal_sign_Idx + 1); // Check the argument name and set the corresponding value - if (argument_name == "--Dimension" || argument_name == "--dimension" || argument_name == "--dim" || - argument_name == "--Dim") { - SetDimension(CheckDimensionValue(argument_value)); - } else if (argument_name == "--DataPath" || argument_name == "--dataPath" || - argument_name == "--data_path") { + if (argument_name == "--DataPath" || argument_name == "--dataPath" || + argument_name == "--data_path") { SetDataPath(argument_value); SetIsSynthetic(false); - SetIsCSV(true); } } } if (GetDimension() != DimensionST) { - if (GetTimeSlot() > 1) { + if (GetTimeSlot() != 1) { throw std::runtime_error("Time Slot can only be greater than 1 if the dimensions are set to SpaceTime."); } } else if (GetTimeSlot() < 1) { @@ -289,16 +300,13 @@ void Configurations::InitializeDataModelingArguments() { argument_value = argument.substr(equal_sign_Idx + 1); // Check the argument name and set the corresponding value - if (argument_name == "--distance_metric" || argument_name == "--distanceMetric") { - ParseDistanceMetric(argument_value); - } else if (argument_name == "--max_mle_iterations" || argument_name == "--maxMleIterations") { + if (argument_name == "--max_mle_iterations" || argument_name == "--maxMleIterations" || + argument_name == "--opt_iters") { SetMaxMleIterations(CheckNumericalValue(argument_value)); - } else if (argument_name == "--tolerance") { + } else if (argument_name == "--tolerance" || argument_name == "--opt_tol") { SetTolerance(CheckNumericalValue(argument_value)); } else if (argument_name == "--Band" || argument_name == "--band") { SetBand(CheckNumericalValue(argument_value)); - } else if (argument_name == "--LTS" || argument_name == "--lts" || argument_name == "--Lts") { - SetLowTileSize(CheckNumericalValue(argument_value)); } else if (argument_name == "--acc" || argument_name == "--Acc") { SetAccuracy(CheckNumericalValue(argument_value)); } else if (argument_name == "--log_file_name" || argument_name == "--logFileName") { @@ -316,7 +324,7 @@ void Configurations::InitializeDataModelingArguments() { } } if (GetComputation() == TILE_LOW_RANK) { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA if (GetLowTileSize() == 0) { throw domain_error("You need to set the Low tile size, before starting"); } @@ -352,21 +360,21 @@ void Configurations::InitializeDataPredictionArguments() { argument_name = argument.substr(0, equal_sign_Idx); if (argument_name == "--mspe" || argument_name == "--MSPE") { - if (GetUnknownObservationsNb() <= 0) { + if (GetUnknownObservationsNb() <= 1) { throw domain_error( - "You need to set ZMiss number, as the number of missing values should be positive value"); + "You need to set ZMiss number, as the number of missing values should be bigger than one"); } SetIsMSPE(true); } else if (argument_name == "--idw" || argument_name == "--IDW") { - if (GetUnknownObservationsNb() <= 0) { + if (GetUnknownObservationsNb() <= 1) { throw domain_error( - "You need to set ZMiss number, as the number of missing values should be positive value"); + "You need to set ZMiss number, as the number of missing values should be bigger than one"); } SetIsIDW(true); } else if (argument_name == "--mloe-mmom" || argument_name == "--MLOE_MMOM" || argument_name == "--mloe_mmom") { - if (GetUnknownObservationsNb() <= 0) { + if (GetUnknownObservationsNb() <= 1) { throw domain_error( - "You need to set ZMiss number, as the number of missing values should be positive value"); + "You need to set ZMiss number, as the number of missing values should be bigger than one"); } SetIsMLOEMMOM(true); } else if (argument_name == "--Fisher" || argument_name == "--fisher") { @@ -390,7 +398,7 @@ void Configurations::PrintUsage() { LOGGER("--gpus=value : Used to set the number of GPUs.") LOGGER("--dts=value : Used to set the Dense Tile size.") LOGGER("--lts=value : Used to set the Low Tile size.") - LOGGER("--diag_thick=value : Used to set the Tile diagonal thickness.") + LOGGER("--band=value : Used to set the Tile diagonal thickness.") LOGGER("--Zmiss=value : Used to set number of unknown observation to be predicted.") LOGGER("--observations_file=PATH/TO/File : Used to pass the observations file path.") LOGGER("--max_rank=value : Used to the max rank value.") @@ -490,24 +498,23 @@ void Configurations::CheckKernelValue(const string &aKernel) { // Check if the kernel name exists in the availableKernels set. if (availableKernels.count(aKernel) <= 0) { throw range_error("Invalid value for Kernel. Please check manual."); - } else { - // Check if the string is already in CamelCase format - if (IsCamelCase(aKernel)) { - this->SetKernelName(aKernel); - return; - } - string str = aKernel; - // Replace underscores with spaces and split the string into words - std::replace(str.begin(), str.end(), '_', ' '); - std::istringstream iss(str); - std::string word, result; - while (iss >> word) { - // Capitalize the first letter of each word and append it to the result - word[0] = static_cast(toupper(word[0])); - result += word; - } - this->SetKernelName(result); } + // Check if the string is already in CamelCase format + if (IsCamelCase(aKernel)) { + this->SetKernelName(aKernel); + return; + } + string str = aKernel; + // Replace underscores with spaces and split the string into words + std::replace(str.begin(), str.end(), '_', ' '); + std::istringstream iss(str); + std::string word, result; + while (iss >> word) { + // Capitalize the first letter of each word and append it to the result + word[0] = static_cast(toupper(word[0])); + result += word; + } + this->SetKernelName(result); } bool Configurations::IsCamelCase(const std::string &aString) { @@ -589,25 +596,15 @@ int Configurations::CheckUnknownObservationsValue(const string &aValue) { } void Configurations::ParseDistanceMetric(const std::string &aDistanceMetric) { - if (aDistanceMetric == "eg" || aDistanceMetric == "EG") { + if (aDistanceMetric == "eg" || aDistanceMetric == "EG" || aDistanceMetric == "euclidean") { SetDistanceMetric(EUCLIDEAN_DISTANCE); - } else if (aDistanceMetric == "gcd" || aDistanceMetric == "GCD") { + } else if (aDistanceMetric == "gcd" || aDistanceMetric == "GCD" || aDistanceMetric == "great_circle") { SetDistanceMetric(GREAT_CIRCLE_DISTANCE); } else { throw range_error("Invalid value. Please use eg or gcd values only."); } } -void Configurations::InitLog() { - try { - SetFileLogPath(fopen(GetFileLogName().c_str(), "w+")); - } - catch (std::exception &e) { - SetFileLogPath(fopen("log_file", "w+")); - } - fprintf(GetFileLogPath(), "\t\tlog file is generated by ExaGeoStat application\n"); - fprintf(GetFileLogPath(), "\t\t============================================\n"); -} void Configurations::InitTheta(vector &aTheta, const int &size) { @@ -628,13 +625,14 @@ void Configurations::PrintSummary() { Verbose temp = this->GetVerbosity(); mVerbosity = STANDARD_MODE; - if (!mIsPrinted) { + + if (!mFirstInit) { LOGGER("********************SUMMARY**********************") if (this->GetIsSynthetic()) { - LOGGER("#Synthetic Dataset") + LOGGER("#Synthetic Data generation") } else { - LOGGER("#Real Dataset") + LOGGER("#Real Data loader") } LOGGER("#Number of Locations: " << this->GetProblemSize()) LOGGER("#Threads per node: " << this->GetCoresNumber()) @@ -647,7 +645,7 @@ void Configurations::PrintSummary() { LOGGER("#Precision: Single/Double") } LOGGER("#Dense Tile Size: " << this->GetDenseTileSize()) -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA LOGGER("#Low Tile Size: " << this->GetLowTileSize()) #endif if (this->GetComputation() == TILE_LOW_RANK) { @@ -657,16 +655,46 @@ void Configurations::PrintSummary() { } else if (this->GetComputation() == DIAGONAL_APPROX) { LOGGER("#Computation: Diagonal Approx") } + + if (this->GetDimension() == Dimension2D) { + LOGGER("#Dimension: 2D") + } else if (this->GetDimension() == Dimension3D) { + LOGGER("#Dimension: 3D") + } else if (this->GetDimension() == DimensionST) { + LOGGER("#Dimension: ST") + } LOGGER("#Kernel: " << this->GetKernelName()) + if (this->GetDistanceMetric() == EUCLIDEAN_DISTANCE) { + LOGGER("#Distance Metric: Euclidean distance") + } else { + LOGGER("#Distance Metric: Great Circle Distance") + } LOGGER("#p: " << this->GetPGrid() << "\t\t #q: " << this->GetQGrid()) + if (this->GetIsOOC()) { + LOGGER("#Out Of Core (OOC) technology is enabled") + } LOGGER("*************************************************") - mIsPrinted = true; + mVerbosity = temp; + mFirstInit = true; } - mVerbosity = temp; } -bool Configurations::mIsPrinted = false; - int Configurations::CalculateZObsNumber() { - return this->GetProblemSize() - GetUnknownObservationsNb(); -} \ No newline at end of file + return (this->GetProblemSize()) - this->GetUnknownObservationsNb(); +} + +Configurations::~Configurations() { + + if (mHeapAllocated) { + for (size_t i = 0; i < this->mArgC; ++i) { + delete[] this->mpArgV[i]; // Delete each string + } + delete[] this->mpArgV; // Delete the array of pointers + } + this->mpArgV = nullptr; + mFirstInit = false; +} + +void Configurations::SetTolerance(double aTolerance) { + mDictionary["Tolerance"] = pow(10, -1 * aTolerance); +} diff --git a/src/data-generators/CMakeLists.txt b/src/data-generators/CMakeLists.txt index 67966b9e..e5e32bdb 100644 --- a/src/data-generators/CMakeLists.txt +++ b/src/data-generators/CMakeLists.txt @@ -1,14 +1,14 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief CMake configuration file for Data Generators module -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah -# @date 2023-02-14 +# @date 2024-02-04 # Add subdirectories for concrete implementations add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/concrete) @@ -16,6 +16,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/concrete) # Add source files to the parent scope set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/DataGenerator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/LocationGenerator.cpp ${SOURCES} PARENT_SCOPE ) diff --git a/src/data-generators/DataGenerator.cpp b/src/data-generators/DataGenerator.cpp index 548185a0..dd4bec8b 100644 --- a/src/data-generators/DataGenerator.cpp +++ b/src/data-generators/DataGenerator.cpp @@ -1,40 +1,40 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DataGenerator.cpp * @brief Implementation of DataGenerator class - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-02-14 + * @date 2024-02-04 **/ #include #include -#include -#include +#include using namespace exageostat::generators; +using namespace exageostat::dataLoader::csv; using namespace exageostat::generators::synthetic; -using namespace exageostat::generators::csv; -using namespace exageostat::dataunits; -using namespace exageostat::configurations; +using namespace exageostat::common; +using namespace exageostat::results; template -std::unique_ptr> DataGenerator::CreateGenerator(Configurations &apConfigurations) { +std::unique_ptr> DataGenerator::CreateGenerator(configurations::Configurations &apConfigurations) { + //// TODO: In case of other file support, Then we can create another layer for the factory creation depending on the file size. // Check the used Data generation method, whether it's synthetic or real. - mIsSynthetic = apConfigurations.GetIsSynthetic(); - mIsCSV = apConfigurations.GetIsCSV(); - results::Results::GetInstance()->SetIsSynthetic(mIsSynthetic); + aDataSourceType = apConfigurations.GetIsSynthetic() ? SYNTHETIC : CSV_FILE; // Return DataGenerator unique pointer of Synthetic type - if (mIsSynthetic) { + if (aDataSourceType == SYNTHETIC) { + Results::GetInstance()->SetIsSynthetic(true); return std::unique_ptr>(SyntheticGenerator::GetInstance()); - } else if (mIsCSV) { - return std::unique_ptr>(CSVDataGenerator::GetInstance()); + } else if (aDataSourceType == CSV_FILE) { + Results::GetInstance()->SetIsSynthetic(false); + return std::unique_ptr>(CSVLoader::GetInstance()); } else { throw std::runtime_error("Data Loading for this file type is unsupported for now"); } @@ -43,15 +43,14 @@ std::unique_ptr> DataGenerator::CreateGenerator(Configuratio template DataGenerator::~DataGenerator() { // Return DataGenerator unique pointer of Synthetic type - if (mIsSynthetic) { + if (aDataSourceType == SYNTHETIC) { SyntheticGenerator::GetInstance()->ReleaseInstance(); - } else if (mIsCSV) { - CSVDataGenerator::GetInstance()->ReleaseInstance(); + } else if (aDataSourceType == CSV_FILE) { + CSVLoader::GetInstance()->ReleaseInstance(); } else { std::cerr << "Data Loading for this file type is unsupported for now" << std::endl; std::exit(1); } } -template bool DataGenerator::mIsSynthetic = true; -template bool DataGenerator::mIsCSV = false; +template DataSourceType DataGenerator::aDataSourceType = SYNTHETIC; diff --git a/src/data-generators/LocationGenerator.cpp b/src/data-generators/LocationGenerator.cpp new file mode 100644 index 00000000..5703e04b --- /dev/null +++ b/src/data-generators/LocationGenerator.cpp @@ -0,0 +1,124 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file LocationGenerator.cpp + * @brief Generates and manages spatial locations for ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-04 +**/ + +#include +#include + +#include +#include + +using namespace exageostat::generators; +using namespace exageostat::common; +using namespace exageostat::dataunits; +using namespace exageostat::helpers; + +template +void LocationGenerator::GenerateLocations(const int &aN, const int &aTimeSlot, const Dimension &aDimension, + Locations &aLocations) { + + aLocations.SetSize(aN); + int index = 0; + aLocations.SetDimension(aDimension); + + int rootN; + if (aDimension == Dimension3D) { + //Cubic root. + rootN = ceil(cbrt(aN)); + } else { + //Square root. + rootN = ceil(sqrt(aN)); + } + + int *grid = new int[rootN](); + for (auto i = 0; i < rootN; i++) { + grid[i] = i + 1; + } + T range_low = -0.4, range_high = 0.4; + + for (auto i = 0; i < rootN && index < aN; i++) { + for (auto j = 0; j < rootN && index < aN; j++) { + if (aDimension == Dimension3D) { + for (auto k = 0; k < rootN && index < aN; k++) { + aLocations.GetLocationX()[index] = + (grid[i] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; + aLocations.GetLocationY()[index] = + (grid[j] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; + aLocations.GetLocationZ()[index] = + (grid[k] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; + index++; + } + } else { + aLocations.GetLocationX()[index] = + (grid[i] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; + aLocations.GetLocationY()[index] = + (grid[j] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; + if (aDimension == DimensionST) { + aLocations.GetLocationZ()[index] = 1.0; + } + index++; + } + } + } + delete[] grid; + if (aDimension != DimensionST) { + SortLocations(aN, aDimension, aLocations); + } else { + for (auto i = 0; i < aN; i++) { + aLocations.GetLocationX()[i] = aLocations.GetLocationX()[i]; + aLocations.GetLocationY()[i] = aLocations.GetLocationY()[i]; + aLocations.GetLocationZ()[i] = (T) (i / aTimeSlot + 1); + } + } +} + +template +T LocationGenerator::UniformDistribution(const T &aRangeLow, const T &aRangeHigh) { + T myRand = (T) rand() / (T) (1.0 + RAND_MAX); + T range = aRangeHigh - aRangeLow; + return (myRand * range) + aRangeLow; +} + +template +void +LocationGenerator::SortLocations(const int &aN, const Dimension &aDimension, Locations &aLocations) { + + // Some sorting, required by spatial statistics code + uint16_t x, y, z; + uint64_t vectorZ[aN]; + + // Encode data into vector z + for (auto i = 0; i < aN; i++) { + x = (uint16_t) (aLocations.GetLocationX()[i] * (double) UINT16_MAX + .5); + y = (uint16_t) (aLocations.GetLocationY()[i] * (double) UINT16_MAX + .5); + if (aDimension != Dimension2D) { + z = (uint16_t) (aLocations.GetLocationZ()[i] * (double) UINT16_MAX + .5); + } else { + z = (uint16_t) 0.0; + } + vectorZ[i] = (SpreadBits(z) << 2) + (SpreadBits(y) << 1) + SpreadBits(x); + } + // Sort vector z + std::sort(vectorZ, vectorZ + aN, CompareUint64); + + // Decode data from vector z + for (auto i = 0; i < aN; i++) { + x = ReverseSpreadBits(vectorZ[i] >> 0); + y = ReverseSpreadBits(vectorZ[i] >> 1); + z = ReverseSpreadBits(vectorZ[i] >> 2); + aLocations.GetLocationX()[i] = (double) x / (double) UINT16_MAX; + aLocations.GetLocationY()[i] = (double) y / (double) UINT16_MAX; + if (aDimension == Dimension3D) { + aLocations.GetLocationZ()[i] = (double) z / (double) UINT16_MAX; + } + } +} \ No newline at end of file diff --git a/src/data-generators/concrete/CMakeLists.txt b/src/data-generators/concrete/CMakeLists.txt index 55d821bb..bca0dfdb 100644 --- a/src/data-generators/concrete/CMakeLists.txt +++ b/src/data-generators/concrete/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief CMake configuration file for the Synthetic Generator module -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-02-14 @@ -13,8 +13,6 @@ # Add source files to the parent scope set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/SyntheticGenerator.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/CSVDataGenerator.cpp - ${SOURCES} PARENT_SCOPE ) \ No newline at end of file diff --git a/src/data-generators/concrete/CSVDataGenerator.cpp b/src/data-generators/concrete/CSVDataGenerator.cpp deleted file mode 100644 index 820a9fab..00000000 --- a/src/data-generators/concrete/CSVDataGenerator.cpp +++ /dev/null @@ -1,201 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file CSVDataGenerator.cpp - * @brief Implementation of the CSVDataGenerator class - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-02-14 -**/ - -#include - -#include - -using namespace std; - -using namespace exageostat::generators::csv; -using namespace exageostat::configurations; -using namespace exageostat::hardware; -using namespace exageostat::dataunits; -using namespace exageostat::kernels; -using namespace exageostat::common; -using namespace exageostat::linearAlgebra; - -template -CSVDataGenerator *CSVDataGenerator::GetInstance() { - - if (mpInstance == nullptr) { - mpInstance = new CSVDataGenerator(); - } - return mpInstance; -} - -template -ExaGeoStatData *CSVDataGenerator::CreateData(exageostat::configurations::Configurations &aConfigurations, - const exageostat::hardware::ExaGeoStatHardware &aHardware, - exageostat::kernels::Kernel &aKernel) { - // create vectors that will be populated with read data. - vector measurements_vector; - vector x_locations; - vector y_locations; - vector z_locations; - - aKernel.SetPValue(aConfigurations.GetTimeSlot()); - aConfigurations.SetP(aKernel.GetPValue()); - int p = aConfigurations.GetP(); - - //Read the data out of the CSV file. - ReadData(aConfigurations, measurements_vector, x_locations, y_locations, z_locations); - - //create data object - auto *data = new ExaGeoStatData(aConfigurations.GetProblemSize() / p, aConfigurations.GetDimension()); - - //Initialize the descriptors. - auto linear_algebra_solver = LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); - linear_algebra_solver->SetContext(aHardware.GetChameleonContext()); - linear_algebra_solver->InitiateDescriptors(aConfigurations, *data->GetDescriptorData()); - linear_algebra_solver->ExaGeoStatLaSetTile(EXAGEOSTAT_UPPER_LOWER, 0, 0, data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_C).chameleon_desc); - //populate data object with read data - for (int i = 0; i < aConfigurations.GetProblemSize() / p; i++) { - data->GetLocations()->GetLocationX()[i] = x_locations[i]; - data->GetLocations()->GetLocationY()[i] = y_locations[i]; - if (aConfigurations.GetDimension() != Dimension2D) { - data->GetLocations()->GetLocationZ()[i] = z_locations[i]; - } - } - for (int i = 0; i < aConfigurations.GetProblemSize(); i++){ - ((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc->mat)[i] = measurements_vector[i]; - } - - results::Results::GetInstance()->SetGeneratedLocationsNumber(aConfigurations.GetProblemSize()); - results::Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); - results::Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); - - return data; -} - -template -void -CSVDataGenerator::ReadData(Configurations &aConfigurations, - vector &aMeasurementsMatrix, vector &aXLocations, - vector &aYLocations, vector &aZLocations) { - - //Check if the user entered a valid path for the CSV file. - if (aConfigurations.GetDataPath().empty()) { - throw runtime_error("Please enter the path to data file."); - } - - string data_path = aConfigurations.GetDataPath(); - Dimension dimension = aConfigurations.GetDimension(); - int p = aConfigurations.GetP(); - ifstream file; - - file.open(data_path, ios::in); - - //Throw error if unable to open file. - if (!file.is_open()) { - throw runtime_error("Cannot read locations file: " + data_path); - } - - //Keep track of number of lines. - int index = 0; - string line; - //Loop through the lines - while (getline(file, line)) { - istringstream iss(line); - string token; - - // Split each line into tokens using ',' as the delimiter - if (getline(iss, token, ',')) { - aXLocations.push_back(stod(token)); - } - if (getline(iss, token, ',')) { - aYLocations.push_back(stod(token)); - } - if (getline(iss, token, ',')) { - //If it's a 2D locations data, the last values of the lines should be the measurement values. - //If it's 3D locations data, the third value of the line should be the Z coordinate. - //If it's ST location data, the third value of the line should be the Time coordinate - if (dimension == Dimension2D) { - aMeasurementsMatrix.push_back(stod(token)); - //if p == 2, the third and fourth values of each line are saved in the Measurements Matrix. - if (p == 2) { - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } else { - throw runtime_error( - "The data P in the provided file isn't consistent with the Kernel's P."); - } - } - if (p == 3) { - //if p == 3, the third, fourth, and fifth values of each line are saved in the Measurements Matrix. - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } else { - throw runtime_error( - "The data P in the provided file isn't consistent with the Kernel's P."); - } - } - } else { - aZLocations.push_back(stod(token)); - } - } - - if (getline(iss, token, ',')) { - if (dimension != Dimension2D) { - aMeasurementsMatrix.push_back(stod(token)); - //if p == 2, the fourth and fifth values of each line are saved in the Measurements Matrix. - if (p == 2) { - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } else { - throw runtime_error( - "The data P in the provided file isn't consistent with the Kernel's P."); - } - } - if (p == 3) { - //if p == 3, the fourth, fifth, and sixth values of each line are saved in the Measurements Matrix. - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } - if (getline(iss, token, ',')) { - aMeasurementsMatrix.push_back(stod(token)); - } else { - throw runtime_error( - "The data P in the provided file isn't consistent with the Kernel's P."); - } - } - } else { - throw runtime_error( - "The data dimensions in the provided file isn't consistent with the dimensions input."); - } - } else if (dimension != Dimension2D) { - throw runtime_error("The data dimensions in the provided file isn't consistent with the dimensions input."); - } - index++; - } - - //problem size is equal to the number of the CSV lines * P / aConfigurations.GetTimeSlot(). - aConfigurations.SetProblemSize(index * p / aConfigurations.GetTimeSlot()); - - file.close(); -} - -template -void CSVDataGenerator::ReleaseInstance() { - if (mpInstance != nullptr) { - mpInstance = nullptr; - } -} - -template CSVDataGenerator *CSVDataGenerator::mpInstance = nullptr; diff --git a/src/data-generators/concrete/SyntheticGenerator.cpp b/src/data-generators/concrete/SyntheticGenerator.cpp index 2f21aa6a..85cfa7ec 100644 --- a/src/data-generators/concrete/SyntheticGenerator.cpp +++ b/src/data-generators/concrete/SyntheticGenerator.cpp @@ -1,27 +1,25 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file SyntheticGenerator.cpp * @brief Implementation of the SyntheticGenerator class - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-02-14 + * @date 2024-02-04 **/ #include +#include +#include using namespace exageostat::generators::synthetic; -using namespace exageostat::dataunits; -using namespace exageostat::hardware; using namespace exageostat::common; using namespace exageostat::configurations; -using namespace exageostat::kernels; -using namespace exageostat::helpers; -using namespace exageostat::linearAlgebra; +using namespace exageostat::results; template SyntheticGenerator *SyntheticGenerator::GetInstance() { @@ -33,204 +31,63 @@ SyntheticGenerator *SyntheticGenerator::GetInstance() { } template -ExaGeoStatData *SyntheticGenerator::CreateData(exageostat::configurations::Configurations &aConfigurations, - const exageostat::hardware::ExaGeoStatHardware &aHardware, - exageostat::kernels::Kernel &aKernel) { +std::unique_ptr> +SyntheticGenerator::CreateData(Configurations &aConfigurations, + exageostat::kernels::Kernel &aKernel) { - auto *data = new ExaGeoStatData(aConfigurations.GetProblemSize(), aConfigurations.GetDimension()); + int n = aConfigurations.GetProblemSize() * aConfigurations.GetTimeSlot(); + auto data = std::make_unique>(n, aConfigurations.GetDimension()); // Allocated new Locations object. - auto *locations = new Locations((aConfigurations.GetProblemSize() * aConfigurations.GetTimeSlot()), - aConfigurations.GetDimension()); - - // Set some kernel and arguments values. - aKernel.SetPValue(aConfigurations.GetTimeSlot()); - int N = aConfigurations.GetProblemSize(); - aConfigurations.SetProblemSize( - aConfigurations.GetProblemSize() * aKernel.GetPValue() / aConfigurations.GetTimeSlot()); - - aConfigurations.SetP(aKernel.GetPValue()); + auto *locations = new dataunits::Locations(n, aConfigurations.GetDimension()); int parameters_number = aKernel.GetParametersNumbers(); // Set initial theta values. Configurations::InitTheta(aConfigurations.GetInitialTheta(), parameters_number); aConfigurations.SetInitialTheta(aConfigurations.GetInitialTheta()); - GenerateLocations(N, aConfigurations.GetTimeSlot(), aConfigurations.GetDimension(), *locations); + // Generate Locations phase + LocationGenerator::GenerateLocations(n, aConfigurations.GetTimeSlot(), aConfigurations.GetDimension(), + *locations); data->SetLocations(*locations); - auto linear_algebra_solver = LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); - linear_algebra_solver->GenerateSyntheticData(aConfigurations, aHardware, *data, aKernel); + // Generate Descriptors phase + auto linear_algebra_solver = linearAlgebra::LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); + linear_algebra_solver->GenerateSyntheticData(aConfigurations, data, aKernel); if (aConfigurations.GetLogger()) { VERBOSE("Writing generated data to the disk (Synthetic Dataset Generation Phase) .....") -#ifdef CHAMELEON_USE_MPI +#ifdef USE_MPI auto pMatrix = new T[aConfigurations.GetProblemSize()]; std::string path = aConfigurations.GetLoggerPath(); CHAMELEON_Desc2Lap(ChamUpperLower, data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc, pMatrix, aConfigurations.GetProblemSize()); - if ( CHAMELEON_Comm_rank == 0 ){ - DiskWriter::WriteVectorsToDisk(*((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc->mat), - aConfigurations.GetProblemSize(), aConfigurations.GetP(), path, - *data->GetLocations()); + DESCRIPTOR_Z).chameleon_desc, + pMatrix, aConfigurations.GetProblemSize()); + if (helpers::CommunicatorMPI::GetInstance()->GetRank() == 0) { + dataLoader::csv::CSVLoader::GetInstance()->WriteData( + *((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_Z).chameleon_desc->mat), + aConfigurations.GetProblemSize(), parameters_number, path, + *data->GetLocations()); } delete[] pMatrix; #else std::string path = aConfigurations.GetLoggerPath(); - DiskWriter::WriteVectorsToDisk(*((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + dataLoader::csv::CSVLoader::GetInstance()->WriteData(*((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc->mat), - aConfigurations.GetProblemSize(), aConfigurations.GetP(), path, + aConfigurations.GetProblemSize(), aKernel.GetVariablesNumber(), path, *data->GetLocations()); #endif VERBOSE("Done.") } - results::Results::GetInstance()->SetGeneratedLocationsNumber(aConfigurations.GetProblemSize()); - results::Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); - results::Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); + Results::GetInstance()->SetGeneratedLocationsNumber(n); + Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); + Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); return data; } -template -void SyntheticGenerator::GenerateLocations(const int &aN, const int &aTimeSlot, const Dimension &aDimension, - Locations &aLocations) { - - aLocations.SetSize(aN); - int index = 0; - aLocations.SetDimension(aDimension); - - int rootN; - if (aDimension == Dimension3D) { - //Cubic root. - rootN = ceil(cbrt(aN)); - } else { - //Square root. - rootN = ceil(sqrt(aN)); - } - - int *grid = new int[rootN](); - for (auto i = 0; i < rootN; i++) { - grid[i] = i + 1; - } - - double range_low = -0.4, range_high = 0.4; - - for (auto i = 0; i < rootN && index < aN; i++) { - for (auto j = 0; j < rootN && index < aN; j++) { - if (aDimension == Dimension3D) { - for (auto k = 0; k < rootN && index < aN; k++) { - aLocations.GetLocationX()[index] = - (grid[i] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; - aLocations.GetLocationY()[index] = - (grid[j] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; - aLocations.GetLocationZ()[index] = - (grid[k] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; - index++; - } - } else { - aLocations.GetLocationX()[index] = (grid[i] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; - aLocations.GetLocationY()[index] = (grid[j] - 0.5 + UniformDistribution(range_low, range_high)) / rootN; - if (aDimension == DimensionST) { - aLocations.GetLocationZ()[index] = 1.0; - } - index++; - } - } - } - delete[] grid; - if (aDimension != DimensionST) { - SortLocations(aN, aDimension, aLocations); - } else { - for (auto j = 1; j < aTimeSlot; j++) { - for (auto i = 0; i < aN; i++) { - aLocations.GetLocationX()[i + j * aN] = aLocations.GetLocationX()[i]; - aLocations.GetLocationY()[i + j * aN] = aLocations.GetLocationY()[i]; - aLocations.GetLocationZ()[i + j * aN] = (double) (j + 1); - } - } - } -} - -template -double SyntheticGenerator::UniformDistribution(const double &aRangeLow, const double &aRangeHigh) { - double myRand = (double) rand() / (double) (1.0 + RAND_MAX); - double range = aRangeHigh - aRangeLow; - return (myRand * range) + aRangeLow; -} - -template -void SyntheticGenerator::SortLocations(const int &aN, const Dimension &aDimension, Locations &aLocations) { - - // Some sorting, required by spatial statistics code - uint16_t x, y, z; - uint64_t vectorZ[aN]; - - // Encode data into vector z - for (auto i = 0; i < aN; i++) { - x = (uint16_t) (aLocations.GetLocationX()[i] * (double) UINT16_MAX + .5); - y = (uint16_t) (aLocations.GetLocationY()[i] * (double) UINT16_MAX + .5); - if (aDimension != Dimension2D) { - z = (uint16_t) (aLocations.GetLocationZ()[i] * (double) UINT16_MAX + .5); - } else { - z = (uint16_t) 0.0; - } - vectorZ[i] = (SpreadBits(z) << 2) + (SpreadBits(y) << 1) + SpreadBits(x); - } - // Sort vector z - std::sort(vectorZ, vectorZ + aN, CompareUint64); - - // Decode data from vector z - for (auto i = 0; i < aN; i++) { - x = ReverseSpreadBits(vectorZ[i] >> 0); - y = ReverseSpreadBits(vectorZ[i] >> 1); - z = ReverseSpreadBits(vectorZ[i] >> 2); - aLocations.GetLocationX()[i] = (double) x / (double) UINT16_MAX; - aLocations.GetLocationY()[i] = (double) y / (double) UINT16_MAX; - if (aDimension == Dimension3D) { - aLocations.GetLocationZ()[i] = (double) z / (double) UINT16_MAX; - } - } -} - -template -uint64_t SyntheticGenerator::SpreadBits(uint64_t aInputByte) { - aInputByte &= 0x000000000000ffff; - // aInputByte = ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- fedc ba98 7654 3210 - aInputByte = (aInputByte ^ (aInputByte << 24)) & 0x000000ff000000ff; - // aInputByte = ---- ---- ---- ---- ---- ---- fedc ba98 ---- ---- ---- ---- ---- ---- 7654 3210 - aInputByte = (aInputByte ^ (aInputByte << 12)) & 0x000f000f000f000f; //000 7000f000f000f - // aInputByte = ---- ---- ---- fedc ---- ---- ---- ba98 ---- ---- ---- 7654 ---- ---- ---- 3210 - aInputByte = (aInputByte ^ (aInputByte << 6)) & 0x0303030303030303; //0 0001 0 0011 0 0011 0 0011 0 - // aInputByte = ---- --fe ---- --dc ---- --ba ---- --98 ---- --76 ---- --54 ---- --32 ---- --10 - aInputByte = (aInputByte ^ (aInputByte << 3)) & 0x1111111111111111; - // aInputByte = ---f ---e ---d ---c ---b ---a ---9 ---8 ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0 - return aInputByte; -} - -template -uint64_t SyntheticGenerator::ReverseSpreadBits(uint64_t aInputByte) { - - aInputByte &= 0x1111111111111111; - // aInputByte = ---f ---e ---d ---c ---b ---a ---9 ---8 ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0 - aInputByte = (aInputByte ^ (aInputByte >> 3)) & 0x0303030303030303; - // aInputByte = ---- --fe ---- --dc ---- --ba ---- --98 ---- --76 ---- --54 ---- --32 ---- --10 - aInputByte = (aInputByte ^ (aInputByte >> 6)) & 0x000f000f000f000f; - // aInputByte = ---- ---- ---- fedc ---- ---- ---- ba98 ---- ---- ---- 7654 ---- ---- ---- 3210 - aInputByte = (aInputByte ^ (aInputByte >> 12)) & 0x000000ff000000ff; - // aInputByte = ---- ---- ---- ---- ---- ---- fedc ba98 ---- ---- ---- ---- ---- ---- 7654 3210 - aInputByte = (aInputByte ^ (aInputByte >> 24)) & 0x000000000000ffff; - // aInputByte = ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- fedc ba98 7654 3210 - return aInputByte; - -} - -template -bool SyntheticGenerator::CompareUint64(const uint64_t &aFirstValue, const uint64_t &aSecondValue) { - return aFirstValue < aSecondValue; -} - template void SyntheticGenerator::ReleaseInstance() { if (mpInstance != nullptr) { diff --git a/src/data-loader/CMakeLists.txt b/src/data-loader/CMakeLists.txt new file mode 100644 index 00000000..03a54e86 --- /dev/null +++ b/src/data-loader/CMakeLists.txt @@ -0,0 +1,20 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @brief CMake configuration file for Data loader module +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-02-14 + +# Add subdirectories for concrete implementations +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/concrete) + +# Add source files to the parent scope +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/DataLoader.cpp + ${SOURCES} + PARENT_SCOPE + ) diff --git a/src/data-loader/DataLoader.cpp b/src/data-loader/DataLoader.cpp new file mode 100644 index 00000000..fb7ca2fd --- /dev/null +++ b/src/data-loader/DataLoader.cpp @@ -0,0 +1,67 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file SyntheticGenerator.cpp + * @brief Implementation of the SyntheticGenerator class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2023-02-14 +**/ + +#include + +using namespace std; + +using namespace exageostat::dataLoader; +using namespace exageostat::common; +using namespace exageostat::results; + +template +std::unique_ptr> +DataLoader::CreateData(configurations::Configurations &aConfigurations, exageostat::kernels::Kernel &aKernel) { + + // create vectors that will be populated with read data. + vector measurements_vector; + vector x_locations; + vector y_locations; + vector z_locations; + + aKernel.SetPValue(aConfigurations.GetTimeSlot()); + int p = aKernel.GetVariablesNumber(); + + //Read the data out of the CSV file. + this->ReadData(aConfigurations, measurements_vector, x_locations, y_locations, z_locations, p); + + //create data object + auto data = std::make_unique>(aConfigurations.GetProblemSize() / p, + aConfigurations.GetDimension()); + + //Initialize the descriptors. + auto linear_algebra_solver = linearAlgebra::LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); + linear_algebra_solver->InitiateDescriptors(aConfigurations, *data->GetDescriptorData(), p); + linear_algebra_solver->ExaGeoStatLaSetTile(EXAGEOSTAT_UPPER_LOWER, 0, 0, + data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_C).chameleon_desc); + //populate data object with read data + for (int i = 0; i < aConfigurations.GetProblemSize() / p; i++) { + data->GetLocations()->GetLocationX()[i] = x_locations[i]; + data->GetLocations()->GetLocationY()[i] = y_locations[i]; + if (aConfigurations.GetDimension() != Dimension2D) { + data->GetLocations()->GetLocationZ()[i] = z_locations[i]; + } + } + for (int i = 0; i < aConfigurations.GetProblemSize(); i++) { + ((T *) data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_Z).chameleon_desc->mat)[i] = measurements_vector[i]; + } + + Results::GetInstance()->SetGeneratedLocationsNumber(aConfigurations.GetProblemSize() / p); + Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); + Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); + + return data; +} diff --git a/src/data-loader/concrete/CMakeLists.txt b/src/data-loader/concrete/CMakeLists.txt new file mode 100644 index 00000000..88180c80 --- /dev/null +++ b/src/data-loader/concrete/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @brief CMake configuration file for the data loader module +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-02-14 + +# Add source files to the parent scope +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/CSVLoader.cpp + ${SOURCES} + PARENT_SCOPE + ) \ No newline at end of file diff --git a/src/data-loader/concrete/CSVLoader.cpp b/src/data-loader/concrete/CSVLoader.cpp new file mode 100644 index 00000000..bfd153cd --- /dev/null +++ b/src/data-loader/concrete/CSVLoader.cpp @@ -0,0 +1,241 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file CSVDataGenerator.cpp + * @brief Implementation of the CSVDataGenerator class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2023-02-14 +**/ + +#include + +#include + +using namespace std; + +using namespace exageostat::configurations; +using namespace exageostat::common; +using namespace exageostat::dataLoader::csv; + +template +CSVLoader *CSVLoader::GetInstance() { + + if (mpInstance == nullptr) { + mpInstance = new CSVLoader(); + } + return mpInstance; +} + +template +void CSVLoader::ReadData(Configurations &aConfigurations, vector &aMeasurementsMatrix, vector &aXLocations, + vector &aYLocations, vector &aZLocations, const int &aP) { + + //Check if the user entered a valid path for the CSV file. + if (aConfigurations.GetDataPath().empty()) { + throw runtime_error("Please enter the path to data file."); + } + + string data_path = aConfigurations.GetDataPath(); + Dimension dimension = aConfigurations.GetDimension(); + ifstream file; + + file.open(data_path, ios::in); + + //Throw error if unable to open file. + if (!file.is_open()) { + throw runtime_error("Cannot read locations file: " + data_path); + } + + //Keep track of number of lines. + int index = 0; + string line; + //Loop through the lines + while (getline(file, line)) { + istringstream iss(line); + string token; + + // Split each line into tokens using ',' as the delimiter + if (getline(iss, token, ',')) { + aXLocations.push_back(stod(token)); + } + if (getline(iss, token, ',')) { + aYLocations.push_back(stod(token)); + } + if (getline(iss, token, ',')) { + //If its a 2D locations' data, the last values of the lines should be the measurement values. + //If its 3D locations' data, the third value of the line should be the Z coordinate. + //If its ST location data, the third value of the line should be the Time coordinate + if (dimension == Dimension2D) { + aMeasurementsMatrix.push_back(stod(token)); + //if p == 2, the third and fourth values of each line are saved in the Measurements Matrix. + if (aP == 2) { + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } else { + throw runtime_error( + "The data P in the provided file isn't consistent with the Kernel's P."); + } + } + if (aP == 3) { + //if p == 3, the third, fourth, and fifth values of each line are saved in the Measurements Matrix. + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } else { + throw runtime_error( + "The data P in the provided file isn't consistent with the Kernel's P."); + } + } + } else { + aZLocations.push_back(stod(token)); + } + } + + if (getline(iss, token, ',')) { + if (dimension != Dimension2D) { + aMeasurementsMatrix.push_back(stod(token)); + //if p == 2, the fourth and fifth values of each line are saved in the Measurements Matrix. + if (aP == 2) { + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } else { + throw runtime_error( + "The data P in the provided file isn't consistent with the Kernel's P."); + } + } + if (aP == 3) { + //if p == 3, the fourth, fifth, and sixth values of each line are saved in the Measurements Matrix. + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } + if (getline(iss, token, ',')) { + aMeasurementsMatrix.push_back(stod(token)); + } else { + throw runtime_error( + "The data P in the provided file isn't consistent with the Kernel's P."); + } + } + } else { + throw runtime_error( + "The data dimensions in the provided file isn't consistent with the dimensions input."); + } + } else if (dimension != Dimension2D) { + throw runtime_error("The data dimensions in the provided file isn't consistent with the dimensions input."); + } + index++; + } + + //problem size is equal to the number of the CSV lines * P / aConfigurations.GetTimeSlot(). + aConfigurations.SetProblemSize(index * aP / aConfigurations.GetTimeSlot()); + + file.close(); + LOGGER("\tData is read from " << data_path << " successfully.") +} + +template +void CSVLoader::WriteData(const T &aMatrixPointer, const int &aProblemSize, const int &aP, std::string &aLoggerPath, + dataunits::Locations &aLocations) { + // Determine the path for storing the output files + if (aLoggerPath.empty()) { + aLoggerPath = LOG_PATH; + } else { + if (aLoggerPath.back() == '/') { + aLoggerPath += "synthetic_ds"; + } else { + aLoggerPath += "/synthetic_ds"; + } + } + // Create a new directory if it does not already exist + bool created; + if (!filesystem::exists(aLoggerPath)) { + try { + created = filesystem::create_directories(aLoggerPath); + } catch (const filesystem::filesystem_error &e) { + throw runtime_error("Error creating directory: " + aLoggerPath); + } + } else { + created = true; + } + + // Check if the directory was created successfully + if (!created) { + throw runtime_error("Error creating directory: " + aLoggerPath); + } + + // Determine the names of the output files + size_t i = 1, j; + std::ofstream p_file_synthetic, p_file_log; + std::string n_file_synthetic = aLoggerPath + "/SYN_" + std::to_string(aProblemSize / aP) + "_"; + std::string n_file_log = aLoggerPath + "/log_" + std::to_string(aProblemSize / aP) + "_"; + std::string temp = n_file_log + std::to_string(i); + + // Check if log file exists + while (std::filesystem::exists(temp)) { + i++; + temp = n_file_log + std::to_string(i); + } + + n_file_synthetic += std::to_string(i); + p_file_synthetic.open(n_file_synthetic); + + for (j = 0, i = 0; i < aProblemSize / aP; i++) { + if (aLocations.GetLocationZ() == nullptr) { + //2 Dimensions + if (aP == 1) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[i] + << '\n'; + } else if (aP == 2) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[j] + << "," + << std::setprecision(15) << (&aMatrixPointer)[j + 1] << '\n'; + j += 2; + } else if (aP == 3) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[j] + << "," + << std::setprecision(15) << (&aMatrixPointer)[j + 1] << "," << std::setprecision(15) + << (&aMatrixPointer)[j + 2] << '\n'; + j += 3; + } + } else { + //3 Dimensions + if (aP == 1) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," + << std::setprecision(15) << (&aMatrixPointer)[i] << '\n'; + } else if (aP == 2) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," + << std::setprecision(15) << (&aMatrixPointer)[j] << std::setprecision(15) << "," + << (&aMatrixPointer)[j + 1] << '\n'; + j += 2; + } else if (aP == 3) { + p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' + << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," + << std::setprecision(15) << (&aMatrixPointer)[j] << "," << std::setprecision(15) + << (&aMatrixPointer)[j + 1] << "," << std::setprecision(15) << (&aMatrixPointer)[j + 2] + << '\n'; + j += 3; + } + } + } + p_file_synthetic.close(); +} + +template +void CSVLoader::ReleaseInstance() { + if (mpInstance != nullptr) { + mpInstance = nullptr; + } +} + +template CSVLoader *CSVLoader::mpInstance = nullptr; diff --git a/src/data-units/CMakeLists.txt b/src/data-units/CMakeLists.txt index d05e9096..85e48392 100644 --- a/src/data-units/CMakeLists.txt +++ b/src/data-units/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-02-27 diff --git a/src/data-units/DescriptorData.cpp b/src/data-units/DescriptorData.cpp index b64f9d03..eff728d3 100644 --- a/src/data-units/DescriptorData.cpp +++ b/src/data-units/DescriptorData.cpp @@ -1,18 +1,17 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DescriptorData.cpp * @brief Contains the definition of the DescriptorData class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-07-18 **/ -#include #include using namespace exageostat::dataunits; @@ -28,8 +27,8 @@ DescriptorData::~DescriptorData() { for (const auto &pair: this->mDictionary) { const std::string &key = pair.first; if (key.find("CHAMELEON") != std::string::npos && pair.second != nullptr) { - exaGeoStatDescriptor.DestroyDescriptor(common::CHAMELEON_DESCRIPTOR, pair.second); -#ifdef EXAGEOSTAT_USE_HICMA + exaGeoStatDescriptor.DestroyDescriptor(CHAMELEON_DESCRIPTOR, pair.second); +#ifdef USE_HICMA // Since there are converted descriptors from Chameleon to Hicma, which have the same memory address. // So, by deleting the owner which is Chameleon, no need to delete hicma. Therefore, we remove the row of that descriptor. std::string converted_chameleon = key.substr(0, key.length() - chameleon.length()); @@ -41,7 +40,7 @@ DescriptorData::~DescriptorData() { } #endif } else if (key.find("HICMA") != std::string::npos && pair.second != nullptr) { - exaGeoStatDescriptor.DestroyDescriptor(common::HICMA_DESCRIPTOR, pair.second); + exaGeoStatDescriptor.DestroyDescriptor(HICMA_DESCRIPTOR, pair.second); } } this->mDictionary.clear(); @@ -70,35 +69,19 @@ void *DescriptorData::GetRequest() { return this->mpRequest; } -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA template -HICMA_desc_t *DescriptorData::ConvertChameleonToHicma(CHAM_desc_t *apChameleonDesc) { +HICMA_desc_t * +DescriptorData::ConvertChameleonToHicma(CHAM_desc_t *apChameleonDesc, const DescriptorName &aDescriptorName) { - // Create a new HICMA descriptor - auto *hicma_desc = new HICMA_desc_t; + this->SetDescriptor(HICMA_DESCRIPTOR, aDescriptorName, apChameleonDesc->ooc, apChameleonDesc->mat, + (FloatPoint) (apChameleonDesc->dtyp), apChameleonDesc->mb, apChameleonDesc->nb, + apChameleonDesc->bsiz, apChameleonDesc->lm, apChameleonDesc->ln, apChameleonDesc->i, + apChameleonDesc->j, apChameleonDesc->m, apChameleonDesc->n, apChameleonDesc->p, + apChameleonDesc->q, apChameleonDesc->ooc, true); - // Set function pointers in HICMA descriptor - hicma_desc->get_blkaddr = hicma_getaddr_ccrb; - hicma_desc->get_blkldd = hicma_getblkldd_ccrb; - hicma_desc->get_rankof = hicma_getrankof_2d; - - // Set sizes and offsets for memory copy - size_t hicma_desc_total_size = 184; - size_t chameleon_desc_total_size = 200; - // Size of the common members between Hicma_desc and Chameleon_desc - size_t common_total_size = 3 * sizeof(size_t) + 30 * sizeof(int); - // Skip the size of function pointers. - size_t hicma_offset = hicma_desc_total_size - (common_total_size + sizeof(void *)); - size_t chameleon_offset = chameleon_desc_total_size - (common_total_size + sizeof(void *)); - - // Copy common data from CHAMELEON descriptor to HICMA descriptor - memcpy(((char *) hicma_desc) + hicma_offset, ((char *) apChameleonDesc) + chameleon_offset, common_total_size); - // Set additional data in HICMA descriptor - hicma_desc->mat = apChameleonDesc->mat; - hicma_desc->schedopt = apChameleonDesc->schedopt; - - return hicma_desc; + return this->GetDescriptor(HICMA_DESCRIPTOR, aDescriptorName).hicma_desc; } #endif @@ -115,7 +98,7 @@ DescriptorData::GetDescriptor(const DescriptorType &aDescriptorType, const De descriptor.chameleon_desc = (CHAM_desc_t *) this->mDictionary[GetDescriptorName(aDescriptorName) + "_CHAMELEON"]; } else { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA if (this->mDictionary.find(GetDescriptorName(aDescriptorName) + "_HICMA") != this->mDictionary.end()) { descriptor.hicma_desc = (HICMA_desc_t *) this->mDictionary[GetDescriptorName(aDescriptorName) + "_HICMA"]; @@ -126,13 +109,14 @@ DescriptorData::GetDescriptor(const DescriptorType &aDescriptorType, const De } else if (this->mDictionary.find(GetDescriptorName(aDescriptorName) + "_CHAMELEON") != this->mDictionary.end()) { descriptor.hicma_desc = this->ConvertChameleonToHicma( - (CHAM_desc_t *) this->mDictionary[GetDescriptorName(aDescriptorName) + "_CHAMELEON"]); + (CHAM_desc_t *) this->mDictionary[GetDescriptorName(aDescriptorName) + "_CHAMELEON"], + aDescriptorName); this->mDictionary[GetDescriptorName(aDescriptorName) + "_CHAM_HIC"] = descriptor.hicma_desc; } else { descriptor.hicma_desc = nullptr; } #else - throw std::runtime_error("To use HiCMA descriptor you need to enable EXAGEOSTAT_USE_HICMA!"); + throw std::runtime_error("To use HiCMA descriptor you need to enable USE_HICMA!"); #endif } return descriptor; @@ -140,10 +124,10 @@ DescriptorData::GetDescriptor(const DescriptorType &aDescriptorType, const De template void DescriptorData::SetDescriptor(const DescriptorType &aDescriptorType, const DescriptorName &aDescriptorName, - const bool &aIsOOC, void *apMatrix, const common::FloatPoint &aFloatPoint, + const bool &aIsOOC, void *apMatrix, const FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, const int &aM, const int &aN, const int &aP, - const int &aQ) { + const int &aQ, const bool &aValidOOC, const bool &aConverted) { void *descriptor; std::string type; @@ -151,32 +135,37 @@ void DescriptorData::SetDescriptor(const DescriptorType &aDescriptorType, con if (aDescriptorType == CHAMELEON_DESCRIPTOR) { descriptor = exaGeoStatDescriptor.CreateDescriptor((CHAM_desc_t *) descriptor, aDescriptorType, aIsOOC, apMatrix, aFloatPoint, aMB, aNB, aSize, aLM, aLN, aI, aJ, aM, - aN, aP, aQ); + aN, aP, aQ, aValidOOC); type = "_CHAMELEON"; } else { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA descriptor = exaGeoStatDescriptor.CreateDescriptor((HICMA_desc_t *) descriptor, aDescriptorType, aIsOOC, apMatrix, aFloatPoint, aMB, aNB, aSize, aLM, aLN, aI, aJ, aM, - aN, aP, aQ); + aN, aP, aQ, aValidOOC); type = "_HICMA"; #else - throw std::runtime_error("To create HiCMA descriptor you need to enable EXAGEOSTAT_USE_HICMA!"); + throw std::runtime_error("To create HiCMA descriptor you need to enable USE_HICMA!"); #endif } + if (aConverted) { + type = "_CHAM_HIC"; + } this->mDictionary[GetDescriptorName(aDescriptorName) + type] = descriptor; + } template -T *DescriptorData::GetDescriptorMatrix(const common::DescriptorType &aDescriptorType, void *apDesc) { - if (aDescriptorType == common::CHAMELEON_DESCRIPTOR) { - return (T *) ((CHAM_desc_t *) apDesc)->mat; +T * +DescriptorData::GetDescriptorMatrix(const DescriptorType &aDescriptorType, const DescriptorName &aDescriptorName) { + if (aDescriptorType == CHAMELEON_DESCRIPTOR) { + return (T *) (this->GetDescriptor(CHAMELEON_DESCRIPTOR, aDescriptorName).chameleon_desc)->mat; } else { -#ifdef EXAGEOSTAT_USE_HICMA - return (T *) ((HICMA_desc_t *) apDesc)->mat; +#ifdef USE_HICMA + return (T *) (this->GetDescriptor(HICMA_DESCRIPTOR, aDescriptorName).hicma_desc)->mat; #else - throw std::runtime_error("To use Hicma descriptor you need to enable EXAGEOSTAT_USE_HICMA!"); + throw std::runtime_error("To use Hicma descriptor you need to enable USE_HICMA!"); #endif } } @@ -289,6 +278,12 @@ std::string DescriptorData::GetDescriptorName(const DescriptorName &aDescript return "DESCRIPTOR_C_TRACE"; case DESCRIPTOR_C_DIAG : return "DESCRIPTOR_C_DIAG"; + case DESCRIPTOR_SUM : + return "DESCRIPTOR_SUM"; + case DESCRIPTOR_R : + return "DESCRIPTOR_R"; + case DESCRIPTOR_R_COPY : + return "DESCRIPTOR_R_COPY"; default: throw std::invalid_argument( "The name of descriptor you provided is undefined, Please read the user manual to know the available descriptors"); diff --git a/src/data-units/ExaGeoStatData.cpp b/src/data-units/ExaGeoStatData.cpp index f64078e0..a1c912a5 100644 --- a/src/data-units/ExaGeoStatData.cpp +++ b/src/data-units/ExaGeoStatData.cpp @@ -1,18 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatData.cpp * @brief Contains the implementation of the ExaGeoStatData class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-07-21 + * @date 2024-02-04 **/ #include +#include using namespace exageostat::dataunits; using namespace exageostat::common; @@ -23,6 +24,13 @@ ExaGeoStatData::ExaGeoStatData(const int &aSize, const Dimension &aDimension) this->mpDescriptorData = new DescriptorData(); } +template +ExaGeoStatData::ExaGeoStatData(const int &aSize, const std::string &aDimension) { + + this->mpLocations = new Locations(aSize, GetInputDimension(aDimension)); + this->mpDescriptorData = new DescriptorData(); +} + template ExaGeoStatData::~ExaGeoStatData() { delete this->mpLocations; @@ -70,7 +78,7 @@ void ExaGeoStatData::CalculateMedianLocations(const std::string &aKernelName, T x_min = this->mpLocations->GetLocationX()[0], x_max = this->mpLocations->GetLocationX()[0], y_min = this->mpLocations->GetLocationY()[0], y_max = this->mpLocations->GetLocationY()[0], z_min, z_max; - if (this->mpLocations->GetDimension() != common::Dimension2D) { + if (this->mpLocations->GetDimension() != Dimension2D) { z_min = this->mpLocations->GetLocationZ()[0]; z_max = this->mpLocations->GetLocationZ()[0]; } @@ -84,7 +92,7 @@ void ExaGeoStatData::CalculateMedianLocations(const std::string &aKernelName, y_min = (y < y_min) ? y : y_min; y_max = (y > y_max) ? y : y_max; - if (this->mpLocations->GetDimension() != common::Dimension2D) { + if (this->mpLocations->GetDimension() != Dimension2D) { T z = this->mpLocations->GetLocationX()[i]; z_min = (z < z_min) ? z : z_min; z_max = (z > z_max) ? z : z_max; @@ -93,13 +101,13 @@ void ExaGeoStatData::CalculateMedianLocations(const std::string &aKernelName, aLocations.GetLocationX()[0] = x_min + (x_max - x_min) / 2; aLocations.GetLocationY()[0] = y_min + (y_max - y_min) / 2; - if (this->mpLocations->GetDimension() != common::Dimension2D) { + if (this->mpLocations->GetDimension() != Dimension2D) { aLocations.GetLocationZ()[0] = z_min + (z_max - z_min) / 2; } } else { aLocations.GetLocationX()[0] = 0.5; aLocations.GetLocationY()[0] = 0.5; - if (this->mpLocations->GetDimension() != common::Dimension2D) { + if (this->mpLocations->GetDimension() != Dimension2D) { aLocations.GetLocationY()[0] = 0.5; } } diff --git a/src/data-units/Locations.cpp b/src/data-units/Locations.cpp index a2605ee3..abe0572c 100644 --- a/src/data-units/Locations.cpp +++ b/src/data-units/Locations.cpp @@ -1,24 +1,21 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Locations.cpp * @brief Implementation of the Locations class - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-02-27 **/ -#include #include #include -using namespace std; - using namespace exageostat::dataunits; using namespace exageostat::common; diff --git a/src/data-units/descriptor/CMakeLists.txt b/src/data-units/descriptor/CMakeLists.txt index fd3cff70..352aec33 100644 --- a/src/data-units/descriptor/CMakeLists.txt +++ b/src/data-units/descriptor/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-08-15 diff --git a/src/data-units/descriptor/ExaGeoStatDescriptor.cpp b/src/data-units/descriptor/ExaGeoStatDescriptor.cpp index 38e104d9..5d6cd730 100644 --- a/src/data-units/descriptor/ExaGeoStatDescriptor.cpp +++ b/src/data-units/descriptor/ExaGeoStatDescriptor.cpp @@ -1,45 +1,46 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatDescriptor.cpp * @brief Implementation of creating matrix descriptors used in CHAMELEON and HiCMA libraries. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-07-17 **/ +#include + +#include #include -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA #include #endif -#include - using namespace exageostat::common; using namespace exageostat::dataunits::descriptor; template void * -ExaGeoStatDescriptor::CreateDescriptor(void *apDescriptor, const DescriptorType &aDescriptorType, const bool &aIsOOC, - void *apMatrix, const common::FloatPoint &aFloatPoint, const int &aMB, - const int &aNB, const int &aSize, const int &aLM, const int &aLN, - const int &aI, const int &aJ, const int &aM, const int &aN, const int &aP, - const int &aQ) { +ExaGeoStatDescriptor::CreateDescriptor(void *apDescriptor, const common::DescriptorType &aDescriptorType, + const bool &aIsOOC, void *apMatrix, const common::FloatPoint &aFloatPoint, + const int &aMB, const int &aNB, const int &aSize, const int &aLM, + const int &aLN, const int &aI, const int &aJ, const int &aM, + const int &aN, const int &aP, const int &aQ, const bool &aValidOOC) { if (aDescriptorType == CHAMELEON_DESCRIPTOR) { return ChameleonDescriptor::CreateChameleonDescriptor(apDescriptor, aIsOOC, apMatrix, aFloatPoint, aMB, aNB, - aSize, aLM, aLN, aI, aJ, aM, aN, aP, aQ); + aSize, aLM, aLN, aI, aJ, aM, aN, aP, aQ, aValidOOC); } else if (aDescriptorType == HICMA_DESCRIPTOR) { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA return HicmaDescriptor::CreateHicmaDescriptor(apDescriptor, aIsOOC, apMatrix, aFloatPoint, aMB, aNB, aSize, - aLM, aLN, aI, aJ, aM, aN, aP, aQ); + aLM, aLN, aI, aJ, aM, aN, aP, aQ, aValidOOC); #endif } std::cerr << "Error, please select the correct descriptor type!" << std::endl; @@ -51,7 +52,7 @@ int ExaGeoStatDescriptor::DestroyDescriptor(const DescriptorType &aDescriptor if (aDescriptorType == CHAMELEON_DESCRIPTOR) { return ChameleonDescriptor::DestroyChameleonDescriptor(apDesc); } else if (aDescriptorType == HICMA_DESCRIPTOR) { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA return HicmaDescriptor::DestroyHicmaDescriptor(apDesc); #endif } diff --git a/src/data-units/descriptor/concrete/CMakeLists.txt b/src/data-units/descriptor/concrete/CMakeLists.txt index 291edada..6bb197d4 100644 --- a/src/data-units/descriptor/concrete/CMakeLists.txt +++ b/src/data-units/descriptor/concrete/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @brief CMake build script for the descriptors library, which includes the concrete implementations of the # Descriptors class based on the enabled libraries (HiCMA or Chameleon). # @author Mahmoud ElKarargy @@ -17,7 +17,7 @@ set(SOURCES ${SOURCES} ) -if (EXAGEOSTAT_USE_HICMA) +if (USE_HICMA) list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/HicmaDescriptor.cpp ) diff --git a/src/data-units/descriptor/concrete/ChameleonDescriptor.cpp b/src/data-units/descriptor/concrete/ChameleonDescriptor.cpp index 75984603..964215ec 100644 --- a/src/data-units/descriptor/concrete/ChameleonDescriptor.cpp +++ b/src/data-units/descriptor/concrete/ChameleonDescriptor.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ChameleonDescriptor.cpp * @brief Defines the ChameleonDescriptor class for creating matrix descriptors using the CHAMELEON library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-08-15 @@ -22,9 +22,9 @@ CHAM_desc_t *ChameleonDescriptor::CreateChameleonDescriptor(void *apDescripto const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, const int &aM, const int &aN, const int &aP, - const int &aQ) { + const int &aQ, const bool &aValidOOC) { auto chameleon_desc = (CHAM_desc_t *) apDescriptor; - if (aIsOOC && apMatrix == nullptr && aMB != 1 && aNB != 1) { + if (aIsOOC && apMatrix == nullptr && aMB != 1 && aNB != 1 && aValidOOC) { CHAMELEON_Desc_Create_OOC(&chameleon_desc, (cham_flttype_t) aFloatPoint, aMB, aNB, aSize, aLM, aLN, aI, aJ, aM, aN, aP, aQ); } else { diff --git a/src/data-units/descriptor/concrete/HicmaDescriptor.cpp b/src/data-units/descriptor/concrete/HicmaDescriptor.cpp index 8aa5f011..9a4e6724 100644 --- a/src/data-units/descriptor/concrete/HicmaDescriptor.cpp +++ b/src/data-units/descriptor/concrete/HicmaDescriptor.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file HicmaDescriptor.cpp * @brief Defines the Hicma Descriptor class for creating matrix descriptors using the HICMA library. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-08-15 @@ -20,9 +20,10 @@ HICMA_desc_t *HicmaDescriptor::CreateHicmaDescriptor(void *apDescriptor, cons const common::FloatPoint &aFloatPoint, const int &aMB, const int &aNB, const int &aSize, const int &aLM, const int &aLN, const int &aI, const int &aJ, const int &aM, - const int &aN, const int &aP, const int &aQ) { + const int &aN, const int &aP, const int &aQ, + const bool &aValidOOC) { auto hicma_desc = (HICMA_desc_t *) apDescriptor; - if (aIsOOC && apMatrix == nullptr && aMB != 1 && aNB != 1) { + if (aIsOOC && apMatrix == nullptr && aMB != 1 && aNB != 1 && aValidOOC) { HICMA_Desc_Create_OOC(&hicma_desc, (HICMA_enum) aFloatPoint, aMB, aNB, aSize, aLM, aLN, aI, aJ, aM, aN, aP, aQ); } else { HICMA_Desc_Create(&hicma_desc, apMatrix, (HICMA_enum) aFloatPoint, aMB, aNB, aSize, aLM, aLN, aI, aJ, aM, aN, diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt index 4d5f98f4..98fc7760 100644 --- a/src/hardware/CMakeLists.txt +++ b/src/hardware/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief This file contains the CMake configuration for the configurations directory. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-08-08 diff --git a/src/hardware/ExaGeoStatHardware.cpp b/src/hardware/ExaGeoStatHardware.cpp index 7419c4dc..3e9f3c18 100644 --- a/src/hardware/ExaGeoStatHardware.cpp +++ b/src/hardware/ExaGeoStatHardware.cpp @@ -1,104 +1,160 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ExaGeoStatHardware.cpp * @brief Contains the implementation of the ExaGeoStatHardware class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-08-07 + * @date 2024-02-04 **/ +#ifdef USE_MPI +#include +#endif + #include #include #include #include #include +#include +#include + +using namespace exageostat::common; +using namespace exageostat::results; + +ExaGeoStatHardware::ExaGeoStatHardware(const Computation &aComputation, const int &aCoreNumber, const int &aGpuNumber, + const int &aP, const int &aQ) { + InitHardware(aComputation, aCoreNumber, aGpuNumber, aP, aQ); +} -using namespace exageostat::hardware; +// Constructor for R +ExaGeoStatHardware::ExaGeoStatHardware(const std::string &aComputation, const int &aCoreNumber, const int &aGpuNumber, + const int &aP, const int &aQ) { + InitHardware(GetInputComputation(aComputation), aCoreNumber, aGpuNumber, aP, aQ); +} + +void ExaGeoStatHardware::InitHardware(const Computation &aComputation, const int &aCoreNumber, const int &aGpuNumber, + const int &aP, const int &aQ) { -ExaGeoStatHardware::ExaGeoStatHardware(const common::Computation &aComputation, const int &aCoreNumber, - const int &aGpuNumber) { + SetPGrid(aP); + SetQGrid(aQ); + int tag_width = 31, tag_sep = 40; - this->mComputation = aComputation; - int tag_width = 31, tag_sep = 26; // Init hardware using Chameleon - if (!this->mpChameleonContext) { + if (!mpChameleonContext) { +#ifdef USE_MPI + // Due to a bug in Chameleon if CHAMELEON_user_tag_size is called twice with MPI an error happens due to a static variable in chameleon that doesn't change. + if(!mIsMPIInit){ + CHAMELEON_user_tag_size(tag_width, tag_sep); + mIsMPIInit = true; + } +#else CHAMELEON_user_tag_size(tag_width, tag_sep); +#endif CHAMELEON_Init(aCoreNumber, aGpuNumber) - this->mpChameleonContext = chameleon_context_self(); + mpChameleonContext = chameleon_context_self(); } - // Init hardware using Hicma - if (aComputation == common::TILE_LOW_RANK) { -#ifdef EXAGEOSTAT_USE_HICMA - if (!this->mpHicmaContext) { + // Init hardware using HiCMA + if (aComputation == TILE_LOW_RANK) { +#ifdef USE_HICMA + if (!mpHicmaContext) { +#ifdef USE_MPI + // Due to a bug in HiCMA if HICMA_user_tag_size is called twice with MPI an error happens due to a static variable in HiCMA that doesn't change. + if(!mIsMPIInit){ + HICMA_user_tag_size(tag_width, tag_sep); + mIsMPIInit = true; + } +#else HICMA_user_tag_size(tag_width, tag_sep); +#endif HICMA_Init(aCoreNumber, aGpuNumber); - this->mpHicmaContext = hicma_context_self(); + mpHicmaContext = hicma_context_self(); } #else - throw std::runtime_error("You need to enable Hicma to use TLR computation!"); + throw std::runtime_error("You need to enable HiCMA to use TLR computation!"); #endif } - helpers::CommunicatorMPI::GetInstance()->SetHardwareInitialization(); + exageostat::helpers::CommunicatorMPI::GetInstance()->SetHardwareInitialization(); + LOGGER("** Initialize ExaGeoStat hardware **") } -ExaGeoStatHardware::~ExaGeoStatHardware() { - // finalize hardware using Hicma - // finalize hardware using Chameleon - if (!this->mpChameleonContext) { - std::cerr << "No initialized context of Chameleon, Please initialize a hardware first" << std::endl; - exit(1); - } else { - CHAMELEON_Finalize() - this->mpChameleonContext = nullptr; +void ExaGeoStatHardware::FinalizeHardware() { + + // finalize hardware using HiCMA +#ifdef USE_HICMA + if (mpHicmaContext) { + HICMA_Finalize(); + mpHicmaContext = nullptr; } - if (this->mComputation == common::TILE_LOW_RANK) { -#ifdef EXAGEOSTAT_USE_HICMA - if (!this->mpHicmaContext) { - std::cout - << "No initialized context of HiCMA, Please use 'ExaGeoStatHardware::ExaGeoStatHardware(aComputation, CoreNumber, aGpuNumber);'" - << std::endl; - } else { - HICMA_Finalize(); - this->mpHicmaContext = nullptr; - } #endif + + // finalize hardware using Chameleon + if (mpChameleonContext) { +#if defined(USE_MPI) && defined(USE_HICMA) + // Since already HiCMA do so, then no need to remove empty cache. + starpu_mpi_cache_set(0); +#endif + CHAMELEON_Finalize() + mpChameleonContext = nullptr; } - helpers::CommunicatorMPI::GetInstance()->RemoveHardwareInitialization(); - results::Results::GetInstance()->PrintEndSummary(); + + exageostat::helpers::CommunicatorMPI::GetInstance()->RemoveHardwareInitialization(); } -#ifdef EXAGEOSTAT_USE_HICMA +ExaGeoStatHardware::~ExaGeoStatHardware() { -void *ExaGeoStatHardware::GetHicmaContext() const { - if (!this->mpHicmaContext) { - throw std::runtime_error("Hardware is not initialized!"); - } - return this->mpHicmaContext; + Results::GetInstance()->PrintEndSummary(); + FinalizeHardware(); } -#endif +void *ExaGeoStatHardware::GetHicmaContext() { + if (!mpHicmaContext) { + throw std::runtime_error("HiCMA Hardware is not initialized!"); + } + return mpHicmaContext; +} -void *ExaGeoStatHardware::GetChameleonContext() const { - if (!this->mpChameleonContext) { - throw std::runtime_error("Hardware is not initialized!"); +void *ExaGeoStatHardware::GetChameleonContext() { + if (!mpChameleonContext) { + throw std::runtime_error("Chameleon Hardware is not initialized!"); } - return this->mpChameleonContext; + return mpChameleonContext; } -void *ExaGeoStatHardware::GetContext(common::Computation aComputation) const { - if (aComputation == common::EXACT_DENSE || aComputation == common::DIAGONAL_APPROX) { +void *ExaGeoStatHardware::GetContext(Computation aComputation) { + if (aComputation == EXACT_DENSE || aComputation == DIAGONAL_APPROX) { return GetChameleonContext(); } - if (aComputation == common::TILE_LOW_RANK) { -#ifdef EXAGEOSTAT_USE_HICMA + if (aComputation == TILE_LOW_RANK) { return GetHicmaContext(); -#endif } return nullptr; } + +int ExaGeoStatHardware::GetPGrid() { + return mPGrid; +} + +int ExaGeoStatHardware::GetQGrid() { + return mQGrid; +} + +void ExaGeoStatHardware::SetPGrid(int aP) { + mPGrid = aP; +} + +void ExaGeoStatHardware::SetQGrid(int aQ) { + mQGrid = aQ; +} + +void *ExaGeoStatHardware::mpChameleonContext = nullptr; +void *ExaGeoStatHardware::mpHicmaContext = nullptr; +int ExaGeoStatHardware::mPGrid = 1; +int ExaGeoStatHardware::mQGrid = 1; +bool ExaGeoStatHardware::mIsMPIInit = false; diff --git a/src/helpers/BasselFunction.cpp b/src/helpers/BasselFunction.cpp new file mode 100644 index 00000000..b0b58689 --- /dev/null +++ b/src/helpers/BasselFunction.cpp @@ -0,0 +1,44 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file BasselFunction + * @brief This file contains the BasselFunction class which provides methods for computing derivatives of the modified Bessel function of the second kind. These functions are crucial in statistical and mathematical computations, especially in fields such as geostatistics and spatial analysis. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-01-24 +**/ + +extern "C" { +#include +} + +#include + +using namespace exageostat::helpers; + +template +T BasselFunction::CalculateDerivativeBesselNu(const T &aOrder, const T &aInputValue) { + if (aOrder == 0) { + return 0; + } else { + // Use a small step size to calculate the derivative numerically + const T step_size = 0.000000001; + return (gsl_sf_bessel_Knu(aOrder + step_size, aInputValue) - gsl_sf_bessel_Knu(aOrder, aInputValue)) / + step_size; + } +} + +template +T BasselFunction::CalculateSecondDerivativeBesselNu(const T &aOrder, const T &aInputValue) { + return (-0.5 * (CalculateSecondDerivativeBesselNuInput(aOrder - 1, aInputValue) + + CalculateSecondDerivativeBesselNuInput(aOrder + 1, aInputValue))); +} + +template +T BasselFunction::CalculateSecondDerivativeBesselNuInput(const T &aOrder, const T &aInputValue) { + return (aOrder / aInputValue * gsl_sf_bessel_Knu(aOrder, aInputValue) - gsl_sf_bessel_Knu(aOrder + 1, aInputValue)); +} diff --git a/src/helpers/ByteHandler.cpp b/src/helpers/ByteHandler.cpp new file mode 100644 index 00000000..252858b0 --- /dev/null +++ b/src/helpers/ByteHandler.cpp @@ -0,0 +1,52 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ByteHandler.hpp + * @brief Implementation of byte manipulation functions for ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-01-24 +**/ + +#include + +namespace exageostat::helpers { + + uint64_t SpreadBits(uint64_t aInputByte) { + + aInputByte &= 0x000000000000ffff; + // aInputByte = ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- fedc ba98 7654 3210 + aInputByte = (aInputByte ^ (aInputByte << 24)) & 0x000000ff000000ff; + // aInputByte = ---- ---- ---- ---- ---- ---- fedc ba98 ---- ---- ---- ---- ---- ---- 7654 3210 + aInputByte = (aInputByte ^ (aInputByte << 12)) & 0x000f000f000f000f; //000 7000f000f000f + // aInputByte = ---- ---- ---- fedc ---- ---- ---- ba98 ---- ---- ---- 7654 ---- ---- ---- 3210 + aInputByte = (aInputByte ^ (aInputByte << 6)) & 0x0303030303030303; //0 0001 0 0011 0 0011 0 0011 0 + // aInputByte = ---- --fe ---- --dc ---- --ba ---- --98 ---- --76 ---- --54 ---- --32 ---- --10 + aInputByte = (aInputByte ^ (aInputByte << 3)) & 0x1111111111111111; + // aInputByte = ---f ---e ---d ---c ---b ---a ---9 ---8 ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0 + return aInputByte; + } + + uint64_t ReverseSpreadBits(uint64_t aInputByte) { + + aInputByte &= 0x1111111111111111; + // aInputByte = ---f ---e ---d ---c ---b ---a ---9 ---8 ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0 + aInputByte = (aInputByte ^ (aInputByte >> 3)) & 0x0303030303030303; + // aInputByte = ---- --fe ---- --dc ---- --ba ---- --98 ---- --76 ---- --54 ---- --32 ---- --10 + aInputByte = (aInputByte ^ (aInputByte >> 6)) & 0x000f000f000f000f; + // aInputByte = ---- ---- ---- fedc ---- ---- ---- ba98 ---- ---- ---- 7654 ---- ---- ---- 3210 + aInputByte = (aInputByte ^ (aInputByte >> 12)) & 0x000000ff000000ff; + // aInputByte = ---- ---- ---- ---- ---- ---- fedc ba98 ---- ---- ---- ---- ---- ---- 7654 3210 + aInputByte = (aInputByte ^ (aInputByte >> 24)) & 0x000000000000ffff; + // aInputByte = ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- fedc ba98 7654 3210 + return aInputByte; + } + + bool CompareUint64(const uint64_t &aFirstValue, const uint64_t &aSecondValue) { + return aFirstValue < aSecondValue; + } +} \ No newline at end of file diff --git a/src/helpers/CMakeLists.txt b/src/helpers/CMakeLists.txt index 5c01b62a..f2f6ef82 100644 --- a/src/helpers/CMakeLists.txt +++ b/src/helpers/CMakeLists.txt @@ -1,18 +1,19 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-06-08 set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/DiskWriter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DistanceCalculationHelpers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CommunicatorMPI.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ByteHandler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/BasselFunction.cpp ${SOURCES} PARENT_SCOPE ) \ No newline at end of file diff --git a/src/helpers/CommunicatorMPI.cpp b/src/helpers/CommunicatorMPI.cpp index 488f386a..0abc6d1c 100644 --- a/src/helpers/CommunicatorMPI.cpp +++ b/src/helpers/CommunicatorMPI.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file CommunicatorMPI.cpp * @brief Defines the CommunicatorMPI class for MPI rank communication. - * @version 1.0.0 + * @version 1.1.0 * @author Sameh Abdulah * @date 2023-11-10 **/ @@ -23,25 +23,24 @@ CommunicatorMPI *CommunicatorMPI::GetInstance() { return mpInstance; } -bool CommunicatorMPI::GetRank() const { - - if(!this->mIsHardwareInitialized){ - return false; - } - else{ - if(CHAMELEON_Comm_rank() == 0){ - return true; - } - return false; +int CommunicatorMPI::GetRank() const { +#ifdef USE_MPI + if (!mIsHardwareInitialized) { + return 0; + } else { + return CHAMELEON_Comm_rank(); } +#else + return 0; +#endif } void CommunicatorMPI::SetHardwareInitialization() { - this->mIsHardwareInitialized = true; + mIsHardwareInitialized = true; } -CommunicatorMPI *CommunicatorMPI::mpInstance = nullptr; - void CommunicatorMPI::RemoveHardwareInitialization() { - this->mIsHardwareInitialized = false; + mIsHardwareInitialized = false; } + +CommunicatorMPI *CommunicatorMPI::mpInstance = nullptr; diff --git a/src/helpers/DiskWriter.cpp b/src/helpers/DiskWriter.cpp deleted file mode 100644 index b168c634..00000000 --- a/src/helpers/DiskWriter.cpp +++ /dev/null @@ -1,114 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file DiskWriter.cpp - * @brief Contains the implementation of the DiskWriter class for writing data to disk. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-06-08 -**/ - -#include -#include -#include - -#include -using namespace std; - -using namespace exageostat::helpers; -using namespace exageostat::dataunits; - -template -void DiskWriter::WriteVectorsToDisk(const T &aMatrixPointer, const int &aProblemSize, const int &aP, - std::string &aLoggerPath, Locations &aLocations) { - - // Determine the path for storing the output files - if (aLoggerPath.empty()) { - aLoggerPath = LOG_PATH; - } else { - if (aLoggerPath.back() == '/') { - aLoggerPath += "synthetic_ds"; - } else { - aLoggerPath += "/synthetic_ds"; - } - } - // Create a new directory if it does not already exist - bool created; - if (!filesystem::exists(aLoggerPath)) { - try { - created = filesystem::create_directories(aLoggerPath); - } catch (const filesystem::filesystem_error &e) { - throw runtime_error("Error creating directory: " + aLoggerPath); - } - } else { - created = true; - } - - // Check if the directory was created successfully - if (!created) { - throw runtime_error("Error creating directory: " + aLoggerPath); - } - - // Determine the names of the output files - size_t i = 1, j; - std::ofstream p_file_synthetic, p_file_log; - std::string n_file_synthetic = aLoggerPath + "/SYN_" + std::to_string(aProblemSize / aP) + "_"; - std::string n_file_log = aLoggerPath + "/log_" + std::to_string(aProblemSize / aP) + "_"; - std::string temp = n_file_log + std::to_string(i); - - // Check if log file exists - while (std::filesystem::exists(temp)) { - i++; - temp = n_file_log + std::to_string(i); - } - - n_file_synthetic += std::to_string(i); - p_file_synthetic.open(n_file_synthetic); - - for (j = 0, i = 0; i < aProblemSize / aP; i++) { - if (aLocations.GetLocationZ() == nullptr) { - //2 Dimensions - if (aP == 1) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[i] - << '\n'; - } else if (aP == 2) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[j] << "," - << std::setprecision(15) << (&aMatrixPointer)[j + 1] << '\n'; - j += 2; - } else if (aP == 3) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << "," << std::setprecision(15) << (&aMatrixPointer)[j] << "," - << std::setprecision(15) << (&aMatrixPointer)[j + 1] << "," << std::setprecision(15) - << (&aMatrixPointer)[j + 2] << '\n'; - j += 3; - } - } else { - //3 Dimensions - if (aP == 1) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," - << std::setprecision(15) << (&aMatrixPointer)[i] << '\n'; - } else if (aP == 2) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," - << std::setprecision(15) << (&aMatrixPointer)[j] << std::setprecision(15) << "," - << (&aMatrixPointer)[j + 1] << '\n'; - j += 2; - } else if (aP == 3) { - p_file_synthetic << std::setprecision(15) << aLocations.GetLocationX()[i] << ',' - << aLocations.GetLocationY()[i] << ',' << aLocations.GetLocationZ()[i] << "," - << std::setprecision(15) << (&aMatrixPointer)[j] << "," << std::setprecision(15) - << (&aMatrixPointer)[j + 1] << "," << std::setprecision(15) << (&aMatrixPointer)[j + 2] - << '\n'; - j += 3; - } - } - } - p_file_synthetic.close(); -} diff --git a/src/helpers/DistanceCalculationHelpers.cpp b/src/helpers/DistanceCalculationHelpers.cpp index 9ca5d61c..65487536 100644 --- a/src/helpers/DistanceCalculationHelpers.cpp +++ b/src/helpers/DistanceCalculationHelpers.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file DistanceCalculationHelpers.cpp * @brief Contains the implementation of the DistanceCalculationHelpers class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -18,14 +18,14 @@ using namespace exageostat::helpers; -//convert degree to radian -static double DegreeToRadian(double aDegree) { +template +T DistanceCalculationHelpers::DegreeToRadian(T aDegree) { return (aDegree * PI / 180); } template T DistanceCalculationHelpers::DistanceEarth(T &aLatitude1, T &aLongitude1, T &aLatitude2, T &aLongitude2) { - double lat1r, lon1r, lat2r, lon2r, u, v; + T lat1r, lon1r, lat2r, lon2r, u, v; lat1r = DegreeToRadian(aLatitude1); lon1r = DegreeToRadian(aLongitude1); lat2r = DegreeToRadian(aLatitude2); diff --git a/src/kernels/CMakeLists.txt b/src/kernels/CMakeLists.txt index 6b89f681..1c6b67cd 100644 --- a/src/kernels/CMakeLists.txt +++ b/src/kernels/CMakeLists.txt @@ -1,38 +1,22 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt # @brief This file contains the CMake configuration for the kernels directory. -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-04-11 -# Add the Configurations.cpp file to the list of source files. +# Automatically add all kernels in the concrete directory. +file(GLOB ALL_KERNELS ${CMAKE_CURRENT_SOURCE_DIR}/concrete/*.cpp) + +# Add the kernel.cpp file to the list with other kernels. set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Kernel.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternNonStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/BivariateMaternFlexible.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/BivariateMaternParsimonious.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternNuggetsStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateSpacetimeMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDsigmaSquare.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDnu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDbeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdsigmaSquare.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdsigmaSquareBeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdsigmaSquareNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdbetaBeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdbetaNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternDdnuNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/BivariateSpacetimeMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternNonGaussian.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateExpNonGaussian.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TrivariateMaternParsimonious.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/UnivariateMaternNonStat.cpp + ${ALL_KERNELS} ${SOURCES} PARENT_SCOPE ) \ No newline at end of file diff --git a/src/kernels/Kernel.cpp b/src/kernels/Kernel.cpp index a238accb..931a9d97 100644 --- a/src/kernels/Kernel.cpp +++ b/src/kernels/Kernel.cpp @@ -1,74 +1,35 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Kernel.cpp * @brief implementation file for the Kernels class, which contains the main kernel functions. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-12 **/ -extern "C" { -#include -} - #include using namespace std; -using namespace exageostat::dataunits; using namespace exageostat::kernels; template -T Kernel::CalculateDerivativeBesselInputNu(const T &aOrder, const T &aInputValue) { - if (aOrder < 1) { - T nu_new = abs(aOrder - 1); - return (-0.5 * (-CalculateDerivativeBesselNu(nu_new, aInputValue) + - CalculateDerivativeBesselNu(abs(aOrder + 1), aInputValue))); - } else { - return (-0.5 * (CalculateDerivativeBesselNu(aOrder - 1, aInputValue) + - CalculateDerivativeBesselNu(abs(aOrder + 1), aInputValue))); - } -} - -template -T Kernel::CalculateDerivativeBesselNu(const T &aOrder, const T &aInputValue) { - if (aOrder == 0) { - return 0; - } else { - // Use a small step size to calculate the derivative numerically - const T step_size = 0.000000001; - return (gsl_sf_bessel_Knu(aOrder + step_size, aInputValue) - gsl_sf_bessel_Knu(aOrder, aInputValue)) / - step_size; - } -} - -template -T Kernel::CalculateSecondDerivativeBesselNu(const T &aOrder, const T &aInputValue) { - return (-0.5 * (CalculateSecondDerivativeBesselNuInput(aOrder - 1, aInputValue) + - CalculateSecondDerivativeBesselNuInput(aOrder + 1, aInputValue))); -} - -template -T Kernel::CalculateSecondDerivativeBesselNuInput(const T &aOrder, const T &aInputValue) { - return (aOrder / aInputValue * gsl_sf_bessel_Knu(aOrder, aInputValue) - gsl_sf_bessel_Knu(aOrder + 1, aInputValue)); -} - -template -int Kernel::GetPValue() const { - return this->mP; +int Kernel::GetVariablesNumber() const { + return this->mVariablesNumber; } template -void Kernel::SetPValue(int aP) { - // Each kernel has its own initial P value, But in case of used spacetime kernels then aP won't be equal to 1. +void Kernel::SetPValue(int aTimeSlot) { + // Each kernel has its own initial P value, But in case of used spacetime kernels then Time Slot won't be equal to 1. // In case of uni-variate spacetime P = 1 * time slot // In case of Bi-variate spacetime P = 2 * time slot - this->mP = this->mP * aP; + // P and timeslot will be constant with each created kernel, overriding the Calculated P value to handle case of calling the function multiple times. + this->mVariablesNumber = this->mP * aTimeSlot; } template diff --git a/src/kernels/concrete/BivariateMaternFlexible.cpp b/src/kernels/concrete/BivariateMaternFlexible.cpp index 1e9aedad..1ae4e414 100644 --- a/src/kernels/concrete/BivariateMaternFlexible.cpp +++ b/src/kernels/concrete/BivariateMaternFlexible.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateMaternFlexible.cpp * @brief Implementation of the BivariateMaternFlexible kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,9 +47,9 @@ BivariateMaternFlexible::GenerateCovarianceMatrix(T *apMatrixA, const int &aR int i, j; int i0 = aRowOffset; int j0; - double expr1, expr2, expr12; - double con1, con2, con12, scale12, rho, nu12, sigma_square11, sigma_square22; - double scale1 = aLocalTheta[0], scale2 = aLocalTheta[1], nu1 = aLocalTheta[4], nu2 = aLocalTheta[5]; + T expr1, expr2, expr12; + T con1, con2, con12, scale12, rho, nu12, sigma_square11, sigma_square22; + T scale1 = aLocalTheta[0], scale2 = aLocalTheta[1], nu1 = aLocalTheta[4], nu2 = aLocalTheta[5]; //Remark 1 (c) of Apanasovich et al. (2012) scale12 = pow(0.5 * (pow(scale1, -2) + pow(scale2, -2)) + aLocalTheta[2] * (1 - aLocalTheta[3]), -0.5); @@ -76,7 +76,7 @@ BivariateMaternFlexible::GenerateCovarianceMatrix(T *apMatrixA, const int &aR con12 = rho * con12; i0 /= 2; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i += 2) { j0 = aColumnOffset / 2; diff --git a/src/kernels/concrete/BivariateMaternParsimonious.cpp b/src/kernels/concrete/BivariateMaternParsimonious.cpp index 123f3b92..1a200997 100644 --- a/src/kernels/concrete/BivariateMaternParsimonious.cpp +++ b/src/kernels/concrete/BivariateMaternParsimonious.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateMaternParsimonious.cpp * @brief Implementation of the BivariateMaternParsimonious kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,8 +46,8 @@ void BivariateMaternParsimonious::GenerateCovarianceMatrix(T *apMatrixA, cons int i, j; int i0 = aRowOffset; int j0; - double expr; - double con1, con2, con12, rho, nu12; + T expr; + T con1, con2, con12, rho, nu12; con1 = pow(2, (aLocalTheta[3] - 1)) * tgamma(aLocalTheta[3]); con1 = 1.0 / con1; @@ -66,13 +66,13 @@ void BivariateMaternParsimonious::GenerateCovarianceMatrix(T *apMatrixA, cons con12 = rho * sqrt(aLocalTheta[0] * aLocalTheta[1]) * con12; i0 /= 2; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i += 2) { j0 = aColumnOffset / 2; for (j = 0; j < aColumnsNumber; j += 2) { expr = DistanceCalculationHelpers::CalculateDistance(aLocation1, aLocation2, i0, j0, aDistanceMetric, - flag) / aLocalTheta[2]; + 0) / aLocalTheta[2]; if (expr == 0) { apMatrixA[i + j * aRowsNumber] = aLocalTheta[0]; diff --git a/src/kernels/concrete/BivariateSpacetimeMaternStationary.cpp b/src/kernels/concrete/BivariateSpacetimeMaternStationary.cpp index 8ef95c6e..06693b34 100644 --- a/src/kernels/concrete/BivariateSpacetimeMaternStationary.cpp +++ b/src/kernels/concrete/BivariateSpacetimeMaternStationary.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file BivariateSpacetimeMaternStationary.cpp * @brief Implementation of the BivariateSpacetimeMaternStationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,9 +47,9 @@ BivariateSpacetimeMaternStationary::GenerateCovarianceMatrix(T *apMatrixA, co int i, j; int i0 = aRowOffset; int j0; - double z0, z1; - double expr, expr2, expr3, expr4; - double con1, con2, con12, rho, nu12; + T z0, z1; + T expr, expr2, expr3, expr4; + T con1, con2, con12, rho, nu12; con1 = pow(2, (aLocalTheta[3] - 1)) * tgamma(aLocalTheta[3]); con1 = 1.0 / con1; diff --git a/src/kernels/concrete/TrivariateMaternParsimonious.cpp b/src/kernels/concrete/TrivariateMaternParsimonious.cpp index a7de387b..628a7b6f 100644 --- a/src/kernels/concrete/TrivariateMaternParsimonious.cpp +++ b/src/kernels/concrete/TrivariateMaternParsimonious.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TrivariateMaternParsimonious.cpp * @brief Implementation of the BivariateMaternParsimonious kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,8 +46,8 @@ void TrivariateMaternParsimonious::GenerateCovarianceMatrix(T *apMatrixA, con int i, j; int i0 = aRowOffset; int j0; - double expr; - double con1, con2, con3, con12, con13, con23, rho12, rho13, rho23, nu12, nu13, nu23; + T expr; + T con1, con2, con3, con12, con13, con23, rho12, rho13, rho23, nu12, nu13, nu23; con1 = pow(2, (aLocalTheta[4] - 1)) * tgamma(aLocalTheta[4]); con1 = 1.0 / con1; @@ -88,13 +88,13 @@ void TrivariateMaternParsimonious::GenerateCovarianceMatrix(T *apMatrixA, con i0 /= 3; int matrix_size = aRowsNumber * aColumnsNumber; int index; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber - 1; i += 3) { j0 = aColumnOffset / 3; for (j = 0; j < aColumnsNumber - 1; j += 3) { expr = DistanceCalculationHelpers::CalculateDistance(aLocation1, aLocation2, i0, j0, aDistanceMetric, - flag) / aLocalTheta[3]; + 0) / aLocalTheta[3]; if (expr == 0) { diff --git a/src/kernels/concrete/UnivariateExpNonGaussian.cpp b/src/kernels/concrete/UnivariateExpNonGaussian.cpp index c785cc7b..1507d6ca 100644 --- a/src/kernels/concrete/UnivariateExpNonGaussian.cpp +++ b/src/kernels/concrete/UnivariateExpNonGaussian.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateExpNonGaussian.cpp * @brief Implementation of the UnivariateExpNonGaussian kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,16 +47,15 @@ UnivariateExpNonGaussian::GenerateCovarianceMatrix(T *apMatrixA, const int &a int i, j; int i0 = aRowOffset; int j0; - double expr; - double sigma_square = 1; - int flag = 0; + T expr; + T sigma_square = 1; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; for (j = 0; j < aColumnsNumber; j++) { expr = DistanceCalculationHelpers::CalculateDistance(aLocation1, aLocation2, i0, j0, aDistanceMetric, flag) / aLocalTheta[0]; - if (expr == 0) { apMatrixA[i + j * aRowsNumber] = sigma_square; } else { diff --git a/src/kernels/concrete/UnivariateMaternDbeta.cpp b/src/kernels/concrete/UnivariateMaternDbeta.cpp index 27137dee..6ebaf025 100644 --- a/src/kernels/concrete/UnivariateMaternDbeta.cpp +++ b/src/kernels/concrete/UnivariateMaternDbeta.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDbeta.cpp * @brief Implementation of the UnivariateMaternDbeta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,13 +46,13 @@ void UnivariateMaternDbeta::GenerateCovarianceMatrix(T *apMatrixA, const int int i, j; int i0 = aRowOffset; int j0; - double expr; - double beta_expr; - double con; - double sigma_square = aLocalTheta[0]; + T expr; + T beta_expr; + T con; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; diff --git a/src/kernels/concrete/UnivariateMaternDdbetaBeta.cpp b/src/kernels/concrete/UnivariateMaternDdbetaBeta.cpp index b2d4d4e7..36ae025b 100644 --- a/src/kernels/concrete/UnivariateMaternDdbetaBeta.cpp +++ b/src/kernels/concrete/UnivariateMaternDdbetaBeta.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdbetaBeta.cpp * @brief Implementation of the UnivariateMaternDdbetaBeta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,14 +47,14 @@ UnivariateMaternDdbetaBeta::GenerateCovarianceMatrix(T *apMatrixA, const int int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double beta_expr; - double beta_expr_prime; - double sigma_square = aLocalTheta[0]; + T expr; + T con; + T beta_expr; + T beta_expr_prime; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; diff --git a/src/kernels/concrete/UnivariateMaternDdbetaNu.cpp b/src/kernels/concrete/UnivariateMaternDdbetaNu.cpp index 7d2b036e..955ae083 100644 --- a/src/kernels/concrete/UnivariateMaternDdbetaNu.cpp +++ b/src/kernels/concrete/UnivariateMaternDdbetaNu.cpp @@ -1,19 +1,18 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdbetaNu.cpp * @brief Implementation of the UnivariateMaternDdbetaNu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,14 +46,14 @@ UnivariateMaternDdbetaNu::GenerateCovarianceMatrix(T *apMatrixA, const int &a int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double nu_expr; - double nu_expr_prime; - double sigma_square = aLocalTheta[0]; + T expr; + T con; + T nu_expr; + T nu_expr_prime; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; @@ -98,7 +97,7 @@ UnivariateMaternDdbetaNu::GenerateCovarianceMatrix(T *apMatrixA, const int &a aLocalTheta[2] + 1, expr)) + pow(expr, aLocalTheta[2]) * - this->CalculateSecondDerivativeBesselNuInput( + BasselFunction::CalculateSecondDerivativeBesselNuInput( aLocalTheta[2], expr))); apMatrixA[i + j * aRowsNumber] = (-1 / aLocalTheta[1] * (con * pow(expr, aLocalTheta[2]) * gsl_sf_bessel_Knu(aLocalTheta[2], expr)) - diff --git a/src/kernels/concrete/UnivariateMaternDdnuNu.cpp b/src/kernels/concrete/UnivariateMaternDdnuNu.cpp index fd884838..2869e0fb 100644 --- a/src/kernels/concrete/UnivariateMaternDdnuNu.cpp +++ b/src/kernels/concrete/UnivariateMaternDdnuNu.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdnuNu.cpp * @brief Implementation of the UnivariateMaternDdnuNu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,14 +47,14 @@ UnivariateMaternDdnuNu::GenerateCovarianceMatrix(T *apMatrixA, const int &aRo int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double nu_expr; - double nu_expr_dprime; - double sigma_square = aLocalTheta[0]; + T expr; + T con; + T nu_expr; + T nu_expr_dprime; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; @@ -72,22 +72,23 @@ UnivariateMaternDdnuNu::GenerateCovarianceMatrix(T *apMatrixA, const int &aRo (pow(expr, aLocalTheta[2]) * log(expr) * gsl_sf_bessel_Knu(aLocalTheta[2], expr) + pow(expr, aLocalTheta[2]) * - this->CalculateDerivativeBesselNu(aLocalTheta[2], - expr))); + BasselFunction::CalculateDerivativeBesselNu( + aLocalTheta[2], + expr))); nu_expr_dprime = (1 - aLocalTheta[2]) * 1 / pow(2, aLocalTheta[2]) * 1 / tgamma(aLocalTheta[2]) * - pow(expr, aLocalTheta[2]) * this->CalculateDerivativeBesselNu(aLocalTheta[2], expr) + + pow(expr, aLocalTheta[2]) * + BasselFunction::CalculateDerivativeBesselNu(aLocalTheta[2], expr) + pow(2, 1 - aLocalTheta[2]) * (-1 / tgamma(aLocalTheta[2]) * gsl_sf_psi(aLocalTheta[2]) * pow(expr, aLocalTheta[2]) * - this->CalculateDerivativeBesselNu(aLocalTheta[2], expr) + 1 / tgamma(aLocalTheta[2]) * - (pow(expr, aLocalTheta[2]) * - log(expr) * - this->CalculateDerivativeBesselNu( - aLocalTheta[2], - expr) + - pow(expr, aLocalTheta[2]) * - this->CalculateSecondDerivativeBesselNu( - aLocalTheta[2], - expr))); + BasselFunction::CalculateDerivativeBesselNu(aLocalTheta[2], expr) + + 1 / tgamma(aLocalTheta[2]) * + (pow(expr, aLocalTheta[2]) * + log(expr) * + BasselFunction::CalculateDerivativeBesselNu( + aLocalTheta[2], + expr) + + pow(expr, aLocalTheta[2]) * + BasselFunction::CalculateSecondDerivativeBesselNu(aLocalTheta[2], expr))); apMatrixA[i + j * aRowsNumber] = (-0.5 * con * pow(expr, aLocalTheta[2]) * gsl_sf_bessel_Knu(aLocalTheta[2], expr) + (1 - aLocalTheta[2]) / 2 * nu_expr - diff --git a/src/kernels/concrete/UnivariateMaternDdsigmaSquare.cpp b/src/kernels/concrete/UnivariateMaternDdsigmaSquare.cpp index af410d57..600c8c5f 100644 --- a/src/kernels/concrete/UnivariateMaternDdsigmaSquare.cpp +++ b/src/kernels/concrete/UnivariateMaternDdsigmaSquare.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquare.cpp * @brief Implementation of the UnivariateMaternDdsigmaSquare kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 @@ -44,8 +44,8 @@ void UnivariateMaternDdsigmaSquare::GenerateCovarianceMatrix(T *apMatrixA, co int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; + T expr; + T con; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; diff --git a/src/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.cpp b/src/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.cpp index 579d1dcc..2111d1d0 100644 --- a/src/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.cpp +++ b/src/kernels/concrete/UnivariateMaternDdsigmaSquareBeta.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquareBeta.cpp * @brief Implementation of the UnivariateMaternDdsigmaSquareBeta kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,12 +46,12 @@ void UnivariateMaternDdsigmaSquareBeta::GenerateCovarianceMatrix(T *apMatrixA int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double beta_expr; + T expr; + T con; + T beta_expr; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; diff --git a/src/kernels/concrete/UnivariateMaternDdsigmaSquareNu.cpp b/src/kernels/concrete/UnivariateMaternDdsigmaSquareNu.cpp index 7563c676..20f2e7de 100644 --- a/src/kernels/concrete/UnivariateMaternDdsigmaSquareNu.cpp +++ b/src/kernels/concrete/UnivariateMaternDdsigmaSquareNu.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDdsigmaSquareNu.cpp * @brief Implementation of the UnivariateMaternDdsigmaSquareNu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,9 +46,9 @@ void UnivariateMaternDdsigmaSquareNu::GenerateCovarianceMatrix(T *apMatrixA, int i, j; int i0 = aRowOffset; int j0; - double expr; - double nu_expr; - int flag = 0; + T expr; + T nu_expr; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; diff --git a/src/kernels/concrete/UnivariateMaternDnu.cpp b/src/kernels/concrete/UnivariateMaternDnu.cpp index 8830f0f8..9fe8dd67 100644 --- a/src/kernels/concrete/UnivariateMaternDnu.cpp +++ b/src/kernels/concrete/UnivariateMaternDnu.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDnu.cpp * @brief Implementation of the UnivariateMaternDnu kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,10 +46,10 @@ void UnivariateMaternDnu::GenerateCovarianceMatrix(T *apMatrixA, const int &a int i, j; int i0 = aRowOffset; int j0; - double expr; - double nu_expr; - double sigma_square = aLocalTheta[0]; - int flag = 0; + T expr; + T nu_expr; + T sigma_square = aLocalTheta[0]; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; @@ -68,7 +68,8 @@ void UnivariateMaternDnu::GenerateCovarianceMatrix(T *apMatrixA, const int &a (pow(expr, aLocalTheta[2]) * log(expr) * gsl_sf_bessel_Knu(aLocalTheta[2], expr) + pow(expr, aLocalTheta[2]) * - Kernel::CalculateDerivativeBesselNu(aLocalTheta[2], expr))); + BasselFunction::CalculateDerivativeBesselNu( + aLocalTheta[2], expr))); apMatrixA[i + j * aRowsNumber] = sigma_square * nu_expr; } j0++; diff --git a/src/kernels/concrete/UnivariateMaternDsigmaSquare.cpp b/src/kernels/concrete/UnivariateMaternDsigmaSquare.cpp index f48bd9b0..d4e7ec77 100644 --- a/src/kernels/concrete/UnivariateMaternDsigmaSquare.cpp +++ b/src/kernels/concrete/UnivariateMaternDsigmaSquare.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternDsigmaSquare.cpp * @brief Implementation of the UnivariateMaternDsigmaSquare kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @author Suhas Shankar @@ -15,7 +15,7 @@ **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -47,12 +47,12 @@ void UnivariateMaternDsigmaSquare::GenerateCovarianceMatrix(T *apMatrixA, con int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; + T expr; + T con; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; for (j = 0; j < aColumnsNumber; j++) { diff --git a/src/kernels/concrete/UnivariateMaternNonGaussian.cpp b/src/kernels/concrete/UnivariateMaternNonGaussian.cpp index 2a10db0f..070a1e70 100644 --- a/src/kernels/concrete/UnivariateMaternNonGaussian.cpp +++ b/src/kernels/concrete/UnivariateMaternNonGaussian.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternNonGaussian.cpp * @brief Implementation of the UnivariateMaternNonGaussian kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,14 +46,14 @@ void UnivariateMaternNonGaussian::GenerateCovarianceMatrix(T *apMatrixA, cons int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double sigma_square = 1; + T expr; + T con; + T sigma_square = 1; con = pow(2, (aLocalTheta[1] - 1)) * tgamma(aLocalTheta[1]); con = 1.0 / con; con = sigma_square * con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; for (i = 0; i < aRowsNumber; i++) { j0 = aColumnOffset; diff --git a/src/kernels/concrete/UnivariateMaternNonStat.cpp b/src/kernels/concrete/UnivariateMaternNonStat.cpp deleted file mode 100644 index b2ee916f..00000000 --- a/src/kernels/concrete/UnivariateMaternNonStat.cpp +++ /dev/null @@ -1,145 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file UnivariateMaternNonStat.cpp - * @brief Implementation of the UnivariateMaternNonStat kernel. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-04-14 -**/ - -#include - -using namespace exageostat::kernels; -using namespace exageostat::dataunits; - -template -UnivariateMaternNonStat::UnivariateMaternNonStat() { - this->mP = 1; - this->mParametersNumber = 8; -} - -template -Kernel *UnivariateMaternNonStat::Create() { - KernelsConfigurations::GetParametersNumberKernelMap()["UnivariateMaternNonStat"] = 8; - return new UnivariateMaternNonStat(); -} - -namespace exageostat::kernels { - template bool UnivariateMaternNonStat::plugin_name = plugins::PluginRegistry>::Add( - "UnivariateMaternNonStat", UnivariateMaternNonStat::Create); -} - -template -void -UnivariateMaternNonStat::GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, - const int &aRowOffset, const int &aColumnOffset, - Locations &aLocation1, Locations &aLocation2, - Locations &aLocation3, T *aLocalTheta, - const int &aDistanceMetric) { - - double l1x, l1y, l2x, l2y; - double a, b, d, e, f, g, h, ti; - a = aLocalTheta[0]; - b = aLocalTheta[1]; - d = aLocalTheta[2]; - e = aLocalTheta[3]; - f = aLocalTheta[4]; - g = aLocalTheta[5]; - h = aLocalTheta[6]; - ti = aLocalTheta[7]; - - double nu_arr_1[aRowsNumber]; - double sigma_arr_1[aRowsNumber]; - double lambda_arr_1[aRowsNumber]; - double nu_arr_2[aColumnsNumber]; - double sigma_arr_2[aColumnsNumber]; - double lambda_arr_2[aColumnsNumber]; - double term1; - double term2; - double neuij; - double Qij; - double prod1; - double term3; - - for (int i = 0; i < aRowsNumber; i++) { - l1x = aLocation1.GetLocationX()[i + aRowOffset]; - l1y = aLocation1.GetLocationY()[i + aRowOffset]; - nu_arr_1[i] = Neu(l1x, l1y, g, h, ti); - sigma_arr_1[i] = Sigma(l1x, l1y, d, e, f); - lambda_arr_1[i] = Lambda(l1x, l1y, a, b); - } - - for (int j = 0; j < aColumnsNumber; j++) { - l2x = aLocation2.GetLocationX()[j + aColumnOffset]; - l2y = aLocation2.GetLocationY()[j + aColumnOffset]; - - nu_arr_2[j] = Neu(l2x, l2y, g, h, ti); - sigma_arr_2[j] = Sigma(l2x, l2y, d, e, f); - lambda_arr_2[j] = Lambda(l2x, l2y, a, b); - } - - for (int i = 0; i < aRowsNumber; i++) { - l1x = aLocation1.GetLocationX()[i + aRowOffset]; - l1y = aLocation1.GetLocationY()[i + aRowOffset]; - - for (int j = 0; j < aColumnsNumber; j++) { - l2x = aLocation2.GetLocationX()[j + aColumnOffset]; - l2y = aLocation2.GetLocationY()[j + aColumnOffset]; - term1 = (sigma_arr_1[i]) * (sigma_arr_2[j]) * sqrt(lambda_arr_1[i]) * sqrt(lambda_arr_2[j]); - term2 = 2 / ((lambda_arr_1[i]) + (lambda_arr_2[j])); - neuij = ((nu_arr_1[i]) + (nu_arr_2[j])) / 2; - Qij = CalculateMahalanobisDistanceSquared(l1x, l1y, l2x, l2y, term2, 0, 0, term2); - prod1 = 2 * sqrt(neuij * Qij); - term3 = MaternUtil(1, neuij, prod1); - apMatrixA[i + j * aRowsNumber] = term1 * term2 * term3; - } - } -} - -template -double UnivariateMaternNonStat::Neu(double x, double y, double g, double h, double ti) { - return (g * pow(POW_e, h * (x + y)) + ti); -} - -template -double UnivariateMaternNonStat::Sigma(double x, double y, double d, double e, double f) { - return (d * pow(POW_e, e * (x + y)) + f); -} - -template -double UnivariateMaternNonStat::Lambda(double x, double y, double a, double b) { - return (a * pow(POW_e, sin(b * x) + sin(b * y))); -} - -template -double -UnivariateMaternNonStat::CalculateMahalanobisDistanceSquared(double x1, double y1, double x2, double y2, double a11, - double a12, double a21, double a22) { - - double diffx = x1 - x2; - double diffy = y1 - y2; - double el1 = a11 * diffx + a21 * diffy; - double el2 = a12 * diffx + a22 * diffy; - double ans = el1 * diffx + el2 * diffy; - - return ans; -} - -template -double UnivariateMaternNonStat::MaternUtil(double range, double smoothness, double distance) { - double con; - con = pow(2, (smoothness - 1)) * tgamma(smoothness); - con = 1.0 / con; - - if (distance == 0) { - return 1; - } else { - // Matern Function - return con * pow(distance / range, smoothness) * gsl_sf_bessel_Knu(smoothness, distance / range); - } -} \ No newline at end of file diff --git a/src/kernels/concrete/UnivariateMaternNonStationary.cpp b/src/kernels/concrete/UnivariateMaternNonStationary.cpp deleted file mode 100644 index 72b47001..00000000 --- a/src/kernels/concrete/UnivariateMaternNonStationary.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file UnivariateMaternNonStationary.cpp - * @brief Implementation of the UnivariateMaternNonStationary kernel. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-04-13 -**/ - -#include -#include - -using namespace exageostat::kernels; -using namespace exageostat::dataunits; -using namespace exageostat::helpers; - -template -UnivariateMaternNonStationary::UnivariateMaternNonStationary() { - this->mP = 1; - this->mParametersNumber = 9; -} - -template -Kernel *UnivariateMaternNonStationary::Create() { - KernelsConfigurations::GetParametersNumberKernelMap()["UnivariateMaternNonStationary"] = 9; - return new UnivariateMaternNonStationary(); -} - -namespace exageostat::kernels { - template bool UnivariateMaternNonStationary::plugin_name = plugins::PluginRegistry>::Add( - "UnivariateMaternNonStationary", UnivariateMaternNonStationary::Create); -} - -template -void UnivariateMaternNonStationary::GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, - const int &aColumnsNumber, const int &aRowOffset, - const int &aColumnOffset, Locations &aLocation1, - Locations &aLocation2, Locations &aLocation3, - T *aLocalTheta, const int &aDistanceMetric) { - - double location1X, location1Y, location2X, location2Y, location3X, location3Y; - double theta_0i, theta_0j, theta_1i, theta_1j, theta_2i, theta_2j; - double dx, dy; - double dist; - double con, sigma_square, beta, nu; - int i, j; - - aLocation3 = aLocation1; - double x_max = aLocation1->GetLocationX()[0]; - double x_min = aLocation1->GetLocationX()[0]; - double y_max = aLocation1->GetLocationY()[0]; - double y_min = aLocation1->GetLocationY()[0]; - for (i = 1; i < 9; i++) { - if (x_max < aLocation1->GetLocationX()[i]) - x_max = aLocation1->GetLocationX()[i]; - if (x_min > aLocation1->GetLocationX()[i]) - x_min = aLocation1->GetLocationX()[i]; - if (y_max < aLocation1->GetLocationY()[i]) - y_max = aLocation1->GetLocationY()[i]; - if (y_max > aLocation1->GetLocationY()[i]) - y_max = aLocation1->GetLocationY()[i]; - } - - aLocation3->GetLocationX()[0] = x_min + (x_max - x_min) / 2; - aLocation3->GetLocationY()[0] = y_min + (y_max - y_min) / 2; - LOGGER(" The central point is ( %f, %f)\n", aLocation3->GetLocationX()[0], aLocation3->GetLocationY()[0]); - - // Compute the covariance matrix elements - for (j = 0; j < aColumnsNumber; j++) { - location1X = aLocation1->GetLocationX()[aColumnOffset + j]; - location1Y = aLocation1->GetLocationY()[aColumnOffset + j]; - location3X = aLocation3->GetLocationX()[j]; - location3Y = aLocation3->GetLocationY()[j]; - dx = abs(location1X - location3X); - dy = abs(location1Y - location3Y); - - theta_0i = aLocalTheta[0] + (aLocalTheta[1] * dx) + (aLocalTheta[2] * dy); - theta_1i = aLocalTheta[3] + (aLocalTheta[4] * dx) + (aLocalTheta[5] * dy); - theta_2i = aLocalTheta[6] + (aLocalTheta[7] * dx) + (aLocalTheta[8] * dy); - - for (i = 0; i < aRowsNumber; i++) { - location2X = aLocation2->GetLocationX()[aRowOffset + i]; - location2Y = aLocation2->GetLocationY()[aRowOffset + i]; - location3X = aLocation3->GetLocationX()[i]; - location3Y = aLocation3->GetLocationY()[i]; - dx = abs(location2X - location3X); - dy = abs(location2Y - location3Y); - - theta_0j = aLocalTheta[0] + (aLocalTheta[1] * dx) + (aLocalTheta[2] * dy); - theta_1j = aLocalTheta[3] + (aLocalTheta[4] * dx) + (aLocalTheta[5] * dy); - theta_2j = aLocalTheta[6] + (aLocalTheta[7] * dx) + (aLocalTheta[8] * dy); - - // Compute the Matérn parameters and distance metric - sigma_square = (theta_0i + theta_0j) / 2; - beta = (theta_1i + theta_1j) / 2; - nu = (theta_2i + theta_2j) / 2; - con = pow(2, (nu - 1)) / tgamma(nu); - - con = 1.0 / con; - con = sigma_square * con; - int flag = 0; - - //MLE calculation - dist = DistanceCalculationHelpers::CalculateDistance(aLocation1, aLocation2, i, j, aDistanceMetric, - flag) / beta; - *(apMatrixA + i + j * aRowsNumber) = (dist == 0.0) ? sigma_square : con * pow(dist, nu) * - gsl_sf_bessel_Knu(nu, dist); - } - } -} diff --git a/src/kernels/concrete/UnivariateMaternNuggetsStationary.cpp b/src/kernels/concrete/UnivariateMaternNuggetsStationary.cpp index d2729283..ab960043 100644 --- a/src/kernels/concrete/UnivariateMaternNuggetsStationary.cpp +++ b/src/kernels/concrete/UnivariateMaternNuggetsStationary.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternNuggetsStationary.cpp * @brief Implementation of the UnivariateMaternNuggetsStationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -46,14 +46,14 @@ void UnivariateMaternNuggetsStationary::GenerateCovarianceMatrix(T *apMatrixA int i, j; int i0 = aRowOffset; int j0; - double expr; - double con; - double sigma_square = aLocalTheta[0]; + T expr; + T con; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; con = sigma_square * con; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; if (aLocation1.GetLocationZ() == nullptr || aLocation2.GetLocationZ() == nullptr) { for (i = 0; i < aRowsNumber; i++) { diff --git a/src/kernels/concrete/UnivariateMaternStationary.cpp b/src/kernels/concrete/UnivariateMaternStationary.cpp index 4fe9c1aa..790d9888 100644 --- a/src/kernels/concrete/UnivariateMaternStationary.cpp +++ b/src/kernels/concrete/UnivariateMaternStationary.cpp @@ -1,19 +1,19 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateMaternStationary.cpp * @brief Implementation of the UnivariateMaternStationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 **/ #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -48,7 +48,7 @@ UnivariateMaternStationary::GenerateCovarianceMatrix(T *apMatrixA, const int const T nu = aLocalTheta[2]; const T inv_con = sigma_square * (1.0 / (pow(2, (nu - 1)) * tgamma((nu)))); int i0 = aRowOffset; - int flag = 0; + int flag = aLocation1.GetLocationZ() == nullptr ? 0 : 1; int j0; int i, j; T dist; diff --git a/src/kernels/concrete/UnivariatePowExpStationary.cpp b/src/kernels/concrete/UnivariatePowExpStationary.cpp new file mode 100644 index 00000000..e4fa247f --- /dev/null +++ b/src/kernels/concrete/UnivariatePowExpStationary.cpp @@ -0,0 +1,67 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file UnivariatePowExpStationary.cpp + * @brief Implementation of the UnivariatePowExpStationary kernel. + * @version 1.1.0 + * @author Sameh Abdulah + * @author Mahmoud ElKarargy + * @date 2023-04-14 +**/ + +#include +#include + +using namespace exageostat::kernels; +using namespace exageostat::dataunits; +using namespace exageostat::helpers; + +template +UnivariatePowExpStationary::UnivariatePowExpStationary() { + this->mP = 1; + this->mParametersNumber = 3; +} + +template +Kernel *UnivariatePowExpStationary::Create() { + KernelsConfigurations::GetParametersNumberKernelMap()["UnivariatePowExpStationary"] = 3; + return new UnivariatePowExpStationary(); +} + +namespace exageostat::kernels { + template bool UnivariatePowExpStationary::plugin_name = plugins::PluginRegistry>::Add( + "UnivariatePowExpStationary", UnivariatePowExpStationary::Create); +} + +template +void +UnivariatePowExpStationary::GenerateCovarianceMatrix(T *apMatrixA, const int &aRowsNumber, const int &aColumnsNumber, + const int &aRowOffset, const int &aColumnOffset, + Locations &aLocation1, Locations &aLocation2, + Locations &aLocation3, T *aLocalTheta, + const int &aDistanceMetric) { + + const T sigma_square = aLocalTheta[0]; + const T nu = aLocalTheta[2]; + int i0 = aRowOffset; + int flag = 0; + int j0; + int i, j; + T dist; + + for (i = 0; i < aRowsNumber; i++) { + j0 = aColumnOffset; + for (j = 0; j < aColumnsNumber; j++) { + dist = DistanceCalculationHelpers::CalculateDistance(aLocation1, aLocation2, i0, j0, aDistanceMetric, + flag); + dist = pow(dist, nu); + *(apMatrixA + i + j * aRowsNumber) = (dist == 0.0) ? sigma_square : sigma_square * + exp(-(dist / aLocalTheta[1])); + j0++; + } + i0++; + } +} diff --git a/src/kernels/concrete/UnivariateSpacetimeMaternStationary.cpp b/src/kernels/concrete/UnivariateSpacetimeMaternStationary.cpp index 1eb5d63f..38ab7a9e 100644 --- a/src/kernels/concrete/UnivariateSpacetimeMaternStationary.cpp +++ b/src/kernels/concrete/UnivariateSpacetimeMaternStationary.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file UnivariateSpacetimeMaternStationary.cpp * @brief Implementation of the UnivariateSpacetimeMaternStationary kernel. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-14 @@ -17,7 +17,7 @@ #include #include -#include + using namespace exageostat::kernels; using namespace exageostat::dataunits; @@ -51,10 +51,10 @@ UnivariateSpacetimeMaternStationary::GenerateCovarianceMatrix(T *apMatrixA, c int i, j; int i0 = aRowOffset; int j0; - double z0, z1; - double expr, expr2, expr3, expr4; - double con; - double sigma_square = aLocalTheta[0]; + T z0, z1; + T expr, expr2, expr3, expr4; + T con; + T sigma_square = aLocalTheta[0]; con = pow(2, (aLocalTheta[2] - 1)) * tgamma(aLocalTheta[2]); con = 1.0 / con; diff --git a/src/linear-algebra-solvers/CMakeLists.txt b/src/linear-algebra-solvers/CMakeLists.txt index d3aea1ca..8a9eba80 100644 --- a/src/linear-algebra-solvers/CMakeLists.txt +++ b/src/linear-algebra-solvers/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @brief CMake build script for the linear-algebra-solvers library, which includes the LinearAlgebraMethods base class and the LinearAlgebraFactory class for creating linear algebra solvers for different computations using HiCMA or Chameleon libraries. # @author Mahmoud ElKarargy # @author Sameh Abdulah diff --git a/src/linear-algebra-solvers/LinearAlgebraFactory.cpp b/src/linear-algebra-solvers/LinearAlgebraFactory.cpp index ec759d52..0d72dbad 100644 --- a/src/linear-algebra-solvers/LinearAlgebraFactory.cpp +++ b/src/linear-algebra-solvers/LinearAlgebraFactory.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Implementation of the LinearAlgebraFactory class for creating linear algebra solvers for different computations using HiCMA or Chameleon libraries. * The factory creates a unique pointer to a concrete implementation of the LinearAlgebraMethods class based on the computation specified. * If the required library is not enabled, it throws a runtime_error exception. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-03-20 **/ @@ -16,18 +16,17 @@ #include -#include -#include +#include +#include -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA -#include +#include #endif using namespace exageostat::linearAlgebra; using namespace exageostat::common; -using namespace exageostat::configurations; template std::unique_ptr> LinearAlgebraFactory::CreateLinearAlgebraSolver(Computation aComputation) { @@ -35,19 +34,19 @@ std::unique_ptr> LinearAlgebraFactory::CreateLinearAl // Check the used Linear Algebra solver library, whether it's HiCMA or Chameleon. if (aComputation == EXACT_DENSE) { - return std::make_unique>(); + return std::make_unique>(); } // HiCMA Used else if (aComputation == TILE_LOW_RANK) { -#ifdef EXAGEOSTAT_USE_HICMA +#ifdef USE_HICMA return std::make_unique>(); #else throw std::runtime_error( - "Tile low rank generation isn't supported without enabling HiCMA. Use -DEXAGEOSTAT_USE_HICMA=ON"); + "Tile low rank generation isn't supported without enabling HiCMA. Use -DUSE_HICMA=ON"); #endif } else if (aComputation == DIAGONAL_APPROX) { - return std::make_unique>(); + return std::make_unique>(); } // Return nullptr if no computation is selected diff --git a/src/linear-algebra-solvers/LinearAlgebraMethods.cpp b/src/linear-algebra-solvers/LinearAlgebraMethods.cpp index 5cf36748..f2d98acb 100644 --- a/src/linear-algebra-solvers/LinearAlgebraMethods.cpp +++ b/src/linear-algebra-solvers/LinearAlgebraMethods.cpp @@ -1,23 +1,27 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file LinearAlgebraMethods.cpp * @brief Implementation of linear algebra methods. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-03-20 + * @date 2024-02-04 **/ #ifdef USE_MPI + #include + #endif + #include #include +#include using namespace std; @@ -25,24 +29,25 @@ using namespace exageostat::linearAlgebra; using namespace exageostat::common; using namespace exageostat::dataunits; using namespace exageostat::configurations; -using namespace exageostat::hardware; +using namespace exageostat::runtime; +using namespace exageostat::results; // Define a method to set up the Chameleon descriptors template void LinearAlgebraMethods::InitiateDescriptors(Configurations &aConfigurations, DescriptorData &aDescriptorData, - T *apMeasurementsMatrix) { + const int &aP, T *apMeasurementsMatrix) { // Check for initialize the Chameleon context. - if (!this->mpContext) { + if (!ExaGeoStatHardware::GetChameleonContext()) { throw std::runtime_error( "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); } // Get the problem size and other configuration parameters - int n = aConfigurations.GetProblemSize(); + int full_problem_size = aConfigurations.GetProblemSize() * aP; int dts = aConfigurations.GetDenseTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); bool is_OOC = aConfigurations.GetIsOOC(); // Create a Chameleon sequence, if not initialized before through the same descriptors @@ -65,57 +70,69 @@ void LinearAlgebraMethods::InitiateDescriptors(Configurations &aConfiguration } aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C, is_OOC, nullptr, float_point, dts, dts, - dts * dts, n, n, 0, 0, n, n, p_grid, q_grid); + dts * dts, full_problem_size, full_problem_size, 0, 0, full_problem_size, + full_problem_size, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z, is_OOC, apMeasurementsMatrix, float_point, - dts, dts, dts * dts, n, 1, 0, 0, n, 1, p_grid, q_grid); + dts, dts, dts * dts, full_problem_size, 1, 0, 0, full_problem_size, 1, p_grid, + q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_COPY, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n, 1, 0, 0, n, 1, p_grid, q_grid); + dts, dts * dts, full_problem_size, 1, 0, 0, full_problem_size, 1, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_DETERMINANT, is_OOC, nullptr, float_point, - dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid, false); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT, is_OOC, nullptr, float_point, dts, - dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid, false); if (float_point == EXAGEOSTAT_REAL_DOUBLE) { auto *CHAM_descC = aDescriptorData.GetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C11, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n, n, 0, 0, CHAM_descC->m / 2, CHAM_descC->n / 2, p_grid, q_grid); + dts, dts * dts, full_problem_size, full_problem_size, 0, 0, CHAM_descC->m / 2, + CHAM_descC->n / 2, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n, n, CHAM_descC->m / 2, 0, CHAM_descC->m / 2, CHAM_descC->n / 2, + dts, dts * dts, full_problem_size, full_problem_size, CHAM_descC->m / 2, 0, + CHAM_descC->m / 2, CHAM_descC->n / 2, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C22, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n, n, CHAM_descC->m / 2, CHAM_descC->n / 2, CHAM_descC->m / 2, + dts, dts * dts, full_problem_size, full_problem_size, CHAM_descC->m / 2, + CHAM_descC->n / 2, CHAM_descC->m / 2, CHAM_descC->n / 2, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_1, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n / 2, 1, 0, 0, n / 2, 1, p_grid, q_grid); + dts, dts * dts, full_problem_size / 2, 1, 0, 0, full_problem_size / 2, 1, p_grid, + q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_2, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n / 2, 1, 0, 0, n / 2, 1, p_grid, q_grid); + dts, dts * dts, full_problem_size / 2, 1, 0, 0, full_problem_size / 2, 1, p_grid, + q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_1, is_OOC, nullptr, float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_2, is_OOC, nullptr, float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); } + if (aConfigurations.GetIsNonGaussian()) { + aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_SUM, is_OOC, nullptr, float_point, + dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + } + //stop gsl error handler gsl_set_error_handler_off(); aDescriptorData.SetIsDescriptorInitiated(true); } template -void LinearAlgebraMethods::InitiateFisherDescriptors(configurations::Configurations &aConfigurations, +void LinearAlgebraMethods::InitiateFisherDescriptors(Configurations &aConfigurations, dataunits::DescriptorData &aDescriptorData) { // Check for initialize the Chameleon context. - if (!this->mpContext) { + if (!ExaGeoStatHardware::GetChameleonContext()) { throw std::runtime_error( "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); } // Get the problem size and other configuration parameters - int n = aConfigurations.GetProblemSize(); + int full_problem_size = aConfigurations.GetProblemSize(); int num_params = kernels::KernelsConfigurations::GetParametersNumberKernelMap()[aConfigurations.GetKernelName()]; int dts = aConfigurations.GetDenseTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); bool is_OOC = aConfigurations.GetIsOOC(); // Create a Chameleon sequence, if not initialized before through the same descriptors @@ -139,41 +156,46 @@ void LinearAlgebraMethods::InitiateFisherDescriptors(configurations::Configur if (!aDescriptorData.GetIsDescriptorInitiated()) { aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C, is_OOC, nullptr, float_point, dts, - dts, dts * dts, n, n, 0, 0, n, n, p_grid, q_grid); + dts, dts * dts, full_problem_size, full_problem_size, 0, 0, full_problem_size, + full_problem_size, p_grid, q_grid); } aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_A, is_OOC, nullptr, float_point, dts, dts, dts * dts, num_params, num_params, 0, 0, num_params, num_params, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_CJ, is_OOC, nullptr, float_point, - dts, dts, dts * dts, n, n, 0, 0, n, n, p_grid, q_grid); + dts, dts, dts * dts, full_problem_size, full_problem_size, 0, 0, full_problem_size, + full_problem_size, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_CK, is_OOC, nullptr, float_point, - dts, dts, dts * dts, n, n, 0, 0, n, n, p_grid, q_grid); + dts, dts, dts * dts, full_problem_size, full_problem_size, 0, 0, full_problem_size, + full_problem_size, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_RESULTS, is_OOC, nullptr, - float_point, dts, dts, dts * dts, n, n, 0, 0, n, n, p_grid, q_grid); + float_point, dts, dts, dts * dts, full_problem_size, full_problem_size, 0, 0, + full_problem_size, full_problem_size, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_C_TRACE, is_OOC, nullptr, float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); aDescriptorData.SetDescriptor(common::CHAMELEON_DESCRIPTOR, common::DESCRIPTOR_C_DIAG, is_OOC, nullptr, float_point, - dts, dts, dts * dts, n, 1, 0, 0, n, 1, p_grid, q_grid); + dts, dts, dts * dts, full_problem_size, 1, 0, 0, full_problem_size, 1, p_grid, + q_grid); } template -void LinearAlgebraMethods::InitiatePredictionDescriptors( - Configurations &aConfigurations, ExaGeoStatData &aData) { +void LinearAlgebraMethods::InitiatePredictionDescriptors(Configurations &aConfigurations, + std::unique_ptr> &aData) { - if (!this->mpContext) { + if (!ExaGeoStatHardware::GetChameleonContext()) { throw std::runtime_error( "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); } // Get the problem size and other configuration parameters int dts = aConfigurations.GetDenseTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); bool is_OOC = aConfigurations.GetIsOOC(); int z_miss_number = aConfigurations.GetUnknownObservationsNb(); int n_z_obs = aConfigurations.CalculateZObsNumber(); @@ -186,56 +208,68 @@ void LinearAlgebraMethods::InitiatePredictionDescriptors( } else { throw runtime_error("Unsupported for now!"); } - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_OBSERVATIONS, is_OOC, nullptr, - float_point, dts, dts, dts * dts, n_z_obs, 1, 0, 0, n_z_obs, 1, p_grid, - q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_OBSERVATIONS, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, 1, 0, 0, n_z_obs, 1, p_grid, + q_grid); if (aConfigurations.GetIsMSPE()) { - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_Actual, is_OOC, nullptr, - float_point, dts, dts, dts * dts, z_miss_number, 1, 0, 0, - z_miss_number, 1, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE, is_OOC, nullptr, - float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_1, is_OOC, nullptr, - float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_2, is_OOC, nullptr, - float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_Actual, is_OOC, nullptr, + float_point, dts, dts, dts * dts, z_miss_number, 1, 0, 0, + z_miss_number, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE, is_OOC, nullptr, + float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_1, is_OOC, nullptr, + float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_2, is_OOC, nullptr, + float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); } - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_MISS, is_OOC, nullptr, - float_point, dts, dts, dts * dts, z_miss_number, 1, 0, 0, z_miss_number, 1, - p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_MISS, is_OOC, nullptr, + float_point, dts, dts, dts * dts, z_miss_number, 1, 0, 0, z_miss_number, + 1, p_grid, q_grid); descriptor::ExaGeoStatDescriptor exaGeoStatDescriptor; - auto *CHAM_descC12 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12).chameleon_desc; + auto *CHAM_descC12 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12).chameleon_desc; if (CHAM_descC12) { exaGeoStatDescriptor.DestroyDescriptor(CHAMELEON_DESCRIPTOR, CHAM_descC12); } - auto *CHAM_descC22 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C22).chameleon_desc; + auto *CHAM_descC22 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C22).chameleon_desc; if (CHAM_descC22) { exaGeoStatDescriptor.DestroyDescriptor(CHAMELEON_DESCRIPTOR, CHAM_descC22); } - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12, is_OOC, nullptr, float_point, - dts, dts, dts * dts, z_miss_number, n_z_obs, 0, 0, z_miss_number, n_z_obs, - p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C22, is_OOC, nullptr, float_point, - dts, dts, dts * dts, n_z_obs, n_z_obs, 0, 0, n_z_obs, n_z_obs, p_grid, - q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C22, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, n_z_obs, 0, 0, n_z_obs, + n_z_obs, p_grid, q_grid); + if (aConfigurations.GetIsNonGaussian()) { + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_R, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, z_miss_number, 0, 0, + n_z_obs, z_miss_number, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_R_COPY, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, z_miss_number, 0, 0, + n_z_obs, z_miss_number, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12, is_OOC, nullptr, + float_point, dts, dts, dts * dts, z_miss_number, z_miss_number, 0, 0, + z_miss_number, z_miss_number, p_grid, q_grid); + } else { + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12, is_OOC, nullptr, + float_point, dts, dts, dts * dts, z_miss_number, n_z_obs, 0, 0, + z_miss_number, n_z_obs, p_grid, q_grid); + } } - template -void LinearAlgebraMethods::InitiateMLOEMMOMDescriptors(Configurations &aConfigurations, ExaGeoStatData &aData) { +void LinearAlgebraMethods::InitiateMLOEMMOMDescriptors(Configurations &aConfigurations, + std::unique_ptr> &aData, + const int &aP) { - if (!this->mpContext) { + if (!ExaGeoStatHardware::GetChameleonContext()) { throw std::runtime_error( "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); } - int n_z_obs = aConfigurations.CalculateZObsNumber(); + int n_z_obs = aConfigurations.GetObservationNumber(); int dts = aConfigurations.GetDenseTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); bool is_OOC = aConfigurations.GetIsOOC(); - int P = aConfigurations.GetP(); FloatPoint float_point; if (sizeof(T) == SIZE_OF_FLOAT) { @@ -245,69 +279,71 @@ void LinearAlgebraMethods::InitiateMLOEMMOMDescriptors(Configurations &aConfi } else { throw runtime_error("Unsupported for now!"); } - - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_T, is_OOC, nullptr, float_point, - dts, dts, dts * dts, P * n_z_obs, P, 0, 0, P * n_z_obs, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_A, is_OOC, nullptr, float_point, - dts, dts, dts * dts, P * n_z_obs, P, 0, 0, P * n_z_obs, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_A_TMP, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P * n_z_obs, P, 0, 0, P * n_z_obs, P, - p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_T_TMP, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P * n_z_obs, P, 0, 0, P * n_z_obs, P, - p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_1, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_2, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_3, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_4, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MLOE, is_OOC, nullptr, - float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MMOM, is_OOC, nullptr, - float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_TRUTH_ALPHA, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_TIMATED_ALPHA, is_OOC, nullptr, - float_point, dts, dts, dts * dts, P, P, 0, 0, P, P, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_T, is_OOC, nullptr, float_point, - dts, dts, dts * dts, P * n_z_obs, P * n_z_obs, 0, 0, P * n_z_obs, - P * n_z_obs, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_A, is_OOC, nullptr, float_point, - dts, dts, dts * dts, P * n_z_obs, P * n_z_obs, 0, 0, P * n_z_obs, - P * n_z_obs, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_T, is_OOC, nullptr, + float_point, + dts, dts, dts * dts, n_z_obs, aP, 0, 0, n_z_obs, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_A, is_OOC, nullptr, + float_point, + dts, dts, dts * dts, n_z_obs, aP, 0, 0, n_z_obs, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_A_TMP, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, aP, 0, 0, n_z_obs, aP, + p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_T_TMP, is_OOC, nullptr, + float_point, dts, dts, dts * dts, n_z_obs, aP, 0, 0, n_z_obs, aP, + p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_1, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_2, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_3, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_EXPR_4, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MLOE, is_OOC, nullptr, + float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_MMOM, is_OOC, nullptr, + float_point, dts, dts, dts * dts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_TRUTH_ALPHA, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_TIMATED_ALPHA, is_OOC, nullptr, + float_point, dts, dts, dts * dts, aP, aP, 0, 0, aP, aP, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_T, is_OOC, nullptr, + float_point, + dts, dts, dts * dts, n_z_obs, n_z_obs, 0, 0, n_z_obs, + n_z_obs, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_A, is_OOC, nullptr, + float_point, + dts, dts, dts * dts, n_z_obs, n_z_obs, 0, 0, n_z_obs, + n_z_obs, p_grid, q_grid); //stop gsl error handler gsl_set_error_handler_off(); } template -void LinearAlgebraMethods::GenerateSyntheticData(configurations::Configurations &aConfigurations, - const hardware::ExaGeoStatHardware &aHardware, - dataunits::ExaGeoStatData &aData, +void LinearAlgebraMethods::GenerateSyntheticData(Configurations &aConfigurations, + std::unique_ptr> &aData, const kernels::Kernel &aKernel) { - this->mpContext = aHardware.GetChameleonContext(); - this->InitiateDescriptors(aConfigurations, *aData.GetDescriptorData()); - auto median_locations = Locations(1, aData.GetLocations()->GetDimension()); - this->GenerateObservationsVector(aConfigurations, aData, aData.GetLocations(), aData.GetLocations(), - &median_locations, 0, aKernel); + this->InitiateDescriptors(aConfigurations, *aData->GetDescriptorData(), aKernel.GetVariablesNumber()); + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + this->GenerateObservationsVector(aConfigurations, aData, aData->GetLocations(), aData->GetLocations(), + &median_locations, aConfigurations.GetDistanceMetric(), aKernel); } template -void LinearAlgebraMethods::GenerateObservationsVector(Configurations &aConfigurations, ExaGeoStatData &aData, +void LinearAlgebraMethods::GenerateObservationsVector(Configurations &aConfigurations, + std::unique_ptr> &aData, Locations *apLocation1, Locations *apLocation2, Locations *apLocation3, const int &aDistanceMetric, const kernels::Kernel &aKernel) { // Check for initialize the Chameleon context. - if (!this->mpContext) { + if (!ExaGeoStatHardware::GetChameleonContext()) { throw std::runtime_error( "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); } - - const int n = aConfigurations.GetProblemSize(); + const int P = aKernel.GetVariablesNumber(); + const int full_problem_size = aConfigurations.GetProblemSize() * P; int seed = aConfigurations.GetSeed(); int initial_seed[4] = {seed, seed, seed, 1}; T time_facto = 0.0, time_trmm = 0.0, matrix_gen_time = 0.0, flops = 0; @@ -315,17 +351,17 @@ void LinearAlgebraMethods::GenerateObservationsVector(Configurations &aConfig // Create a Chameleon sequence, if not initialized before through the same descriptors RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; RUNTIME_sequence_t *sequence; - if (!aData.GetDescriptorData()->GetSequence()) { + if (!aData->GetDescriptorData()->GetSequence()) { ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); } else { - sequence = (RUNTIME_sequence_t *) aData.GetDescriptorData()->GetSequence(); + sequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); } - auto *CHAM_descC = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; + auto *CHAM_descC = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; //normal random generation of e -- ei~N(0, 1) to generate Z - auto *randomN = new T[n]; - LAPACKE_dlarnv(3, initial_seed, n, (double *) randomN); + auto *randomN = new T[full_problem_size]; + LAPACKE_dlarnv(3, initial_seed, full_problem_size, (double *) randomN); //Generate the co-variance matrix C auto *theta = new T[aConfigurations.GetInitialTheta().size()]; @@ -333,154 +369,152 @@ void LinearAlgebraMethods::GenerateObservationsVector(Configurations &aConfig theta[i] = aConfigurations.GetInitialTheta()[i]; } - VERBOSE("Initializing Covariance Matrix (Synthetic Dataset Generation Phase).....") + VERBOSE("\tInitializing Covariance Matrix (Synthetic Dataset Generation Phase).....") int upper_lower = EXAGEOSTAT_LOWER; START_TIMING(matrix_gen_time); - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_descC, upper_lower, apLocation1, apLocation2, - apLocation3, theta, aDistanceMetric, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_descC, upper_lower, apLocation1, + apLocation2, + apLocation3, theta, aDistanceMetric, &aKernel); ExaGeoStatSequenceWait(sequence); STOP_TIMING(matrix_gen_time); - VERBOSE("Done.") + VERBOSE("\tDone.") //Copy randomN to Z - VERBOSE("Generate Normal Random Distribution Vector Z (Synthetic Dataset Generation Phase) .....") - auto *CHAM_descZ = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; - CopyDescriptorZ(*aData.GetDescriptorData(), CHAM_descZ, randomN); + VERBOSE("\tGenerate Normal Random Distribution Vector Z (Synthetic Dataset Generation Phase) .....") + auto *CHAM_descZ = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; + RuntimeFunctions::CopyDescriptorZ(*aData->GetDescriptorData(), CHAM_descZ, randomN); VERBOSE("Done.") //Cholesky factorization for the Co-variance matrix C - VERBOSE("Cholesky factorization of Sigma (Synthetic Dataset Generation Phase) .....") + VERBOSE("\tCholesky factorization of Sigma (Synthetic Dataset Generation Phase) .....") START_TIMING(time_facto); - ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_descC, aConfigurations.GetBand(), nullptr, nullptr, 0, 0); + ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_descC, 0, nullptr, nullptr, 0, 0); STOP_TIMING(time_facto); - flops = flops + flops_dpotrf(n); - VERBOSE("Done.") + flops = flops + flops_dpotrf(full_problem_size); + VERBOSE("\tDone.") //Triangular matrix-matrix multiplication - VERBOSE("Triangular matrix-matrix multiplication Z=L.e (Synthetic Dataset Generation Phase) .....") + VERBOSE("\tTriangular matrix-matrix multiplication Z=L.e (Synthetic Dataset Generation Phase) .....") START_TIMING(time_trmm); ExaGeoStatTrmmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_descC, CHAM_descZ); STOP_TIMING(time_trmm); - flops = flops + flops_dtrmm(ChamLeft, n, CHAM_descZ->n); - VERBOSE("Done.") + flops = flops + flops_dtrmm(ChamLeft, full_problem_size, CHAM_descZ->n); + VERBOSE("\tDone.") - if (aConfigurations.GetKernelName() == "UnivariateMaternNonGaussian") { + if (aConfigurations.GetIsNonGaussian()) { //Gaussian to non-gaussian transformation VERBOSE("Convert Z Gaussian to non-Gaussian (Synthetic Dataset Generation Phase) .....") - ExaGeoStatGaussianToNonTileAsync(*aData.GetDescriptorData(), CHAM_descZ, theta); + RuntimeFunctions::ExaGeoStatGaussianToNonTileAsync(*aData->GetDescriptorData(), CHAM_descZ, theta); VERBOSE("Done.") } delete[] theta; - const int P = aConfigurations.GetP(); if (aConfigurations.GetLogger()) { T *pMatrix; VERBOSE("Writing generated data to the disk (Synthetic Dataset Generation Phase) .....") -#ifdef CHAMELEON_USE_MPI - pMatrix = new T[n]; +#ifdef USE_MPI + pMatrix = new T[full_problem_size]; string path = aConfigurations.GetLoggerPath(); - ExaGeoStatDesc2Lap(pMatrix, n, CHAM_descZ, EXAGEOSTAT_UPPER_LOWER); - if ( CHAMELEON_Comm_rank() == 0 ){ - helpers::DiskWriter::WriteVectorsToDisk(*pMatrix, n, P, path, *apLocation1); + ExaGeoStatDesc2Lap(pMatrix, full_problem_size, CHAM_descZ, EXAGEOSTAT_UPPER_LOWER); + if (CHAMELEON_Comm_rank() == 0) { + dataLoader::csv::CSVLoader::GetInstance()->WriteData(*pMatrix, full_problem_size, P, path, *apLocation1); } delete[] pMatrix; #else pMatrix = (T *) CHAM_descZ->mat; string path = aConfigurations.GetLoggerPath(); - helpers::DiskWriter::WriteVectorsToDisk(*pMatrix, n, P, path, *apLocation1); + dataLoader::csv::CSVLoader::GetInstance()->WriteData(*pMatrix, full_problem_size, P, path, *apLocation1); #endif - VERBOSE("Done.") + VERBOSE("\tDone.") } ExaGeoStatLaSetTile(EXAGEOSTAT_UPPER_LOWER, 0, 0, CHAM_descC); delete[] randomN; - VERBOSE("Done Z Vector Generation Phase. (Chameleon Synchronous)") + VERBOSE("\tDone Z Vector Generation Phase. (Chameleon Synchronous)") int total_flops = flops / 1e9 / (time_facto + time_trmm); - LOGGER(" ---- Facto Time: " << time_facto) - LOGGER(" ---- dtrmm Time: " << time_trmm) - LOGGER(" ---- Matrix Generation Time: " << matrix_gen_time) - LOGGER(" ---- Total Time: " << time_facto + time_trmm) - LOGGER(" ---- Gflop/s: " << total_flops) - - results::Results::GetInstance()->SetTotalDataGenerationExecutionTime(time_facto + time_trmm); - results::Results::GetInstance()->SetTotalDataGenerationFlops(total_flops); - results::Results::GetInstance()->SetGeneratedLocationsNumber(n); - results::Results::GetInstance()->SetGeneratedLocationsNumber(n); - results::Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); - results::Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); + VERBOSE("\t---- Facto Time: " << time_facto) + VERBOSE("\t---- dtrmm Time: " << time_trmm) + VERBOSE("\t---- Matrix Generation Time: " << matrix_gen_time) + VERBOSE("\t---- Total Time: " << time_facto + time_trmm) + VERBOSE("\t---- Gflop/s: " << total_flops) + + Results::GetInstance()->SetTotalDataGenerationExecutionTime(time_facto + time_trmm); + Results::GetInstance()->SetTotalDataGenerationFlops(total_flops); + Results::GetInstance()->SetGeneratedLocationsNumber(full_problem_size / aConfigurations.GetTimeSlot()); + Results::GetInstance()->SetIsLogger(aConfigurations.GetLogger()); + Results::GetInstance()->SetLoggerPath(aConfigurations.GetLoggerPath()); } template -T *LinearAlgebraMethods::ExaGeoStatMLEPredictTile(ExaGeoStatData &aData, T *apTheta, const int &aZMissNumber, - const int &aZObsNumber, T *apZObs, T *apZActual, T *apZMiss, - const ExaGeoStatHardware &aHardware, - Configurations &aConfiguration, Locations &aMissLocations, - Locations &aObsLocations, const kernels::Kernel &aKernel) { +T *LinearAlgebraMethods::ExaGeoStatMLEPredictTile(std::unique_ptr> &aData, T *apTheta, + const int &aZMissNumber, const int &aZObsNumber, T *apZObs, + T *apZActual, T *apZMiss, Configurations &aConfiguration, + Locations &aMissLocations, Locations &aObsLocations, + const kernels::Kernel &aKernel) { int i; - this->SetContext(aHardware.GetChameleonContext()); this->InitiatePredictionDescriptors(aConfiguration, aData); double time_solve, mat_gen_time, time_gemm, time_mspe = 0.0, flops = 0.0; int num_params; - auto *CHAM_desc_Zmiss = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_MISS).chameleon_desc; - auto *CHAM_desc_C12 = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C12).chameleon_desc; - auto *CHAM_desc_C22 = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C22).chameleon_desc; - auto *CHAM_desc_mspe = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_MSPE).chameleon_desc; - auto *CHAM_desc_mspe1 = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_MSPE_1).chameleon_desc; - auto *CHAM_desc_mspe2 = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_MSPE_2).chameleon_desc; - auto *CHAM_desc_Zactual = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_Actual).chameleon_desc; - auto *CHAM_desc_Zobs = aData.GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_OBSERVATIONS).chameleon_desc; - - T *mspe = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_mspe); + auto *CHAM_desc_Zmiss = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_MISS).chameleon_desc; + auto *CHAM_desc_C12 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C12).chameleon_desc; + auto *CHAM_desc_C22 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C22).chameleon_desc; + auto *CHAM_desc_mspe = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE).chameleon_desc; + auto *CHAM_desc_mspe1 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE_1).chameleon_desc; + auto *CHAM_desc_mspe2 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE_2).chameleon_desc; + auto *CHAM_desc_Zactual = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_Actual).chameleon_desc; + auto *CHAM_desc_Zobs = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_OBSERVATIONS).chameleon_desc; + + T *mspe = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE); *mspe = 0; - T *mspe_1 = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_mspe1); + T *mspe_1 = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_1); *mspe_1 = 0; - T *mspe_2 = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_mspe2); + T *mspe_2 = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_2); *mspe_2 = 0; auto kernel_name = aConfiguration.GetKernelName(); num_params = aKernel.GetParametersNumbers(); - auto median_locations = Locations(1, aData.GetLocations()->GetDimension()); - aData.CalculateMedianLocations(kernel_name, median_locations); + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + aData->CalculateMedianLocations(kernel_name, median_locations); // Create a Chameleon sequence, if not initialized before through the same descriptors RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; RUNTIME_sequence_t *sequence; - if (!aData.GetDescriptorData()->GetSequence()) { + if (!aData->GetDescriptorData()->GetSequence()) { ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); } else { - sequence = (RUNTIME_sequence_t *) aData.GetDescriptorData()->GetSequence(); + sequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); } - void *request = aData.GetDescriptorData()->GetRequest(); + void *request = aData->GetDescriptorData()->GetRequest(); //Copy data to vectors - VERBOSE("Copy measurements vector to descZobs descriptor...") + VERBOSE("\tCopy measurements vector to descZobs descriptor...") ExaGeoStatLap2Desc(apZObs, aZObsNumber, CHAM_desc_Zobs, UpperLower::EXAGEOSTAT_UPPER_LOWER); - VERBOSE("Done.") + VERBOSE("\tDone.") if (apZActual) { //Copy data to vectors - VERBOSE("Copy actual measurements vector to descZactual descriptor...") + VERBOSE("\tCopy actual measurements vector to descZactual descriptor...") ExaGeoStatLap2Desc(apZActual, aZMissNumber, CHAM_desc_Zactual, UpperLower::EXAGEOSTAT_UPPER_LOWER); - VERBOSE("Done.") + VERBOSE("\tDone.") } - LOGGER("- Estimated Parameters (", true) + LOGGER("\t\t- Estimated Theta (", true) for (i = 0; i < num_params; i++) { LOGGER_PRECISION(apTheta[i]) if (i != num_params - 1) { @@ -491,47 +525,51 @@ T *LinearAlgebraMethods::ExaGeoStatMLEPredictTile(ExaGeoStatData &aData, T LOGGER("") START_TIMING(mat_gen_time); - VERBOSE("Generate C22 Covariance Matrix... (Prediction Stage)") + VERBOSE("\tGenerate C22 Covariance Matrix... (Prediction Stage)") int upper_lower = EXAGEOSTAT_LOWER; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_C22, upper_lower, &aObsLocations, - &aObsLocations, &median_locations, apTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_C22, upper_lower, &aObsLocations, + &aObsLocations, &median_locations, apTheta, 0, &aKernel); ExaGeoStatSequenceWait(sequence); VERBOSE("Done.") VERBOSE("Generate C12 Covariance Matrix... (Prediction Stage)") - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_C12, upper_lower, &aMissLocations, - &aObsLocations, &median_locations, apTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_C12, upper_lower, &aMissLocations, + &aObsLocations, &median_locations, apTheta, 0, &aKernel); ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(mat_gen_time); START_TIMING(time_solve); //Start prediction - VERBOSE("Calculate dposv C22 Covariance Matrix... (Prediction Stage)") + VERBOSE("\tCalculate dposv C22 Covariance Matrix... (Prediction Stage)") ExaGeoStatPosvTile(EXAGEOSTAT_LOWER, CHAM_desc_C22, CHAM_desc_Zobs); flops = flops + flops_dpotrf(aZObsNumber); flops = flops + flops_dtrsm(ChamLeft, aZObsNumber, aZObsNumber); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(time_solve); START_TIMING(time_gemm); - VERBOSE("Calculate dgemm Zmiss= C12 * Zobs Covariance Matrix... (Prediction Stage)") + VERBOSE("\tCalculate dgemm Zmiss= C12 * Zobs Covariance Matrix... (Prediction Stage)") CHAMELEON_dgemm_Tile(ChamNoTrans, ChamNoTrans, 1, CHAM_desc_C12, CHAM_desc_Zobs, 0, CHAM_desc_Zmiss); flops = flops + flops_dgemm(aZMissNumber, aZObsNumber, aZObsNumber); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(time_gemm); ExaGeoStatDesc2Lap(apZMiss, aZMissNumber, CHAM_desc_Zmiss, EXAGEOSTAT_UPPER_LOWER); if (apZActual) { START_TIMING(time_mspe); - VERBOSE("Calculate Mean Square Prediction Error (MSPE) ... (Prediction Stage)") - if (kernel_name == "BivariateMaternParsimonious" || kernel_name == "BivariateMaternParsimonious2" || - kernel_name == "BivariateMaternParsimoniousProfile") { - throw runtime_error("Bivariate Kernels are not supported yet."); + VERBOSE("\tCalculate Mean Square Prediction Error (MSPE) ... (Prediction Stage)") + if (kernel_name == "BivariateMaternParsimonious") { + RuntimeFunctions::ExaGeoStatMLEMSPEBivariateTileAsync(CHAM_desc_Zactual, CHAM_desc_Zmiss, + CHAM_desc_mspe1, + CHAM_desc_mspe2, CHAM_desc_mspe, sequence, + &request_array[0]); } else { - this->ExaGeoStatMLEMSPETileAsync(CHAM_desc_Zactual, CHAM_desc_Zmiss, CHAM_desc_mspe, sequence, request); + RuntimeFunctions::ExaGeoStatMLEMSPETileAsync(CHAM_desc_Zactual, CHAM_desc_Zmiss, CHAM_desc_mspe, + sequence, + request); } ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(time_mspe); *mspe /= aZMissNumber; @@ -547,44 +585,240 @@ T *LinearAlgebraMethods::ExaGeoStatMLEPredictTile(ExaGeoStatData &aData, T "\n\n# of missing observations :%d\n\nPrediction Execution Time: %.8f, ""Flops: %.8f, Mean Square Prediction Error (MSPE): %.8f\n\n", aZMissNumber, (mat_gen_time + time_solve + time_mspe), (flops / 1e9 / (time_solve)), *mspe); } - LOGGER("- Z Actual .. Z Miss") + if (apZActual) { + VERBOSE("\t- Z Actual .. Z Miss") + for (i = 0; i < aZMissNumber; i++) { + VERBOSE("\t (" << apZActual[i] << ", " << apZMiss[i] << ")") + } + } + + Results::GetInstance()->SetMSPEExecutionTime(time_solve + time_gemm); + Results::GetInstance()->SetMSPEFlops((flops / 1e9 / (time_solve + time_gemm))); + Results::GetInstance()->SetMSPEError(*mspe); + + T *all_mspe = new T[3]; + all_mspe[0] = *mspe; + all_mspe[1] = *mspe_1; + all_mspe[2] = *mspe_2; + + return all_mspe; +} + +template +T *LinearAlgebraMethods::ExaGeoStatMLENonGaussianPredictTile(std::unique_ptr> &aData, + T *apTheta, const int &aZMissNumber, + const int &aZObsNumber, T *apZObs, T *apZActual, + T *apZMiss, + Configurations &aConfiguration, + dataunits::Locations &aMissLocations, + dataunits::Locations &aObsLocations, + const kernels::Kernel &aKernel) { + + int i; + this->InitiatePredictionDescriptors(aConfiguration, aData); + + double time_solve, mat_gen_time, mat_gen_time_2, time_trsm, time_gemm, time_mspe = 0.0, flops = 0.0; + int num_params; + + auto *CHAM_desc_Zmiss = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_MISS).chameleon_desc; + auto *CHAM_desc_C12 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C12).chameleon_desc; + auto *CHAM_desc_C22 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C22).chameleon_desc; + auto *CHAM_desc_mspe = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE).chameleon_desc; + auto *CHAM_desc_mspe1 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE_1).chameleon_desc; + auto *CHAM_desc_mspe2 = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_MSPE_2).chameleon_desc; + auto *CHAM_desc_Zactual = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_Actual).chameleon_desc; + auto *CHAM_desc_Zobs = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_OBSERVATIONS).chameleon_desc; + auto *CHAM_desc_R = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_R).chameleon_desc; + auto *CHAM_desc_Rcopy = aData->GetDescriptorData()->GetDescriptor(common::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_R_COPY).chameleon_desc; + + T *mspe = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE); + *mspe = 0; + T *mspe_1 = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_1); + *mspe_1 = 0; + T *mspe_2 = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MSPE_2); + *mspe_2 = 0; + + auto kernel_name = aConfiguration.GetKernelName(); + num_params = aKernel.GetParametersNumbers(); + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + aData->CalculateMedianLocations(kernel_name, median_locations); + + // Create a Chameleon sequence, if not initialized before through the same descriptors + RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; + RUNTIME_sequence_t *sequence; + if (!aData->GetDescriptorData()->GetSequence()) { + ExaGeoStatCreateSequence(&sequence); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); + } else { + sequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); + } + void *request = aData->GetDescriptorData()->GetRequest(); + + //Copy data to vectors + VERBOSE("\tCopy measurements vector to descZobs descriptor...") + ExaGeoStatLap2Desc(apZObs, aZObsNumber, CHAM_desc_Zobs, UpperLower::EXAGEOSTAT_UPPER_LOWER); + VERBOSE("\tDone.") + + if (apZActual) { + //Copy data to vectors + VERBOSE("\tCopy actual measurements vector to descZactual descriptor...") + ExaGeoStatLap2Desc(apZActual, aZMissNumber, CHAM_desc_Zactual, UpperLower::EXAGEOSTAT_UPPER_LOWER); + VERBOSE("\tDone.") + } + + LOGGER("- Estimated Parameters (", true) + for (i = 0; i < num_params; i++) { + LOGGER_PRECISION(apTheta[i]) + if (i != num_params - 1) { + LOGGER_PRECISION(", ") + } + } + LOGGER_PRECISION(")") + LOGGER("") + + //Convert the non-Gaussian observation to Gaussian + RuntimeFunctions::ExaGeoStatNonGaussianTransformTileAsync(aConfiguration.GetComputation(), CHAM_desc_Zobs, + apTheta, sequence, &request_array[0]); + + START_TIMING(mat_gen_time); + VERBOSE("\tGenerate R_theta Covariance Matrix... (Prediction Stage)") + int upper_lower = EXAGEOSTAT_LOWER; + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_C22, upper_lower, &aObsLocations, + &aObsLocations, &median_locations, apTheta, 0, &aKernel); + ExaGeoStatSequenceWait(sequence); + VERBOSE("\tDone.") + STOP_TIMING(mat_gen_time); + + START_TIMING(time_solve); + VERBOSE("Calculate dposv R_theta Covariance Matrix... (Prediction Stage)") + ExaGeoStatPosvTile(EXAGEOSTAT_LOWER, CHAM_desc_C22, CHAM_desc_Zobs); + flops = flops + flops_dpotrf(aZObsNumber); + flops = flops + 2 * flops_dtrsm(ChamLeft, CHAM_desc_C22->m, CHAM_desc_Zobs->n); + VERBOSE("\tDone.") + STOP_TIMING(time_solve); + + START_TIMING(mat_gen_time_2); + VERBOSE("Generate R_theta Covariance Matrix... (Prediction Stage)") + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_R, upper_lower, &aObsLocations, + &aMissLocations, &median_locations, apTheta, 0, &aKernel); + ExaGeoStatSequenceWait(sequence); + VERBOSE("\tDone.") + STOP_TIMING(mat_gen_time_2); + + ExaGeoStatLapackCopyTile(EXAGEOSTAT_LOWER, CHAM_desc_R, CHAM_desc_Rcopy); + + START_TIMING(time_trsm); + VERBOSE("Calculate dposv r_theta Covariance Matrix... (Prediction Stage)") + ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C22, + nullptr, nullptr, CHAM_desc_R, 0); + ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C22, + nullptr, nullptr, CHAM_desc_R, 0); + flops = flops + 2 * flops_dtrsm(ChamLeft, CHAM_desc_C22->m, CHAM_desc_Zobs->n); + VERBOSE("\tDone.") + STOP_TIMING(time_trsm); + + START_TIMING(time_gemm); + VERBOSE("For each missing location, Generate correlation vector CHAMELEON_descr (Prediction Stage) .....") + CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Rcopy, CHAM_desc_Zobs, 0, CHAM_desc_Zmiss); + CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Rcopy, CHAM_desc_R, 0, CHAM_desc_C12); + STOP_TIMING(time_gemm); + + auto r = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C12); + auto Zmiss2 = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_MISS); + + auto ng_nu = new T[aZMissNumber]; + auto ng_sigma_sq = new T[aZMissNumber]; + + double mu = -1; + double sigma_sq = -1; + for (i = 0; i < aZMissNumber; i++) { - LOGGER(" (" << apZActual[i] << ", " << apZMiss[i] << ")") + mu = Zmiss2[i]; + sigma_sq = 1 - r[i * aZMissNumber + i]; + ng_nu[i] = mu; + ng_sigma_sq[i] = sigma_sq; + //r^t X Z + apZMiss[i] = apTheta[2] + (apTheta[3] / (apTheta[4] * sqrt(1 - apTheta[5] * sigma_sq))) * + exp(apTheta[5] * pow(mu, 2) / (2 * (1 - apTheta[5] * sigma_sq))) * + (exp((pow(apTheta[4], 2) * sigma_sq + 2 * apTheta[4] * mu) / + (2 * (1 - apTheta[5] * sigma_sq))) - 1); + } + VERBOSE("\t Done.") + + ExaGeoStatLap2Desc(apZMiss, aZMissNumber, CHAM_desc_Zmiss, EXAGEOSTAT_UPPER_LOWER); + + if (apZActual != nullptr) { + START_TIMING(time_mspe); + VERBOSE("Calculate Mean Square Error (MSE) ... (Prediction Stage) \n") + RuntimeFunctions::ExaGeoStatMLEMSPETileAsync(CHAM_desc_Zactual, CHAM_desc_Zmiss, CHAM_desc_mspe, sequence, + request); + ExaGeoStatSequenceWait(sequence); + VERBOSE("\t Done.") + STOP_TIMING(time_mspe); + *mspe /= aZMissNumber; + } else { + *mspe = -1; } - results::Results::GetInstance()->SetMSPEExecutionTime(time_solve + time_gemm); - results::Results::GetInstance()->SetMSPEFlops((flops / 1e9 / (time_solve + time_gemm))); - results::Results::GetInstance()->SetMSPEError(*mspe); + if (helpers::CommunicatorMPI::GetInstance()->GetRank() == 0) { + if (aConfiguration.GetLogger()) { + fprintf(aConfiguration.GetFileLogPath(), + "\n\n# of missing observations :%d\n\nPrediction Execution Time: %.8f, ""Flops: %.8f, Mean Square Prediction Error (MSPE): %.8f\n\n", + aZMissNumber, (mat_gen_time + mat_gen_time_2 + time_solve + time_mspe), + (flops / 1e9 / (time_solve)), + *mspe); + } + VERBOSE("\t- Z Actual .. Z Miss") + for (i = 0; i < aZMissNumber; i++) { + VERBOSE("\t (" << apZActual[i] << ", " << apZMiss[i] << ")") + } + + Results::GetInstance()->SetMSPEExecutionTime(time_solve + time_gemm + time_trsm); + Results::GetInstance()->SetMSPEFlops((flops / 1e9 / (time_solve + time_gemm))); + Results::GetInstance()->SetMSPEError(*mspe); + } T *all_mspe = new T[3]; all_mspe[0] = *mspe; all_mspe[1] = *mspe_1; all_mspe[2] = *mspe_2; + delete[] ng_sigma_sq; + delete[] ng_nu; return all_mspe; } template -void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigurations, ExaGeoStatData &aData, - const ExaGeoStatHardware &aHardware, T *apTruthTheta, - T *apEstimatedTheta, Locations &aMissLocations, - Locations &aObsLocations, +void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigurations, + std::unique_ptr> &aData, + T *apTruthTheta, T *apEstimatedTheta, + Locations &aMissLocations, Locations &aObsLocations, const kernels::Kernel &aKernel) { - this->SetContext(aHardware.GetChameleonContext()); - this->InitiateMLOEMMOMDescriptors(aConfigurations, aData); + this->InitiateMLOEMMOMDescriptors(aConfigurations, aData, aKernel.GetVariablesNumber()); auto kernel_name = aConfigurations.GetKernelName(); - auto median_locations = Locations(1, aData.GetLocations()->GetDimension()); - aData.CalculateMedianLocations(kernel_name, median_locations); + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + aData->CalculateMedianLocations(kernel_name, median_locations); int n_z_miss = aConfigurations.GetUnknownObservationsNb(); int num_par = aKernel.GetParametersNumbers(); - LOGGER("- Truth Theta: ", true) + LOGGER("\t\t- Truth Theta: ", true) for (int num = 0; num < num_par; num++) { LOGGER_PRECISION(apTruthTheta[num] << " ") } LOGGER("") - LOGGER("- Estimated Theta: ", true) + LOGGER("\t\t- Estimated Theta: ", true) for (int num = 0; num < num_par; num++) { LOGGER_PRECISION(apEstimatedTheta[num] << " ") } @@ -595,49 +829,53 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu auto loe = new T[n_z_miss]; auto mom = new T[n_z_miss]; - auto *CHAM_desc_k_t = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_T).chameleon_desc; - auto *CHAM_desc_k_a = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_k_A).chameleon_desc; - auto *CHAM_desc_K_t = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_T).chameleon_desc; - auto *CHAM_desc_K_a = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_K_A).chameleon_desc; - auto *CHAM_desc_k_a_tmp = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_k_A_TMP).chameleon_desc; - auto *CHAM_desc_k_t_tmp = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_k_T_TMP).chameleon_desc; - auto *CHAM_desc_expr1 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_EXPR_1).chameleon_desc; - auto *CHAM_desc_expr2 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_EXPR_2).chameleon_desc; - auto *CHAM_desc_expr3 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_EXPR_3).chameleon_desc; - auto *CHAM_desc_expr4 = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_EXPR_4).chameleon_desc; - auto *CHAM_desc_mloe = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_MLOE).chameleon_desc; - auto *CHAM_desc_mmom = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_MMOM).chameleon_desc; - auto *CHAM_desc_estimated_alpha = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_TIMATED_ALPHA).chameleon_desc; - auto *CHAM_desc_truth_alpha = aData.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_TRUTH_ALPHA).chameleon_desc; - - T *mloe = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_mloe); + auto *CHAM_desc_k_t = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_k_T).chameleon_desc; + auto *CHAM_desc_k_a = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_k_A).chameleon_desc; + auto *CHAM_desc_K_t = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_K_T).chameleon_desc; + auto *CHAM_desc_K_a = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_K_A).chameleon_desc; + auto *CHAM_desc_k_a_tmp = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_k_A_TMP).chameleon_desc; + auto *CHAM_desc_k_t_tmp = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_k_T_TMP).chameleon_desc; + auto *CHAM_desc_expr1 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_EXPR_1).chameleon_desc; + auto *CHAM_desc_expr2 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_EXPR_2).chameleon_desc; + auto *CHAM_desc_expr3 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_EXPR_3).chameleon_desc; + auto *CHAM_desc_expr4 = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_EXPR_4).chameleon_desc; + auto *CHAM_desc_mloe = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_MLOE).chameleon_desc; + auto *CHAM_desc_mmom = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_MMOM).chameleon_desc; + auto *CHAM_desc_estimated_alpha = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_TIMATED_ALPHA).chameleon_desc; + auto *CHAM_desc_truth_alpha = aData->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_TRUTH_ALPHA).chameleon_desc; + + T *mloe = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MLOE); *mloe = 0; - T *mmom = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_mmom); + T *mmom = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_MMOM); *mmom = 0; // Create a Chameleon sequence, if not initialized before through the same descriptors RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; RUNTIME_sequence_t *sequence; - if (!aData.GetDescriptorData()->GetSequence()) { + if (!aData->GetDescriptorData()->GetSequence()) { ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); } else { - sequence = (RUNTIME_sequence_t *) aData.GetDescriptorData()->GetSequence(); + sequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); } - void *request = aData.GetDescriptorData()->GetRequest(); + void *request = aData->GetDescriptorData()->GetRequest(); - auto lmiss = new Locations(n_z_miss, aData.GetLocations()->GetDimension()); + auto lmiss = new Locations(n_z_miss, aData->GetLocations()->GetDimension()); T nu12; T rho; T sigma_square12; @@ -680,83 +918,77 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu this->ExaGeoStatLap2Desc(truth_alpha, m, CHAM_desc_truth_alpha, EXAGEOSTAT_UPPER_LOWER); this->ExaGeoStatLap2Desc(estimated_alpha, m, CHAM_desc_estimated_alpha, EXAGEOSTAT_UPPER_LOWER); - if (kernel_name == "BivariateMaternParsimonious2" || - kernel_name == "BivariateMaternParsimonious2Profile") { - //// TODO:not implemented in C - throw runtime_error("Selected Kernel Is Not Supported!"); - } - START_TIMING(matrix_gen); - VERBOSE("Create K_a and K_t Covariance Matrices (MLOE-MMOM).....") + VERBOSE("\tCreate K_a and K_t Covariance Matrices (MLOE-MMOM).....") int upper_lower = EXAGEOSTAT_LOWER; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_K_a, upper_lower, &aObsLocations, - &aObsLocations, &median_locations, apEstimatedTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_K_a, upper_lower, &aObsLocations, + &aObsLocations, &median_locations, apEstimatedTheta, 0, &aKernel); this->ExaGeoStatSequenceWait(sequence); - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_K_t, upper_lower, &aObsLocations, - &aObsLocations, &median_locations, apTruthTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_K_t, upper_lower, &aObsLocations, + &aObsLocations, &median_locations, apTruthTheta, 0, &aKernel); this->ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(matrix_gen); //Cholesky factorization for the Co-variance matrix CHAM_desc_K_a START_TIMING(cholesky1); - VERBOSE("Cholesky factorization of CHAM_desc_K_a (MLOE-MMOM) .....") + VERBOSE("\tCholesky factorization of CHAM_desc_K_a (MLOE-MMOM) .....") ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_desc_K_a, aConfigurations.GetBand(), nullptr, nullptr, 0, 0); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(cholesky1); flops = flops + flops_dpotrf(CHAM_desc_K_a->m); START_TIMING(cholesky2); //Cholesky factorization for the Co-variance matrix CHAM_desc_K_t - VERBOSE("Cholesky factorization of CHAM_desc_K_t (MLOE-MMOM) .....") + VERBOSE("\tCholesky factorization of CHAM_desc_K_t (MLOE-MMOM) .....") ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_desc_K_t, aConfigurations.GetBand(), nullptr, nullptr, 0, 0); - VERBOSE("Done.") + VERBOSE("\tDone.") STOP_TIMING(cholesky2); flops = flops + flops_dpotrf(CHAM_desc_K_t->m); T total_loop_time = 0.0; T loop_time; bool verbose; - VERBOSE("* Verbose messages are printed every 10 iteration *") + VERBOSE("\t* Verbose messages are printed every 10 iteration *") for (p = 0; p < n_z_miss; p++) { verbose = p % 10 == 0; lmiss->GetLocationX()[0] = aMissLocations.GetLocationX()[p]; lmiss->GetLocationY()[0] = aMissLocations.GetLocationY()[p]; if (verbose) { - VERBOSE("Generate two vectors k_a and k_t (MLOE-MMOM).....") + VERBOSE("\tGenerate two vectors k_a and k_t (MLOE-MMOM).....") } START_TIMING(vecs_gen); upper_lower = EXAGEOSTAT_UPPER_LOWER; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_k_t, upper_lower, &aObsLocations, lmiss, - &median_locations, apTruthTheta, 0, &aKernel); - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_k_a, upper_lower, &aObsLocations, lmiss, - &median_locations, apEstimatedTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_k_t, upper_lower, &aObsLocations, + lmiss, &median_locations, apTruthTheta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_k_a, upper_lower, &aObsLocations, + lmiss, &median_locations, apEstimatedTheta, 0, &aKernel); this->ExaGeoStatSequenceWait(sequence); STOP_TIMING(vecs_gen); //Copy CHAM_desc_k_a to CHAM_descK_atmp (MLOE-MMOM) if (verbose) { - VERBOSE("Copy CHAM_desc_k_a to CHAM_descK_atmp (MLOE-MMOM).....") + VERBOSE("\tCopy CHAM_desc_k_a to CHAM_descK_atmp (MLOE-MMOM).....") } START_TIMING(copy_vecs); ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, CHAM_desc_k_t, CHAM_desc_k_t_tmp); ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, CHAM_desc_k_a, CHAM_desc_k_a_tmp); STOP_TIMING(copy_vecs); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } START_TIMING(loop_time); START_TIMING(trsm1); // Triangular Solve (TRSM) k_a = TRSM(L_a^-1, k_a) if (verbose) { - VERBOSE("Solving the linear system k_a = TRSM(l_a^-1, k_a) ...(MLOE-MMOM)") + VERBOSE("\tSolving the linear system k_a = TRSM(l_a^-1, k_a) ...(MLOE-MMOM)") } ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_K_a, nullptr, nullptr, CHAM_desc_k_a, 0); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } flops = flops + flops_dtrsm(ChamLeft, CHAM_desc_K_a->m, CHAM_desc_k_a->n); STOP_TIMING(trsm1); @@ -764,75 +996,74 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu START_TIMING(trsm2); // Triangular Solve (TRSM) k_t = TRSM(L_t^-1, k_t) if (verbose) { - VERBOSE("Solving the linear system k_t = TRSM(L_t^-1, k_t) ...(MLOE-MMOM)") + VERBOSE("\tSolving the linear system k_t = TRSM(L_t^-1, k_t) ...(MLOE-MMOM)") } ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_K_t, nullptr, nullptr, CHAM_desc_k_t, 0); flops = flops + flops_dtrsm(ChamLeft, CHAM_desc_K_t->m, CHAM_desc_k_t->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(trsm2); START_TIMING(trsm3); // Triangular Solve (TRSM) k_a = TRSM(L_a^-T, k_a) if (verbose) { - VERBOSE("Solving the linear system k_a = TRSM(L_a^-T, k_a) ...(MLOE-MMOM)") + VERBOSE("\tSolving the linear system k_a = TRSM(L_a^-T, k_a) ...(MLOE-MMOM)") } ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_K_a, nullptr, nullptr, CHAM_desc_k_a, 0); flops = flops + flops_dtrsm(ChamLeft, CHAM_desc_K_a->m, CHAM_desc_k_a->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(trsm3); - START_TIMING(trsm4); // Triangular Solve (TRSM) k_t = TRSM(L_t^-T, k_t) if (verbose) { - VERBOSE("Solving the linear system k_t = TRSM(L_a^-T, k_t) ...(MLOE-MMOM)") + VERBOSE("\tSolving the linear system k_t = TRSM(L_a^-T, k_t) ...(MLOE-MMOM)") } ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_K_t, nullptr, nullptr, CHAM_desc_k_t, 0); flops = flops + flops_dtrsm(ChamLeft, CHAM_desc_K_t->m, CHAM_desc_k_t->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(trsm4); START_TIMING(gevv2); // Calculate dgemm value= CHAM_desc_k_t^T * CHAM_desc_k_a if (verbose) { - VERBOSE("Calculate dgemm CHAM_desc_expr1 = CHAM_desc_k_t^T * CHAM_desc_k_a... (MLOE-MMOM)") + VERBOSE("\tCalculate dgemm CHAM_desc_expr1 = CHAM_desc_k_t^T * CHAM_desc_k_a... (MLOE-MMOM)") } CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_k_t_tmp, CHAM_desc_k_a, 0, CHAM_desc_expr1); flops = flops + flops_dgemm(CHAM_desc_k_t_tmp->m, CHAM_desc_k_a->n, CHAM_desc_expr1->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(gevv2); START_TIMING(gevv3); // Calculate dgemm value= CHAM_desc_k_a^T * CHAM_desc_k_a_tmp if (verbose) { - VERBOSE("Calculate dgemm CHAM_desc_expr1 = CHAM_desc_k_a^T * CHAM_desc_k_a... (MLOE-MMOM)") + VERBOSE("\tCalculate dgemm CHAM_desc_expr1 = CHAM_desc_k_a^T * CHAM_desc_k_a... (MLOE-MMOM)") } CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_k_a_tmp, CHAM_desc_k_a, 0, CHAM_desc_expr4); flops = flops + flops_dgemm(CHAM_desc_k_a_tmp->m, CHAM_desc_k_a->n, CHAM_desc_expr4->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(gevv3); START_TIMING(gevv1); // Calculate dgemm value= CHAM_desc_k_a^T * CHAM_desc_k_t if (verbose) { - VERBOSE("Calculate dgemm CHAM_desc_expr4 = CHAM_desc_k_a^T * CHAM_desc_k_t... (Prediction Stage)") + VERBOSE("\tCalculate dgemm CHAM_desc_expr4 = CHAM_desc_k_a^T * CHAM_desc_k_t... (Prediction Stage)") } CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_k_t_tmp, CHAM_desc_k_t, 0, CHAM_desc_expr3); flops = flops + flops_dgemm(CHAM_desc_k_t_tmp->m, CHAM_desc_k_t->n, CHAM_desc_expr3->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(gevv1); @@ -844,12 +1075,12 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu // Calculate dgemm value= CHAM_desc_k_a^T * CHAM_desc_k_t if (verbose) { - VERBOSE("Calculate dgemm CHAM_desc_expr1 = CHAM_desc_k_a^T * CHAM_desc_k_a... (Prediction Stage)") + VERBOSE("\tCalculate dgemm CHAM_desc_expr1 = CHAM_desc_k_a^T * CHAM_desc_k_a... (Prediction Stage)") } CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_k_a, CHAM_desc_k_a, 0, CHAM_desc_expr2); flops = flops + flops_dgemm(CHAM_desc_k_a_tmp->m, CHAM_desc_k_t->n, CHAM_desc_expr2->n); if (verbose) { - VERBOSE("Done.") + VERBOSE("\tDone.") } START_TIMING(gevv5); STOP_TIMING(gevv5); @@ -862,33 +1093,32 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu ExaGeoStatGeaddTile(EXAGEOSTAT_NO_TRANS, 1, CHAM_desc_truth_alpha, -1, CHAM_desc_expr3); ExaGeoStatGeaddTile(EXAGEOSTAT_NO_TRANS, 1, CHAM_desc_estimated_alpha, -1, CHAM_desc_expr4); - LOGGER("- Matrix Generation Time: " << matrix_gen << " Vectors Generation Time: " << vecs_gen - << " First Cholesky factorization Time: " << cholesky1 - << " First Cholesky factorization Time: " << cholesky2) - LOGGER("- First Trsm time: " << trsm1 << " Second Trsm time: " << trsm2 << " Third Trsm time: " << trsm3 - << " Fourth Trsm time: " << trsm4) - LOGGER("- First gemm time: " << gevv1 << " Second gemm time: " << gevv2 << " Third gemm time: " << gevv3 - << " Fourth gemm time: " << gevv4 << " Fifth gemm time: " << gevv5) - ExaGeoStatMLETileAsyncMLOEMMOM(CHAM_desc_expr2, CHAM_desc_expr3, CHAM_desc_expr4, CHAM_desc_mloe, - CHAM_desc_mmom, sequence, request); + VERBOSE("\t- Matrix Generation Time: " << matrix_gen << " Vectors Generation Time: " << vecs_gen + << " First Cholesky factorization Time: " << cholesky1 + << " First Cholesky factorization Time: " << cholesky2) + VERBOSE("\t- First Trsm time: " << trsm1 << " Second Trsm time: " << trsm2 << " Third Trsm time: " << trsm3 + << " Fourth Trsm time: " << trsm4) + VERBOSE("\t- First gemm time: " << gevv1 << " Second gemm time: " << gevv2 << " Third gemm time: " << gevv3 + << " Fourth gemm time: " << gevv4 << " Fifth gemm time: " << gevv5) + RuntimeFunctions::ExaGeoStatMLETileAsyncMLOEMMOM(CHAM_desc_expr2, CHAM_desc_expr3, CHAM_desc_expr4, + CHAM_desc_mloe, CHAM_desc_mmom, sequence, request); this->ExaGeoStatSequenceWait(sequence); } - LOGGER(" ---- MLOE-MMOM Gflop/s: " << flops / 1e9 / (total_loop_time + cholesky1 + cholesky2)) + VERBOSE("\t---- MLOE-MMOM Gflop/s: " << flops / 1e9 / (total_loop_time + cholesky1 + cholesky2)) *mloe /= n_z_miss; *mmom /= n_z_miss; STOP_TIMING(all_time); - LOGGER(" ---- MLOE = " << *mloe) - LOGGER(" ---- MMOM = " << *mmom) - LOGGER(" ---- MLOE MMOM Time: " << all_time << " seconds.") - - results::Results::GetInstance()->SetMLOE(*mloe); - results::Results::GetInstance()->SetMMOM(*mmom); - results::Results::GetInstance()->SetExecutionTimeMLOEMMOM(all_time); - results::Results::GetInstance()->SetMatrixGenerationTimeMLOEMMOM(matrix_gen); - results::Results::GetInstance()->SetFactoTimeMLOEMMOM(cholesky1 + cholesky2); - results::Results::GetInstance()->SetLoopTimeMLOEMMOM(total_loop_time); - results::Results::GetInstance()->SetFlopsMLOEMMOM((flops / 1e9 / (total_loop_time + cholesky1 + cholesky2))); + LOGGER("\t\t- MLOE = " << *mloe << "\t\t- MMOM = " << *mmom) + VERBOSE("\t---- MLOE MMOM Time: " << all_time << " seconds.") + + Results::GetInstance()->SetMLOE(*mloe); + Results::GetInstance()->SetMMOM(*mmom); + Results::GetInstance()->SetExecutionTimeMLOEMMOM(all_time); + Results::GetInstance()->SetMatrixGenerationTimeMLOEMMOM(matrix_gen); + Results::GetInstance()->SetFactoTimeMLOEMMOM(cholesky1 + cholesky2); + Results::GetInstance()->SetLoopTimeMLOEMMOM(total_loop_time); + Results::GetInstance()->SetFlopsMLOEMMOM((flops / 1e9 / (total_loop_time + cholesky1 + cholesky2))); delete[] loe; delete[] mom; @@ -901,61 +1131,57 @@ void LinearAlgebraMethods::ExaGeoStatMLETileMLOEMMOM(Configurations &aConfigu } template -T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations &aConfigurations, - dataunits::ExaGeoStatData &aData, - const hardware::ExaGeoStatHardware &aHardware, T *apTheta, +T *LinearAlgebraMethods::ExaGeoStatFisherTile(Configurations &aConfigurations, + std::unique_ptr> &aData, T *apTheta, const kernels::Kernel &aKernel) { - this->SetContext(aHardware.GetChameleonContext()); - this->InitiateFisherDescriptors(aConfigurations, *aData.GetDescriptorData()); - - auto *CHAM_desc_A = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_A).chameleon_desc; - auto *CHAM_desc_C = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C).chameleon_desc; - auto *CHAM_desc_CJ = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CJ).chameleon_desc; - auto *CHAM_desc_results = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_RESULTS).chameleon_desc; - auto *CHAM_desc_CK = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CK).chameleon_desc; - auto *CHAM_desc_C_diag = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C_DIAG).chameleon_desc; - auto *CHAM_desc_C_trace = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C_TRACE).chameleon_desc; - - auto trace = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_C_trace); + this->InitiateFisherDescriptors(aConfigurations, *aData->GetDescriptorData()); + + auto *CHAM_desc_A = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_A).chameleon_desc; + auto *CHAM_desc_C = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C).chameleon_desc; + auto *CHAM_desc_CJ = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CJ).chameleon_desc; + auto *CHAM_desc_results = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_RESULTS).chameleon_desc; + auto *CHAM_desc_CK = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CK).chameleon_desc; + auto *CHAM_desc_C_diag = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C_DIAG).chameleon_desc; + auto *CHAM_desc_C_trace = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C_TRACE).chameleon_desc; + + auto trace = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C_TRACE); *trace = 0.0; RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; RUNTIME_sequence_t *sequence; - if (!aData.GetDescriptorData()->GetSequence()) { + if (!aData->GetDescriptorData()->GetSequence()) { ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); } else { - sequence = (RUNTIME_sequence_t *) aData.GetDescriptorData()->GetSequence(); + sequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); } - void *request = aData.GetDescriptorData()->GetRequest(); - auto kernel_name = aConfigurations.GetKernelName(); int num_params = aKernel.GetParametersNumbers(); - auto median_locations = Locations(1, aData.GetLocations()->GetDimension()); - aData.CalculateMedianLocations(kernel_name, median_locations); - double time = 0.0; + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + aData->CalculateMedianLocations(kernel_name, median_locations); + double time; START_TIMING(time); VERBOSE("Generate covariance matrix CHAM_desc_C (Fisher Matrix Generation).....") - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_C, EXAGEOSTAT_LOWER, aData.GetLocations(), - aData.GetLocations(), &median_locations, apTheta, aConfigurations.GetDistanceMetric(), - &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_C, EXAGEOSTAT_LOWER, + aData->GetLocations(), aData->GetLocations(), &median_locations, apTheta, + aConfigurations.GetDistanceMetric(), &aKernel); ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Calculate Cholesky decomposition (Fisher Matrix Generation).....") + VERBOSE("\tCalculate Cholesky decomposition (Fisher Matrix Generation).....") ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_desc_C, 0, nullptr, nullptr, 0, 0); - VERBOSE("Done.") + VERBOSE("\tDone.") //Allocate memory for A, and initialize it with 0s. auto A = new T[num_params * num_params](); @@ -972,23 +1198,24 @@ T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations kernel_name = "UnivariateMaternNuggetsStationary"; } - auto pKernel_cj = plugins::PluginRegistry>::Create(kernel_name); + auto pKernel_cj = plugins::PluginRegistry>::Create(kernel_name, + aConfigurations.GetTimeSlot()); VERBOSE("Generate covariance matrix CHAM_desc_CJ (Fisher Matrix Generation).....") - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_CJ, EXAGEOSTAT_UPPER_LOWER, - aData.GetLocations(), aData.GetLocations(), &median_locations, apTheta, - aConfigurations.GetDistanceMetric(), pKernel_cj); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_CJ, EXAGEOSTAT_UPPER_LOWER, + aData->GetLocations(), aData->GetLocations(), &median_locations, apTheta, + aConfigurations.GetDistanceMetric(), pKernel_cj); ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Compute triangular solve CHAM_desc_CJ (Fisher Matrix Generation).....") + VERBOSE("\tCompute triangular solve CHAM_desc_CJ (Fisher Matrix Generation).....") ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C, nullptr, nullptr, CHAM_desc_CJ, 0); ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C, nullptr, nullptr, CHAM_desc_CJ, 0); - VERBOSE("Done.") + VERBOSE("\tDone.") delete pKernel_cj; for (int k = j; k < num_params; k++) { @@ -1003,33 +1230,35 @@ T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations kernel_name = "UnivariateMaternNuggetsStationary"; } - auto pKernel_ck = plugins::PluginRegistry>::Create(kernel_name); + auto pKernel_ck = plugins::PluginRegistry>::Create(kernel_name, + aConfigurations.GetTimeSlot()); VERBOSE("Generate covariance matrix CHAM_desc_CK (Fisher Matrix Generation).....") - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_CK, EXAGEOSTAT_UPPER_LOWER, - aData.GetLocations(), aData.GetLocations(), &median_locations, apTheta, - aConfigurations.GetDistanceMetric(), pKernel_ck); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_CK, EXAGEOSTAT_UPPER_LOWER, + aData->GetLocations(), aData->GetLocations(), &median_locations, + apTheta, aConfigurations.GetDistanceMetric(), pKernel_ck); ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Compute tringular solve CHAM_desc_CK (Fisher Matrix Generation).....") + VERBOSE("\tCompute tringular solve CHAM_desc_CK (Fisher Matrix Generation).....") ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C, nullptr, nullptr, CHAM_desc_CK, 0); ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C, nullptr, nullptr, CHAM_desc_CK, 0); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Compute matrix-matrix multiplication CHAM_desc_CK (Fisher Matrix Generation).....") + VERBOSE("\tCompute matrix-matrix multiplication CHAM_desc_CK (Fisher Matrix Generation).....") CHAMELEON_dgemm_Tile(ChamNoTrans, ChamNoTrans, 1, CHAM_desc_CJ, CHAM_desc_CK, 0, CHAM_desc_results); - VERBOSE("Done.") + VERBOSE("\tDone.") VERBOSE("Compute the trace/diagonal of CHAM_desc_CK (Fisher Matrix Generation).....") - ExaGeoStatMLETraceTileAsync(CHAM_desc_results, sequence, &request_array[0], CHAM_desc_C_trace, - CHAM_desc_C_diag); + RuntimeFunctions::ExaGeoStatMLETraceTileAsync(CHAM_desc_results, sequence, &request_array[0], + CHAM_desc_C_trace, + CHAM_desc_C_diag); ExaGeoStatSequenceWait(sequence); - VERBOSE("Done.") + VERBOSE("\tDone.") A[k + num_params * j] = 0.5 * *trace; *trace = 0; @@ -1039,19 +1268,19 @@ T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations STOP_TIMING(time); - VERBOSE("Copy A array to descriptor CHAM_desc_A (Fisher Matrix Generation).....") + VERBOSE("\tCopy A array to descriptor CHAM_desc_A (Fisher Matrix Generation).....") ExaGeoStatLap2Desc(A, num_params, CHAM_desc_A, EXAGEOSTAT_UPPER_LOWER); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Calculate Cholesky decomposition (Fisher Matrix Generation).....") + VERBOSE("\tCalculate Cholesky decomposition (Fisher Matrix Generation).....") LAPACKE_dpotrf(LAPACK_COL_MAJOR, 'L', num_params, (double *) A, num_params); - VERBOSE("Done.") - VERBOSE("Generate Identity Matrix (I) (Fisher Matrix Generation).....") + VERBOSE("\tDone.") + VERBOSE("\tGenerate Identity Matrix (I) (Fisher Matrix Generation).....") //Allocate memory for A, and initialize it with 0s. auto I_matrix = new T[num_params * num_params + 1](); LAPACKE_dlaset(LAPACK_COL_MAJOR, 'L', num_params, num_params, 0, 1, (double *) I_matrix, num_params); - VERBOSE("Done.") + VERBOSE("\tDone.") cblas_dtrsm( CblasColMajor, @@ -1071,11 +1300,7 @@ T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations I_matrix[num_params * num_params] = time; - results::Results::GetInstance()->SetTotalFisherTime(time); - results::Results::GetInstance()->SetFisher00((double) I_matrix[0]); - results::Results::GetInstance()->SetFisher11((double) I_matrix[4]); - results::Results::GetInstance()->SetFisher22((double) I_matrix[8]); - + Results::GetInstance()->SetTotalFisherTime(time); delete[] A; return I_matrix; } @@ -1083,14 +1308,14 @@ T *LinearAlgebraMethods::ExaGeoStatFisherTile(configurations::Configurations template void LinearAlgebraMethods::ExaGeoStatGetZObs(Configurations &aConfigurations, T *apZ, const int &aSize, - DescriptorData &aDescData, T *apMeasurementsMatrix) { + DescriptorData &aDescData, T *apMeasurementsMatrix, const int &aP) { auto z_desc = (CHAM_desc_t *) aDescData.GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_COPY).chameleon_desc; if (!z_desc) { - int n = aConfigurations.GetProblemSize(); + int full_problem_size = aConfigurations.GetProblemSize() * aP; int dts = aConfigurations.GetDenseTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); bool is_OOC = aConfigurations.GetIsOOC(); @@ -1104,266 +1329,46 @@ LinearAlgebraMethods::ExaGeoStatGetZObs(Configurations &aConfigurations, T *a throw runtime_error("Unsupported for now!"); } aDescData.SetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_COPY, is_OOC, apMeasurementsMatrix, float_point, dts, - dts, dts * dts, n, 1, 0, 0, n, 1, p_grid, q_grid); + dts, dts * dts, full_problem_size, 1, 0, 0, full_problem_size, 1, p_grid, q_grid); z_desc = (CHAM_desc_t *) aDescData.GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z_COPY).chameleon_desc; } + double epsilon = 1e-8; + if (abs(((T *) z_desc->mat)[0]) < epsilon) { + z_desc = (CHAM_desc_t *) aDescData.GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; + } this->ExaGeoStatDesc2Lap(apZ, aSize, z_desc, UpperLower::EXAGEOSTAT_UPPER_LOWER); } -template -void LinearAlgebraMethods::CovarianceMatrixCodelet(DescriptorData &aDescriptorData, void *apDescriptor, - const int &aTriangularPart, Locations *apLocation1, - Locations *apLocation2, Locations *apLocation3, - T *apLocalTheta, const int &aDistanceMetric, - const kernels::Kernel *apKernel) { +#ifdef USE_HICMA - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - RUNTIME_option_t options; - RUNTIME_options_init((RUNTIME_option_t *) &options, (CHAM_context_t *) this->mpContext, - (RUNTIME_sequence_t *) aDescriptorData.GetSequence(), - (RUNTIME_request_t *) aDescriptorData.GetRequest()); - - int temp, tempnn; - auto *CHAM_apDescriptor = (CHAM_desc_t *) apDescriptor; - struct starpu_codelet *cl = &this->cl_dcmg; - int m, n, m0 = 0, n0 = 0; - - for (n = 0; n < CHAM_apDescriptor->nt; n++) { - tempnn = n == CHAM_apDescriptor->nt - 1 ? CHAM_apDescriptor->n - n * CHAM_apDescriptor->nb - : CHAM_apDescriptor->nb; - if (aTriangularPart == ChamUpperLower) { - m = 0; - } else { - m = CHAM_apDescriptor->m == CHAM_apDescriptor->n ? n : 0; +template +void LinearAlgebraMethods::CopyDescriptors(void *apSourceDesc, void *apDestinationDesc, const int &aSize, + const common::CopyDirection &aDirection) { + auto *z = new T[aSize]; + int status; + if (aDirection == common::CHAMELEON_TO_HICMA) { + status = CHAMELEON_Desc2Lap((cham_uplo_t) EXAGEOSTAT_UPPER_LOWER, (CHAM_desc_t *) apSourceDesc, z, aSize); + if (status != CHAMELEON_SUCCESS) { + throw std::runtime_error("CHAMELEON_Desc2Lap Failed!"); } - for (; m < CHAM_apDescriptor->mt; m++) { - temp = m == CHAM_apDescriptor->mt - 1 ? CHAM_apDescriptor->m - m * CHAM_apDescriptor->mb - : CHAM_apDescriptor->mb; - m0 = m * CHAM_apDescriptor->mb; - n0 = n * CHAM_apDescriptor->nb; - // Register the data with StarPU - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &tempnn, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_VALUE, &n0, sizeof(int), - STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(CHAM_apDescriptor, m, n), - STARPU_VALUE, &apLocation1, sizeof(Locations *), - STARPU_VALUE, &apLocation2, sizeof(Locations *), - STARPU_VALUE, &apLocation3, sizeof(Locations *), - STARPU_VALUE, &apLocalTheta, sizeof(double *), - STARPU_VALUE, &aDistanceMetric, sizeof(int), - STARPU_VALUE, &apKernel, sizeof(kernels::Kernel *), - 0); + status = HICMA_Lapack_to_Tile(z, aSize, (HICMA_desc_t *) apDestinationDesc); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("HICMA_Lapack_to_Tile Failed!"); } - } - - RUNTIME_options_ws_free(&options); - RUNTIME_options_finalize(&options, (CHAM_context_t *) this->mpContext); -} - -template -void -LinearAlgebraMethods::ExaGeoStatMLETraceTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescNum, - void *apDescTrace) { - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m, m0, n0; - int tempmm; - auto A = *((CHAM_desc_t *) apDescA); - struct starpu_codelet *cl = &this->cl_dtrace; - - for (m = 0; m < A.mt; m++) { - tempmm = m == A.mt - 1 ? A.m - m * A.mb : A.mb; - starpu_insert_task(cl, - STARPU_VALUE, &tempmm, sizeof(int), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescA, m, m), - STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescNum, 0, 0), - STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescTrace, m, 0), - 0); - } - - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, this->mpContext); -} - -template -void -LinearAlgebraMethods::ExaGeoStatGaussianToNonTileAsync(DescriptorData &aDescriptorData, void *apDesc, - T *apTheta) { - - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, aDescriptorData.GetSequence(), aDescriptorData.GetRequest()); - - int m, m0; - int temp; - auto desc_z = (CHAM_desc_t *) apDesc; - struct starpu_codelet *cl = &this->cl_gaussian_to_non; - - - for (m = 0; m < desc_z->mt; m++) { - temp = m == desc_z->mt - 1 ? desc_z->m - m * desc_z->mb : desc_z->mb; - m0 = m * desc_z->mb; - - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_z, m, 0), - STARPU_VALUE, &apTheta[0], sizeof(T), - STARPU_VALUE, &apTheta[1], sizeof(T), - STARPU_VALUE, &apTheta[2], sizeof(T), - STARPU_VALUE, &apTheta[3], sizeof(T), - STARPU_VALUE, &apTheta[4], sizeof(T), - STARPU_VALUE, &apTheta[5], sizeof(T), -#if defined(CHAMELEON_CODELETS_HAVE_NAME) - STARPU_NAME, "gaussian_to_non", -#endif - 0); - } - - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, this->mpContext); -} - -template -int LinearAlgebraMethods::ExaGeoStatMLEMSPETileAsync(void *apDescZPredict, void *apDescZMiss, - void *apDescError, void *apSequence, - void *apRequest) { - // Check for Initialise the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m, m0; - int temp; - auto Zpre = (CHAM_desc_t *) apDescZPredict; - struct starpu_codelet *cl = &this->cl_dmse; - - for (m = 0; m < Zpre->mt; m++) { - temp = m == Zpre->mt - 1 ? Zpre->m - m * Zpre->mb : Zpre->mb; - - m0 = m * Zpre->mb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescError, 0, 0), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZPredict, m, 0), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZMiss, m, 0), -#if defined(CHAMELEON_CODELETS_HAVE_NAME) - STARPU_NAME, "dmse", -#endif - 0); - } - ExaGeoStatOptionsFree(&options); - ExaGeoStatOptionsFinalize(&options, (CHAM_context_t *) this->mpContext); - return CHAMELEON_SUCCESS; -} - -template -int LinearAlgebraMethods::ExaGeoStatMLETileAsyncMLOEMMOM(void *apDescExpr2, void *apDescExpr3, void *apDescExpr4, - void *apDescMLOE, void *apDescMMOM, void *apSequence, - void *apRequest) { - - // Check for Initialise the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m, n, m0, n0; - struct starpu_codelet *cl = &this->cl_dmloe_mmom; - int temp, temp2; - - for (n = 0; n < ((CHAM_desc_t *) apDescExpr2)->nt; n++) { - temp2 = n == ((CHAM_desc_t *) apDescExpr2)->nt - 1 ? ((CHAM_desc_t *) apDescExpr2)->n - - n * ((CHAM_desc_t *) apDescExpr2)->nb - : ((CHAM_desc_t *) apDescExpr2)->nb; - for (m = 0; m < ((CHAM_desc_t *) apDescExpr2)->mt; m++) { - - temp = m == ((CHAM_desc_t *) apDescExpr2)->mt - 1 ? ((CHAM_desc_t *) apDescExpr2)->m - - m * ((CHAM_desc_t *) apDescExpr2)->mb - : ((CHAM_desc_t *) apDescExpr2)->mb; - m0 = m * ((CHAM_desc_t *) apDescExpr2)->mb; - n0 = n * ((CHAM_desc_t *) apDescExpr2)->nb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &temp2, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_VALUE, &n0, sizeof(int), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr2, m, n), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr3, m, n), - STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr4, m, n), - STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescMLOE, m, n), - STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescMMOM, m, n), - 0); + } else if (aDirection == common::HICMA_TO_CHAMELEON) { + status = HICMA_Tile_to_Lapack((HICMA_desc_t *) apSourceDesc, z, aSize); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("HICMA_Tile_to_Lapack Failed!"); + } + status = CHAMELEON_Lap2Desc((cham_uplo_t) EXAGEOSTAT_UPPER_LOWER, z, aSize, (CHAM_desc_t *) apDestinationDesc); + if (status != CHAMELEON_SUCCESS) { + throw std::runtime_error("CHAMELEON_Lap2Desc Failed!"); } } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, this->mpContext); - return CHAMELEON_SUCCESS; + delete[] z; } -template -void -LinearAlgebraMethods::CopyDescriptorZ(DescriptorData &aDescriptorData, void *apDescriptor, T *apDoubleVector) { - - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - RUNTIME_options_init(&options, (chameleon_context_s *) this->mpContext, - (RUNTIME_sequence_t *) aDescriptorData.GetSequence(), - (RUNTIME_request_t *) aDescriptorData.GetRequest()); - - int m, m0; - int temp; - auto A = (CHAM_desc_t *) apDescriptor; - struct starpu_codelet *cl = &this->cl_dzcpy; - - for (m = 0; m < A->mt; m++) { - temp = m == A->mt - 1 ? A->m - m * A->mb : A->mb; - m0 = m * A->mb; - - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_VALUE, &apDoubleVector, sizeof(double), - STARPU_W, RUNTIME_data_getaddr(A, m, 0), -#if defined(CHAMELEON_CODELETS_HAVE_NAME) - STARPU_NAME, "dzcpy", #endif - 0); - } - RUNTIME_options_ws_free(&options); - -} template void @@ -1375,6 +1380,15 @@ LinearAlgebraMethods::ExaGeoStatDesc2Lap(T *apA, const int &aLDA, void *apDes } +template +void +LinearAlgebraMethods::ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const UpperLower &aUpperLower) { + int status = CHAMELEON_Lap2Desc((cham_uplo_t) aUpperLower, apA, aLDA, (CHAM_desc_t *) apDescA); + if (status != CHAMELEON_SUCCESS) { + throw std::runtime_error("CHAMELEON_Lap2Desc Failed!"); + } +} + template void LinearAlgebraMethods::ExaGeoStatLaSetTile(const common::UpperLower &aUpperLower, T alpha, T beta, void *apDescriptor) { @@ -1411,4 +1425,39 @@ void LinearAlgebraMethods::ExaGeoStatPosvTile(const common::UpperLower &aUppe if (status != CHAMELEON_SUCCESS) { throw std::runtime_error("CHAMELEON_dposv_Tile Failed!"); } -} \ No newline at end of file +} + +template +bool LinearAlgebraMethods::Recover(char *apPath, const int &aIterationCount, T *apTheta, T *apLogLik, + const int &aNumParams) { + + char *pLine = nullptr, *pTokens; + size_t length = 0; + int count, i; + + FILE *pFile_handler; + pFile_handler = fopen(apPath, "r"); + + if (pFile_handler == nullptr) { + throw std::runtime_error("Cannot open observations file"); + } + while (getline(&pLine, &length, pFile_handler) != -1) { + pTokens = strtok(pLine, " "); + count = (int) strtol(pTokens, nullptr, 10); + if (count == aIterationCount) { + pTokens = strtok(nullptr, " "); + for (i = 0; i < aNumParams; i++) { + apTheta[i] = strtol(pTokens, nullptr, 10); + pTokens = strtok(nullptr, " "); + } + *apLogLik = strtol(pTokens, nullptr, 10); + fclose(pFile_handler); + free(pLine); + return true; + } + } + + fclose(pFile_handler); + free(pLine); + return false; +} diff --git a/src/linear-algebra-solvers/concrete/CMakeLists.txt b/src/linear-algebra-solvers/concrete/CMakeLists.txt index 0174fa63..74df59f8 100644 --- a/src/linear-algebra-solvers/concrete/CMakeLists.txt +++ b/src/linear-algebra-solvers/concrete/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @brief CMake build script for the linear-algebra-solvers library, which includes the concrete implementations of the # LinearAlgebraMethods class based on the enabled libraries (HiCMA or Chameleon). # @author Mahmoud ElKarargy @@ -13,15 +13,15 @@ # Include the concrete implementations of the LinearAlgebraMethods class based on the enabled libraries (HiCMA or Chameleon) set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/chameleon/dense/ChameleonImplementationDense.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/chameleon/diagonal-super-tile/ChameleonImplementationDST.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/chameleon/dense/ChameleonDense.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/chameleon/dst/ChameleonDST.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chameleon/ChameleonImplementation.cpp ${SOURCES} ) -if (EXAGEOSTAT_USE_HICMA) +if (USE_HICMA) list(APPEND SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/tile-low-rank/HicmaImplementation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tlr/HicmaImplementation.cpp ) endif () diff --git a/src/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.cpp b/src/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.cpp index c2236051..8ec6abe8 100644 --- a/src/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.cpp +++ b/src/linear-algebra-solvers/concrete/chameleon/ChameleonImplementation.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,14 +7,16 @@ * @file ChameleonImplementation.cpp * @brief This file contains the declaration of ChameleonImplementation class. * @details ChameleonImplementation is a concrete implementation of LinearAlgebraMethods class for dense or diagonal-super tile matrices.. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-03-20 + * @date 2024-02-04 **/ #ifdef USE_MPI + #include + #endif #include @@ -25,60 +27,30 @@ using namespace std; using namespace exageostat::common; using namespace exageostat::dataunits; +using namespace exageostat::runtime; +using namespace exageostat::results; using namespace exageostat::configurations; using namespace exageostat::linearAlgebra; template -int ChameleonImplementation::ExaGeoStatDoubleDotProduct(void *apDescA, void *apDescProduct, void *apSequence, - void *apRequest) { - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - - int m, m0; - int tempmm; - auto A = (CHAM_desc_t *) apDescA; - - struct starpu_codelet *cl=&this->cl_ddotp; - - for (m = 0; m < A->mt; m++) { - tempmm = m == A->mt-1 ? A->m - m * A->mb : A->mb; - - m0 = m * A->mb; - - - starpu_insert_task(cl, - STARPU_VALUE, &tempmm, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_RW, ExaGeoStatDataGetAddr(apDescProduct, 0, 0), - STARPU_R, RUNTIME_data_getaddr(A, m, 0), - 0); - } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, (CHAM_context_t *) this->mpContext); - return CHAMELEON_SUCCESS; -} - - -template -T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardware &aHardware, ExaGeoStatData &aData, - Configurations &aConfigurations, const double *theta, +T ChameleonImplementation::ExaGeoStatMLETile(std::unique_ptr> &aData, + configurations::Configurations &aConfigurations, const double *theta, T *apMeasurementsMatrix, const kernels::Kernel &aKernel) { - this->SetContext(aHardware.GetContext(aConfigurations.GetComputation())); - if (!aData.GetDescriptorData()->GetIsDescriptorInitiated()) { - this->InitiateDescriptors(aConfigurations, *aData.GetDescriptorData(), apMeasurementsMatrix); + if (!aData->GetDescriptorData()->GetIsDescriptorInitiated()) { + this->InitiateDescriptors(aConfigurations, *aData->GetDescriptorData(), aKernel.GetVariablesNumber(), + apMeasurementsMatrix); } // Create a Chameleon sequence, if not initialized before through the same descriptors RUNTIME_request_t request_array[2] = {RUNTIME_REQUEST_INITIALIZER, RUNTIME_REQUEST_INITIALIZER}; - if (!aData.GetDescriptorData()->GetSequence()) { + if (!aData->GetDescriptorData()->GetSequence()) { RUNTIME_sequence_t *sequence; this->ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); } - auto pSequence = (RUNTIME_sequence_t *) aData.GetDescriptorData()->GetSequence(); + auto pSequence = (RUNTIME_sequence_t *) aData->GetDescriptorData()->GetSequence(); //Initialization T loglik = 0.0, logdet, variance, variance1 = 1, variance2 = 1, variance3, dot_product = 0, dot_product1 = 0, dot_product2 = 0, dot_product3, n, dzcpy_time, time_facto, time_solve, logdet_calculate, matrix_gen_time; double accumulated_executed_time, accumulated_flops; @@ -89,64 +61,71 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa auto kernel_name = aConfigurations.GetKernelName(); int num_params = aKernel.GetParametersNumbers(); - auto median_locations = Locations(1, aData.GetLocations()->GetDimension()); - aData.CalculateMedianLocations(kernel_name, median_locations); - - auto *CHAM_desc_C = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C).chameleon_desc; - auto *CHAM_desc_sub_C11 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C11).chameleon_desc; - auto *CHAM_desc_sub_C12 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C12).chameleon_desc; - auto *CHAM_desc_sub_C22 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C22).chameleon_desc; - auto *CHAM_desc_Z = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z).chameleon_desc; - auto *CHAM_desc_Z1 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_1).chameleon_desc; - auto *CHAM_desc_Z2 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_2).chameleon_desc; - auto *CHAM_desc_Z3 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_3).chameleon_desc; - auto *CHAM_desc_Zcpy = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_COPY).chameleon_desc; - auto *CHAM_desc_det = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_DETERMINANT).chameleon_desc; - auto *CHAM_desc_product = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_PRODUCT).chameleon_desc; - auto *CHAM_desc_product1 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_PRODUCT_1).chameleon_desc; - auto *CHAM_desc_product2 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_PRODUCT_2).chameleon_desc; - auto *CHAM_desc_product3 = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_PRODUCT_3).chameleon_desc; - - T *determinant = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_det); + auto median_locations = Locations(1, aData->GetLocations()->GetDimension()); + aData->CalculateMedianLocations(kernel_name, median_locations); + + auto *CHAM_desc_C = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C).chameleon_desc; + auto *CHAM_desc_sub_C11 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C11).chameleon_desc; + auto *CHAM_desc_sub_C12 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C12).chameleon_desc; + auto *CHAM_desc_sub_C22 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C22).chameleon_desc; + auto *CHAM_desc_Z = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z).chameleon_desc; + auto *CHAM_desc_Z1 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_1).chameleon_desc; + auto *CHAM_desc_Z2 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_2).chameleon_desc; + auto *CHAM_desc_Z3 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_3).chameleon_desc; + auto *CHAM_desc_Zcpy = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_COPY).chameleon_desc; + auto *CHAM_desc_det = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_DETERMINANT).chameleon_desc; + auto *CHAM_desc_product = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_PRODUCT).chameleon_desc; + auto *CHAM_desc_sum = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_SUM).chameleon_desc; + auto *CHAM_desc_product1 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_PRODUCT_1).chameleon_desc; + auto *CHAM_desc_product2 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_PRODUCT_2).chameleon_desc; + auto *CHAM_desc_product3 = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_PRODUCT_3).chameleon_desc; + + T *determinant = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_DETERMINANT); *determinant = 0; - T *product = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_product); + T *product = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT); *product = 0; + T *sum; + if (aConfigurations.GetIsNonGaussian()) { + sum = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_SUM); + *sum = 0; + } n = CHAM_desc_C->m; nhrs = CHAM_desc_Z->n; string recovery_file = aConfigurations.GetRecoveryFile(); - int iter_count = aData.GetMleIterations(); + int iter_count = aData->GetMleIterations(); if (recovery_file.empty() || - !(this->recover((char *) (recovery_file.c_str()), iter_count, (T *) theta, &loglik, num_params))) { + !(this->Recover((char *) (recovery_file.c_str()), iter_count, (T *) theta, &loglik, num_params))) { START_TIMING(dzcpy_time); if (iter_count == 0) { // Save a copy of descZ into descZcpy for restoring each iteration (Only for the first iteration) this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, CHAM_desc_Z, CHAM_desc_Zcpy); } else { - VERBOSE("Re-store the original Z vector...") + VERBOSE("\tRe-store the original Z vector...") this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, CHAM_desc_Zcpy, CHAM_desc_Z); - VERBOSE("Done.") + VERBOSE("\tDone.") } STOP_TIMING(dzcpy_time); } //Generate new co-variance matrix C based on new theta - VERBOSE("Generate New Covariance Matrix...") + VERBOSE("\tGenerate New Covariance Matrix...") START_TIMING(matrix_gen_time); if (kernel_name == "bivariate_matern_parsimonious2" || @@ -162,9 +141,9 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa int distance_metric = aConfigurations.GetDistanceMetric(); - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_sub_C11, upper_lower, aData.GetLocations(), - aData.GetLocations(), &median_locations, univariate_theta, distance_metric, - &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_sub_C11, upper_lower, + aData->GetLocations(), aData->GetLocations(), &median_locations, + univariate_theta, distance_metric, &aKernel); nu12 = 0.5 * (theta[3] + theta[4]); rho = theta[5] * sqrt((tgamma(theta[3] + 1) * tgamma(theta[4] + 1)) / (tgamma(theta[3]) * tgamma(theta[4]))) * @@ -174,56 +153,78 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa univariate2_theta[1] = theta[2]; univariate2_theta[2] = nu12; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_sub_C12, upper_lower, &median_locations, - aData.GetLocations(), &median_locations, univariate2_theta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_sub_C12, upper_lower, + &median_locations, aData->GetLocations(), &median_locations, + univariate2_theta, 0, &aKernel); STOP_TIMING(matrix_gen_time); - VERBOSE("Done.") univariate3_theta[0] = theta[1]; univariate3_theta[1] = theta[2]; univariate3_theta[2] = theta[4]; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_sub_C22, upper_lower, &median_locations, - aData.GetLocations(), &median_locations, univariate2_theta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_sub_C22, upper_lower, + &median_locations, aData->GetLocations(), &median_locations, + univariate2_theta, 0, &aKernel); } else { int upper_lower = EXAGEOSTAT_LOWER; - this->CovarianceMatrixCodelet(*aData.GetDescriptorData(), CHAM_desc_C, upper_lower, aData.GetLocations(), - aData.GetLocations(), &median_locations, (T *) theta, 0, &aKernel); + RuntimeFunctions::CovarianceMatrix(*aData->GetDescriptorData(), CHAM_desc_C, upper_lower, + aData->GetLocations(), aData->GetLocations(), &median_locations, + (T *) theta, 0, &aKernel); } this->ExaGeoStatSequenceWait(pSequence); STOP_TIMING(matrix_gen_time); - VERBOSE("Done.") + VERBOSE("\tDone.") - VERBOSE("Cholesky factorization of Sigma...") + VERBOSE("\tCholesky factorization of Sigma...") START_TIMING(time_facto); this->ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, CHAM_desc_C, aConfigurations.GetBand(), nullptr, nullptr, 0, 0); STOP_TIMING(time_facto); flops += flops_dpotrf(n); - VERBOSE("Done.") + VERBOSE("\tDone.") //Calculate log(|C|) --> log(square(|L|)) - VERBOSE("Calculating the log determinant ...") + VERBOSE("\tCalculating the log determinant ...") START_TIMING(logdet_calculate); - this->ExaGeoStatMeasureDetTileAsync(CHAM_desc_C, pSequence, &request_array, CHAM_desc_det); + RuntimeFunctions::ExaGeoStatMeasureDetTileAsync(aConfigurations.GetComputation(), CHAM_desc_C, pSequence, + &request_array, CHAM_desc_det); this->ExaGeoStatSequenceWait(pSequence); logdet = 2 * (*determinant); STOP_TIMING(logdet_calculate); - VERBOSE("Done.") + VERBOSE("\tDone.") + + if (aConfigurations.GetIsNonGaussian()) { + VERBOSE("Transform Z vector to Gaussian field ...") + RuntimeFunctions::ExaGeoStatNonGaussianTransformTileAsync(aConfigurations.GetComputation(), CHAM_desc_Z, + (T *) theta, pSequence, &request_array[0]); + this->ExaGeoStatSequenceWait(pSequence); + VERBOSE("\tDone.") + + CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z, CHAM_desc_Z, 0, CHAM_desc_product); + + VERBOSE("Calculate non-Gaussian loglik ...") + RuntimeFunctions::ExaGeoStatNonGaussianLogLikeTileAsync(aConfigurations.GetComputation(), CHAM_desc_Z, + CHAM_desc_sum, (T *) theta, pSequence, + &request_array[0]); + this->ExaGeoStatSequenceWait(pSequence); + VERBOSE("\tDone.") + } // Solving Linear System (L*X=Z)--->inv(L)*Z - VERBOSE("Solving the linear system ...") + VERBOSE("\tSolving the linear system ...") START_TIMING(time_solve); this->ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, CHAM_desc_C, nullptr, nullptr, CHAM_desc_Z, 0); STOP_TIMING(time_solve); flops += flops_dtrsm(ChamLeft, n, nhrs); - VERBOSE("Done.") + VERBOSE("\tDone.") //Calculate MLE likelihood VERBOSE("Calculating the MLE likelihood function ...") - ExaGeoStatDoubleDotProduct(CHAM_desc_Z, CHAM_desc_product, pSequence, request_array); + RuntimeFunctions::ExaGeoStatDoubleDotProduct(CHAM_desc_Z, CHAM_desc_product, + pSequence, request_array); ExaGeoStatSequenceWait(pSequence); + if (kernel_name == "BivariateMaternParsimonious2Profile") { loglik = -(n / 2) + (n / 2) * log(n) - (n / 2) * log(dot_product) - 0.5 * logdet - (T) (n / 2.0) * log(2.0 * PI); @@ -235,7 +236,8 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa } else if (kernel_name == "BivariateMaternParsimoniousProfile") { loglik = -(n / 2) + (n / 2) * log(n) - (n / 2) * log(dot_product) - 0.5 * logdet - (double) (n / 2.0) * log(2.0 * PI); - this->ExaGeoStaStrideVectorTileAsync(CHAM_desc_Z, CHAM_desc_Z1, CHAM_desc_Z2, pSequence, &request_array[0]); + RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(CHAM_desc_Z, CHAM_desc_Z1, CHAM_desc_Z2, pSequence, + &request_array[0]); CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z1, CHAM_desc_Z1, 0, CHAM_desc_product1); CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z2, CHAM_desc_Z2, 0, CHAM_desc_product2); variance1 = (1.0 / (n / 2)) * dot_product1; @@ -245,8 +247,8 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa loglik = -(n / 3.0) + (n / 3.0) * log(n / 3.0) - (n / 3.0) * log(dot_product) - 0.5 * logdet - (double) (n / 3.0) * log(2.0 * PI); //to be optimized - this->ExaGeoStaStrideVectorTileAsync(CHAM_desc_Z, CHAM_desc_Z1, CHAM_desc_Z2, CHAM_desc_Z3, pSequence, - &request_array[0]); + RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(CHAM_desc_Z, CHAM_desc_Z1, CHAM_desc_Z2, CHAM_desc_Z3, + pSequence, &request_array[0]); CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z1, CHAM_desc_Z1, 0, CHAM_desc_product1); CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z2, CHAM_desc_Z2, 0, CHAM_desc_product2); CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_desc_Z3, CHAM_desc_Z3, 0, CHAM_desc_product3); @@ -254,19 +256,24 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa variance2 = (1.0 / (n / 3.0)) * dot_product2; } else { dot_product = *product; - loglik = -0.5 * dot_product - 0.5 * logdet - (double) (n / 2.0) * log(2.0 * PI); + loglik = -0.5 * dot_product - 0.5 * logdet; + if (aConfigurations.GetIsNonGaussian()) { + loglik = loglik - *sum - n * log(theta[3]) - (double) (n / 2.0) * log(2.0 * PI); + } else { + loglik = loglik - (double) (n / 2.0) * log(2.0 * PI); + } } - VERBOSE("Done.") + VERBOSE("\tDone.") //Distribute the values in the case of MPI -#if defined(CHAMELEON_USE_MPI) - MPI_Bcast(&loglik, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); +#ifdef USE_MPI + MPI_Bcast(&loglik, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); #endif - LOGGER(iter_count + 1 << " - Model Parameters (", true) + LOGGER("\t" << iter_count + 1 << " - Model Parameters (", true) if (aConfigurations.GetLogger()) { - fprintf(aConfigurations.GetFileLogPath(), " %3d- Model Parameters (", iter_count + 1); + fprintf(aConfigurations.GetFileLogPath(), "\t %d- Model Parameters (", iter_count + 1); } if ((aConfigurations.GetKernelName() == "BivariateMaternParsimoniousProfile") || @@ -294,43 +301,33 @@ T ChameleonImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardwa if (aConfigurations.GetLogger()) { fprintf(aConfigurations.GetFileLogPath(), ")----> LogLi: %.18f\n", loglik); } - LOGGER(" ---- Facto Time: " << time_facto) - LOGGER(" ---- Log Determent Time: " << logdet_calculate) - LOGGER(" ---- dtrsm Time: " << time_solve) - LOGGER(" ---- Matrix Generation Time: " << matrix_gen_time) - LOGGER(" ---- Total Time: " << time_facto + logdet_calculate + time_solve) - LOGGER(" ---- Gflop/s: " << flops / 1e9 / (time_facto + time_solve)) + VERBOSE("---- Facto Time: " << time_facto) + VERBOSE("---- Log Determent Time: " << logdet_calculate) + VERBOSE("---- dtrsm Time: " << time_solve) + VERBOSE("---- Matrix Generation Time: " << matrix_gen_time) + VERBOSE("---- Total Time: " << time_facto + logdet_calculate + time_solve) + VERBOSE("---- Gflop/s: " << flops / 1e9 / (time_facto + time_solve)) - aData.SetMleIterations(aData.GetMleIterations() + 1); + aData->SetMleIterations(aData->GetMleIterations() + 1); // for experiments and benchmarking accumulated_executed_time = - results::Results::GetInstance()->GetTotalModelingExecutionTime() + time_facto + logdet_calculate + + Results::GetInstance()->GetTotalModelingExecutionTime() + time_facto + logdet_calculate + time_solve; - results::Results::GetInstance()->SetTotalModelingExecutionTime(accumulated_executed_time); + Results::GetInstance()->SetTotalModelingExecutionTime(accumulated_executed_time); accumulated_flops = - results::Results::GetInstance()->GetTotalModelingFlops() + (flops / 1e9 / (time_facto + time_solve)); - results::Results::GetInstance()->SetTotalModelingFlops(accumulated_flops); + Results::GetInstance()->GetTotalModelingFlops() + (flops / 1e9 / (time_facto + time_solve)); + Results::GetInstance()->SetTotalModelingFlops(accumulated_flops); - results::Results::GetInstance()->SetMLEIterations(iter_count + 1); - results::Results::GetInstance()->SetMaximumTheta(vector(theta, theta + num_params)); - results::Results::GetInstance()->SetLogLikValue(loglik); + Results::GetInstance()->SetMLEIterations(iter_count + 1); + Results::GetInstance()->SetMaximumTheta(vector(theta, theta + num_params)); + Results::GetInstance()->SetLogLikValue(loglik); - aConfigurations.SetEstimatedTheta(aConfigurations.GetStartingTheta()); return loglik; } template -void -ChameleonImplementation::ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const UpperLower &aUpperLower) { - int status = CHAMELEON_Lap2Desc((cham_uplo_t) aUpperLower, apA, aLDA, (CHAM_desc_t *) apDescA); - if (status != CHAMELEON_SUCCESS) { - throw std::runtime_error("CHAMELEON_Lap2Desc Failed!"); - } -} - -template -void ChameleonImplementation::ExaGeoStatLapackCopyTile(const common::UpperLower &aUpperLower, void *apA, void *apB) { +void ChameleonImplementation::ExaGeoStatLapackCopyTile(const UpperLower &aUpperLower, void *apA, void *apB) { int status = CHAMELEON_dlacpy_Tile((cham_uplo_t) aUpperLower, (CHAM_desc_t *) apA, (CHAM_desc_t *) apB); if (status != CHAMELEON_SUCCESS) { throw std::runtime_error("CHAMELEON_dlacpy_Tile Failed!"); @@ -338,13 +335,8 @@ void ChameleonImplementation::ExaGeoStatLapackCopyTile(const common::UpperLow } template -void *ChameleonImplementation::ExaGeoStatDataGetAddr(void *apA, int aAm, int aAn) { - return RUNTIME_data_getaddr((CHAM_desc_t *) apA, aAm, aAn); -} - -template -void ChameleonImplementation::ExaGeoStatTrsmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, - const common::Trans &aTrans, const common::Diag &aDiag, +void ChameleonImplementation::ExaGeoStatTrsmTile(const Side &aSide, const UpperLower &aUpperLower, + const Trans &aTrans, const Diag &aDiag, const T &aAlpha, void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) { int status = CHAMELEON_dtrsm_Tile((cham_side_t) aSide, (cham_uplo_t) aUpperLower, (cham_trans_t) aTrans, @@ -369,137 +361,3 @@ void ChameleonImplementation::ExaGeoStatCreateSequence(void *apSequence) { throw std::runtime_error("CHAMELEON_Sequence_Create Failed!"); } } - -template -void -ChameleonImplementation::ExaGeoStatOptionsInit(void *apOptions, void *apContext, void *apSequence, void *apRequest) { - RUNTIME_options_init((RUNTIME_option_t *) apOptions, (CHAM_context_t *) apContext, - (RUNTIME_sequence_t *) apSequence, (RUNTIME_request_t *) apRequest); -} - -template -void ChameleonImplementation::ExaGeoStatOptionsFree(void *apOptions) { - RUNTIME_options_ws_free((RUNTIME_option_t *) apOptions); -} - -template -void ChameleonImplementation::ExaGeoStatOptionsFinalize(void *apOptions, void *apContext) { - RUNTIME_options_finalize((RUNTIME_option_t *) apOptions, (CHAM_context_t *) apContext); -} - -template -int ChameleonImplementation::ExaGeoStatMeasureDetTileAsync(void *apDescA, void *apSequence, void *apRequest, - void *apDescDet) { - - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m; - int temp; - auto Z = (CHAM_desc_t *) apDescA; - auto det = (CHAM_desc_t *) apDescDet; - struct starpu_codelet *cl = &this->cl_dmdet; - - for (m = 0; m < Z->mt; m++) { - temp = m == Z->mt - 1 ? Z->m - m * Z->mb : Z->mb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_R, ExaGeoStatDataGetAddr(Z, m, m), - STARPU_RW, ExaGeoStatDataGetAddr(det, 0, 0), - 0); - } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, (CHAM_context_t *) this->mpContext); - return CHAMELEON_SUCCESS; -} - -template -int ChameleonImplementation::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, - void *apSequence, void *apRequest) { - - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m, m0; - int temp; - auto A = (CHAM_desc_t *) apDescA; - auto B = (CHAM_desc_t *) apDescB; - auto C = (CHAM_desc_t *) apDescC; - struct starpu_codelet *cl = &this->cl_stride_vec; - - for (m = 0; m < A->mt; m++) { - temp = m == A->mt - 1 ? A->m - m * A->mb : A->mb; - m0 = m * A->mb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_VALUE, &m, sizeof(int), - STARPU_R, ExaGeoStatDataGetAddr(A, m, 0), - STARPU_W, ExaGeoStatDataGetAddr(B, (int) floor(m / 2.0), 0), - STARPU_W, ExaGeoStatDataGetAddr(C, (int) floor(m / 2.0), 0), -#if defined(CHAMELEON_CODELETS_HAVE_NAME) - STARPU_NAME, "stride_vec", -#endif - 0); - - } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, (CHAM_context_t *) this->mpContext); - return CHAMELEON_SUCCESS; -} - -template -int -ChameleonImplementation::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apDescD, - void *apSequence, void *apRequest) { - - // Check for initialize the Chameleon context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - - RUNTIME_option_t options; - RUNTIME_options_init(&options, (CHAM_context_t *) this->mpContext, (RUNTIME_sequence_t *) apSequence, - (RUNTIME_request_t *) apRequest); - - int m, m0; - int temp; - auto A = (CHAM_desc_t *) apDescA; - auto B = (CHAM_desc_t *) apDescB; - auto C = (CHAM_desc_t *) apDescC; - auto D = (CHAM_desc_t *) apDescD; - struct starpu_codelet *cl = &this->cl_tri_stride_vec; - - for (m = 0; m < A->mt; m++) { - temp = m == A->mt - 1 ? A->m - m * A->mb : A->mb; - m0 = m * A->mb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &m0, sizeof(int), - STARPU_VALUE, &m, sizeof(int), - STARPU_R, ExaGeoStatDataGetAddr(A, m, 0), - STARPU_W, ExaGeoStatDataGetAddr(B, (int) floor(m / 3.0), 0), - STARPU_W, ExaGeoStatDataGetAddr(C, (int) floor(m / 3.0), 0), - STARPU_W, ExaGeoStatDataGetAddr(D, (int) floor(m / 3.0), 0), -#if defined(CHAMELEON_CODELETS_HAVE_NAME) - STARPU_NAME, "tristride_vec", -#endif - 0); - - } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, (CHAM_context_t *) this->mpContext); - return CHAMELEON_SUCCESS; -} \ No newline at end of file diff --git a/src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.cpp b/src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.cpp similarity index 62% rename from src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.cpp rename to src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.cpp index c81d2d98..f08c8c3b 100644 --- a/src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonImplementationDense.cpp +++ b/src/linear-algebra-solvers/concrete/chameleon/dense/ChameleonDense.cpp @@ -1,18 +1,20 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ChameleonImplementationDense.cpp * @brief Dense Tile implementation of linear algebra methods. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-20 **/ -#include +#include + +#include using namespace std; @@ -20,10 +22,12 @@ using namespace exageostat::linearAlgebra::dense; template void -ChameleonImplementationDense::ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, - void *apCD, void *apCrk, const int &aMaxRank, const int &aAcc) { +ChameleonDense::ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, + void *apCD, void *apCrk, const int &aMaxRank, const int &aAcc) { int status = CHAMELEON_dpotrf_Tile((cham_uplo_t) aUpperLower, (CHAM_desc_t *) apA); if (status != CHAMELEON_SUCCESS) { throw std::runtime_error("CHAMELEON_dpotrf_Tile Failed, Matrix is not positive definite"); } + // Due to a leak in dense mode in Chameleon, We had to free the buffer manually. + mkl_free_buffers(); } \ No newline at end of file diff --git a/src/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.cpp b/src/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.cpp similarity index 89% rename from src/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.cpp rename to src/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.cpp index 649520e8..cc58316b 100644 --- a/src/linear-algebra-solvers/concrete/chameleon/diagonal-super-tile/ChameleonImplementationDST.cpp +++ b/src/linear-algebra-solvers/concrete/chameleon/dst/ChameleonDST.cpp @@ -1,18 +1,18 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file ChameleonImplementationDST.cpp * @brief Diagonal Super Tile implementation of linear algebra methods. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-03-20 **/ -#include +#include using namespace std; @@ -20,8 +20,8 @@ using namespace exageostat::linearAlgebra::diagonalSuperTile; using namespace exageostat::common; template -void ChameleonImplementationDST::ExaGeoStatPotrfTile(const UpperLower &aUpperLower, void *apA, int aBand, void *apCD, - void *apCrk, const int &aMaxRank, const int &aAcc) { +void ChameleonDST::ExaGeoStatPotrfTile(const UpperLower &aUpperLower, void *apA, int aBand, void *apCD, + void *apCrk, const int &aMaxRank, const int &aAcc) { CHAM_context_t *chameleon_context; RUNTIME_sequence_t *sequence = nullptr; @@ -39,8 +39,8 @@ void ChameleonImplementationDST::ExaGeoStatPotrfTile(const UpperLower &aUpper } template -int ChameleonImplementationDST::ExaGeoStatPotrfDiagonalTileAsync(const common::UpperLower &aUpperLower, void *apA, - int aBand, void *apSequence, void *apRequest) { +int ChameleonDST::ExaGeoStatPotrfDiagonalTileAsync(const common::UpperLower &aUpperLower, void *apA, + int aBand, void *apSequence, void *apRequest) { CHAM_context_t *chameleon_context; chameleon_context = chameleon_context_self(); @@ -87,8 +87,8 @@ int ChameleonImplementationDST::ExaGeoStatPotrfDiagonalTileAsync(const common template -void ChameleonImplementationDST::ExaGeoStatParallelPotrfDiagonal(const common::UpperLower &aUpperLower, void *apA, - int aBand, void *apSequence, void *apRequest) { +void ChameleonDST::ExaGeoStatParallelPotrfDiagonal(const common::UpperLower &aUpperLower, void *apA, + int aBand, void *apSequence, void *apRequest) { CHAM_context_t *chameleon_context; RUNTIME_option_t options; diff --git a/src/linear-algebra-solvers/concrete/tile-low-rank/HicmaImplementation.cpp b/src/linear-algebra-solvers/concrete/tile-low-rank/HicmaImplementation.cpp deleted file mode 100644 index c8a2b852..00000000 --- a/src/linear-algebra-solvers/concrete/tile-low-rank/HicmaImplementation.cpp +++ /dev/null @@ -1,395 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file HicmaImplementation.cpp - * @brief Sets up the HiCMA descriptors needed for the tile low rank computations in ExaGeoStat. - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-03-26 -**/ - -#include - -using namespace std; - -using namespace exageostat::linearAlgebra::tileLowRank; -using namespace exageostat::common; -using namespace exageostat::dataunits; -using namespace exageostat::kernels; -using namespace exageostat::helpers; -using namespace exageostat::hardware; -using namespace exageostat::configurations; - -//// TODO: These variables are required to avoid undefined reference to HiCMA global variables. -int store_only_diagonal_tiles = 1; -int use_scratch = 1; -int global_check = 0; //used to create dense matrix for accuracy check - -template -void HicmaImplementation::SetModelingDescriptors(ExaGeoStatData &aData, Configurations &aConfigurations) { - - int N = aConfigurations.GetProblemSize(); - int lts = aConfigurations.GetLowTileSize(); - int p_grid = aConfigurations.GetPGrid(); - int q_grid = aConfigurations.GetQGrid(); - bool is_OOC = aConfigurations.GetIsOOC(); - int max_rank = aConfigurations.GetMaxRank(); - - // Set the floating point precision based on the template type - FloatPoint float_point; - if (sizeof(T) == SIZE_OF_FLOAT) { - float_point = EXAGEOSTAT_REAL_FLOAT; - } else if (sizeof(T) == SIZE_OF_DOUBLE) { - float_point = EXAGEOSTAT_REAL_DOUBLE; - } else { - throw runtime_error("Unsupported for now!"); - } - - int MBD = lts; - int NBD = lts; - int MD = N; - int ND = MBD; - aData.GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CD, is_OOC, nullptr, float_point, MBD, - NBD, MBD * NBD, MD, ND, 0, 0, MD, ND, p_grid, q_grid); - int MBUV = lts; - int NBUV = 2 * max_rank; - int MUV; - int N_over_lts_times_lts = N / lts * lts; - if (N_over_lts_times_lts < N) { - MUV = N_over_lts_times_lts + lts; - } else if (N_over_lts_times_lts == N) { - MUV = N_over_lts_times_lts; - } else { - throw runtime_error("This case can't happens, N need to be >= lts*lts"); - } - int expr = MUV / lts; - int NUV = 2 * expr * max_rank; - aData.GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CUV, is_OOC, nullptr, float_point, - MBUV, NBUV, MBUV * NBUV, MUV, NUV, 0, 0, MUV, NUV, p_grid, q_grid); - auto *HICMA_descCUV = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CUV).hicma_desc; - int MBrk = 1; - int NBrk = 1; - int Mrk = HICMA_descCUV->mt; - int Nrk = HICMA_descCUV->mt; - aData.GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CRK, is_OOC, nullptr, float_point, - MBrk, NBrk, MBrk * NBrk, Mrk, Nrk, 0, 0, Mrk, Nrk, p_grid, q_grid); - aData.GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_Z_COPY, is_OOC, nullptr, float_point, - lts, lts, lts * lts, N, 1, 0, 0, N, 1, p_grid, q_grid); -} - -template -T HicmaImplementation::ExaGeoStatMLETile(const hardware::ExaGeoStatHardware &aHardware, ExaGeoStatData &aData, - Configurations &aConfigurations, const double *theta, - T *apMeasurementsMatrix, const Kernel &aKernel) { - - this->SetContext(aHardware.GetContext(aConfigurations.GetComputation())); - if (!aData.GetDescriptorData()->GetIsDescriptorInitiated()) { - this->InitiateDescriptors(aConfigurations, *aData.GetDescriptorData(), apMeasurementsMatrix); - } - // Create a Hicma sequence, if not initialized before through the same descriptors - RUNTIME_request_t request_array[2] = {HICMA_REQUEST_INITIALIZER, HICMA_REQUEST_INITIALIZER}; - if (!aData.GetDescriptorData()->GetSequence()) { - HICMA_sequence_t *sequence; - this->ExaGeoStatCreateSequence(&sequence); - aData.GetDescriptorData()->SetSequence(sequence); - aData.GetDescriptorData()->SetRequest(request_array); - } - auto pSequence = (HICMA_sequence_t *) aData.GetDescriptorData()->GetSequence(); - - //Initialization - T loglik, logdet, test_time, variance, variance1 = 1, variance2 = 1, variance3, dot_product, dot_product1, dot_product2, dot_product3, dzcpy_time, time_facto, time_solve, logdet_calculate, matrix_gen_time; - double accumulated_executed_time, accumulated_flops; - - int NRHS, i; - T flops = 0.0; - - int N; - int lts; - int max_rank = aConfigurations.GetMaxRank(); - int iter_count = aData.GetMleIterations(); - auto kernel_name = aConfigurations.GetKernelName(); - int num_params = aKernel.GetParametersNumbers(); - int acc = aConfigurations.GetAccuracy(); - - if (iter_count == 0) { - this->SetModelingDescriptors(aData, aConfigurations); - } - auto *HICMA_descCUV = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CUV).hicma_desc; - auto *HICMA_descC = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_C).hicma_desc; - auto *HICMA_descCD = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CD).hicma_desc; - auto *HICMA_descCrk = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_CRK).hicma_desc; - auto *HICMA_descZ = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z).hicma_desc; - auto *CHAM_descZ = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z).chameleon_desc; - auto *CHAM_descZcpy = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_COPY).chameleon_desc; - auto *HICMA_descZcpy = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_Z_COPY).hicma_desc; - auto *HICMA_desc_det = aData.GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, - DescriptorName::DESCRIPTOR_DETERMINANT).hicma_desc; - auto *CHAM_desc_product = aData.GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, - DescriptorName::DESCRIPTOR_PRODUCT).chameleon_desc; - - N = HICMA_descCUV->m; - NRHS = HICMA_descZ->n; - lts = HICMA_descZ->mb; - - T *determinant = aData.GetDescriptorData()->GetDescriptorMatrix(HICMA_DESCRIPTOR, HICMA_desc_det); - *determinant = 0; - T *product = aData.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, CHAM_desc_product); - *product = 0; - - string recovery_file = aConfigurations.GetRecoveryFile(); - if (recovery_file.empty() || - !(this->recover((char *) (recovery_file.c_str()), iter_count, (T *) theta, &loglik, num_params))) { - if (iter_count == 0) { - auto *z = new T[N]; - this->ExaGeoStatDesc2Lap(z, N, CHAM_descZ, EXAGEOSTAT_UPPER_LOWER); - this->ExaGeoStatLap2Desc(z, N, HICMA_descZ, EXAGEOSTAT_UPPER_LOWER); - delete[] z; - // Save a copy of descZ into descZcpy for restoring each iteration - this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, HICMA_descZ, HICMA_descZcpy); - // Save another copy into descZcpy for chameleon, This is in case of other operations after Modeling. ex: Prediction. - CHAMELEON_dlacpy_Tile(ChamUpperLower, CHAM_descZ, CHAM_descZcpy); - } - } - //Matrix generation part. - VERBOSE("LR:Generate New Covariance Matrix...") - START_TIMING(matrix_gen_time); - - HICMA_problem_t hicma_problem; - hicma_problem.theta = (double *) theta; - hicma_problem.noise = 1e-4; - hicma_problem.ndim = 2; - - hicma_problem.kernel_type = - aConfigurations.GetDistanceMetric() == common::GREAT_CIRCLE_DISTANCE ? STARSH_SPATIAL_MATERN2_GCD - : STARSH_SPATIAL_MATERN2_SIMD; - HICMA_zgenerate_problem(HICMA_STARSH_PROB_GEOSTAT, 'S', 0, N, lts, HICMA_descCUV->mt, HICMA_descCUV->nt, - &hicma_problem); - int compress_diag = 0; - HICMA_zgytlr_Tile(EXAGEOSTAT_LOWER, HICMA_descCUV, HICMA_descCD, HICMA_descCrk, 0, max_rank, pow(10, -1.0 * acc), - compress_diag, HICMA_descC); - - STOP_TIMING(matrix_gen_time); - VERBOSE("Done.") - //****************************** - VERBOSE("LR: re-Copy z...") - START_TIMING(test_time); - //re-store old Z - this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, HICMA_descZcpy, HICMA_descZ); - STOP_TIMING(test_time); - VERBOSE("Done.") - - //Calculate Cholesky Factorization (C=LL-1) - VERBOSE("LR: Cholesky factorization of Sigma...") - START_TIMING(time_facto); - this->ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, HICMA_descCUV, 0, HICMA_descCD, HICMA_descCrk, max_rank, acc); - - STOP_TIMING(time_facto); - flops = flops + flops_dpotrf(N); - VERBOSE("Done.") - - //Calculate log(|C|) --> log(square(|L|)) - VERBOSE("LR:Calculating the log determinant ...") - START_TIMING(logdet_calculate); - ExaGeoStatMeasureDetTileAsync(HICMA_descCD, pSequence, &request_array[0], HICMA_desc_det); - ExaGeoStatSequenceWait(pSequence); - - logdet = 2 * (*determinant); - STOP_TIMING(logdet_calculate); - VERBOSE("Done.") - - //Solving Linear System (L*X=Z)--->inv(L)*Z - VERBOSE("LR:Solving the linear system ...") - START_TIMING(time_solve); - //Compute triangular solve LC*X = Z - this->ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, - HICMA_descCUV, HICMA_descCD, HICMA_descCrk, HICMA_descZ, max_rank); - STOP_TIMING(time_solve); - flops = flops + flops_dtrsm(ChamLeft, N, NRHS); - VERBOSE("Done.") - - VERBOSE("LR:Calculating dot product...") - CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_descZ, CHAM_descZ, 0, CHAM_desc_product); - dot_product = *product; - loglik = -0.5 * dot_product - 0.5 * logdet - (double) (N / 2.0) * log(2.0 * PI); - VERBOSE("Done.") - - LOGGER(iter_count + 1 << " - Model Parameters (", true) - if (aConfigurations.GetLogger()) { - fprintf(aConfigurations.GetFileLogPath(), " %3d- Model Parameters (", iter_count + 1); - } - if ((aConfigurations.GetKernelName() == "bivariate_matern_parsimonious_profile") || - (aConfigurations.GetKernelName() == "bivariate_matern_parsimonious2_profile")) { - LOGGER(setprecision(8) << variance1 << setprecision(8) << variance2) - if (aConfigurations.GetLogger()) { - fprintf(aConfigurations.GetFileLogPath(), "%.8f, %.8f,", variance1, variance2); - } - i = 2; - } else { - i = 0; - } - - for (; i < num_params; i++) { - LOGGER_PRECISION(theta[i]) - if (i < num_params - 1) { - LOGGER_PRECISION(", ") - } - if (aConfigurations.GetLogger()) { - fprintf(aConfigurations.GetFileLogPath(), "%.8f, ", theta[i]); - } - } - LOGGER_PRECISION(")----> LogLi: " << loglik << "\n", 18) - - if (aConfigurations.GetLogger()) { - fprintf(aConfigurations.GetFileLogPath(), ")----> LogLi: %.18f\n", loglik); - } - - LOGGER(" ---- Facto Time: " << time_facto) - LOGGER(" ---- Log Determent Time: " << logdet_calculate) - LOGGER(" ---- dtrsm Time: " << time_solve) - LOGGER(" ---- Matrix Generation Time: " << matrix_gen_time) - LOGGER(" ---- Total Time: " << time_facto + logdet_calculate + time_solve) - LOGGER(" ---- Gflop/s: " << flops / 1e9 / (time_facto + time_solve)) - - aData.SetMleIterations(aData.GetMleIterations() + 1); - - // for experiments and benchmarking - accumulated_executed_time = - results::Results::GetInstance()->GetTotalModelingExecutionTime() + time_facto + logdet_calculate + - time_solve; - results::Results::GetInstance()->SetTotalModelingExecutionTime(accumulated_executed_time); - accumulated_flops = - results::Results::GetInstance()->GetTotalModelingFlops() + (flops / 1e9 / (time_facto + time_solve)); - results::Results::GetInstance()->SetTotalModelingFlops(accumulated_flops); - - results::Results::GetInstance()->SetMLEIterations(iter_count + 1); - results::Results::GetInstance()->SetMaximumTheta(vector(theta, theta + num_params)); - results::Results::GetInstance()->SetLogLikValue(loglik); - - aConfigurations.SetEstimatedTheta(aConfigurations.GetStartingTheta()); - return loglik; -} - - -template -void HicmaImplementation::ExaGeoStatLapackCopyTile(const UpperLower &aUpperLower, void *apA, void *apB) { - int status = HICMA_dlacpy_Tile(aUpperLower, (HICMA_desc_t *) apA, (HICMA_desc_t *) apB); - if (status != HICMA_SUCCESS) { - throw std::runtime_error("CHAMELEON_dlacpy_Tile Failed!"); - } -} - -template -void -HicmaImplementation::ExaGeoStatOptionsInit(void *apOptions, void *apContext, void *apSequence, void *apRequest) { - HICMA_RUNTIME_options_init((HICMA_option_t *) apOptions, (HICMA_context_t *) apContext, - (HICMA_sequence_t *) apSequence, (HICMA_request_t *) apRequest); -} - -template -void HicmaImplementation::ExaGeoStatOptionsFree(void *apOptions) { - HICMA_RUNTIME_options_ws_free((HICMA_option_t *) apOptions); - -} - -template -void HicmaImplementation::ExaGeoStatSequenceWait(void *apSequence) { - HICMA_Sequence_Wait((HICMA_sequence_t *) apSequence); -} - -template -void HicmaImplementation::ExaGeoStatCreateSequence(void *apSequence) { - int status = HICMA_Sequence_Create((HICMA_sequence_t **) apSequence); - if (status != HICMA_SUCCESS) { - throw std::runtime_error("HICMA_Sequence_Create Failed!"); - } -} - -template -void HicmaImplementation::ExaGeoStatOptionsFinalize(void *apOptions, void *apContext) { - RUNTIME_options_finalize((RUNTIME_option_t *) apOptions, (CHAM_context_t *) apContext); - -} - -template -void HicmaImplementation::ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, - void *apCD, void *apCrk, const int &aMaxRank, const int &aAcc) { - int status = HICMA_dpotrf_Tile(EXAGEOSTAT_LOWER, (HICMA_desc_t *) apA, (HICMA_desc_t *) apCD, - (HICMA_desc_t *) apCrk, aBand, aMaxRank, pow(10, -1.0 * aAcc)); - if (status != HICMA_SUCCESS) { - throw std::runtime_error("HICMA_dpotrf_Tile Failed, Matrix is not positive definite"); - } - -} - -template -void HicmaImplementation::ExaGeoStatTrsmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, - const common::Trans &aTrans, const common::Diag &aDiag, const T &aAlpha, - void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) { - - int status = HICMA_dtrsmd_Tile(aSide, aUpperLower, aTrans, aDiag, aAlpha, (HICMA_desc_t *) apA, - (HICMA_desc_t *) apCD, (HICMA_desc_t *) apCrk, (HICMA_desc_t *) apZ, aMaxRank); - if (status != HICMA_SUCCESS) { - throw std::runtime_error("HICMA_dtrsmd_Tile Failed!"); - } -} - -template -int HicmaImplementation::ExaGeoStatMeasureDetTileAsync(void *apDescA, void *apSequence, void *apRequest, - void *apDescDet) { - - // Check for initialize the Hicma context. - if (!this->mpContext) { - throw std::runtime_error( - "ExaGeoStat hardware is not initialized, please use 'ExaGeoStatHardware(computation, cores_number, gpu_numbers);'."); - } - HICMA_option_t options; - this->ExaGeoStatOptionsInit(&options, this->mpContext, apSequence, apRequest); - - int m; - int temp; - auto Z = (HICMA_desc_t *) apDescA; - auto det = (HICMA_desc_t *) apDescDet; - struct starpu_codelet *cl = &this->cl_dmdet; - - for (m = 0; m < Z->mt; m++) { - temp = m == Z->mt - 1 ? Z->m - m * Z->mb : Z->mb; - starpu_insert_task(cl, - STARPU_VALUE, &temp, sizeof(int), - STARPU_VALUE, &temp, sizeof(int), - STARPU_R, ExaGeoStatDataGetAddr(Z, m, 0), - STARPU_RW, ExaGeoStatDataGetAddr(det, 0, 0), - 0); - } - this->ExaGeoStatOptionsFree(&options); - this->ExaGeoStatOptionsFinalize(&options, (HICMA_context_t *) - this->mpContext); - return HICMA_SUCCESS; -} - - -template -void HicmaImplementation::ExaGeoStatLap2Desc(T *apA, const int &aLDA, void *apDescA, const UpperLower &aUpperLower) { - int status = HICMA_Lapack_to_Tile(apA, aLDA, (HICMA_desc_t *) apDescA); - if (status != HICMA_SUCCESS) { - throw std::runtime_error("HICMA_Lapack_to_Tile Failed!"); - } -} - -template -void *HicmaImplementation::ExaGeoStatDataGetAddr(void *apA, int aAm, int aAn) { - return HICMA_RUNTIME_data_getaddr((HICMA_desc_t *) apA, aAm, aAn); - -} \ No newline at end of file diff --git a/src/linear-algebra-solvers/concrete/tlr/HicmaImplementation.cpp b/src/linear-algebra-solvers/concrete/tlr/HicmaImplementation.cpp new file mode 100644 index 00000000..c297bb01 --- /dev/null +++ b/src/linear-algebra-solvers/concrete/tlr/HicmaImplementation.cpp @@ -0,0 +1,404 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file HicmaImplementation.cpp + * @brief Sets up the HiCMA descriptors needed for the tile low rank computations in ExaGeoStat. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-04 +**/ + +#include + +#ifdef USE_MPI + +#include + +#endif + +#include + +using namespace std; + +using namespace exageostat::linearAlgebra::tileLowRank; +using namespace exageostat::common; +using namespace exageostat::runtime; +using namespace exageostat::dataunits; +using namespace exageostat::kernels; +using namespace exageostat::helpers; +using namespace exageostat::results; + +int store_only_diagonal_tiles = 1; +int use_scratch = 1; +int global_check = 0; //used to create dense matrix for accuracy check + +template +void HicmaImplementation::SetModelingDescriptors(std::unique_ptr> &aData, + configurations::Configurations &aConfigurations, const int &aP) { + + int full_problem_size = aConfigurations.GetProblemSize() * aP; + int lts = aConfigurations.GetLowTileSize(); + int p_grid = ExaGeoStatHardware::GetPGrid(); + int q_grid = ExaGeoStatHardware::GetQGrid(); + bool is_OOC = aConfigurations.GetIsOOC(); + int max_rank = aConfigurations.GetMaxRank(); + + // Set the floating point precision based on the template type + FloatPoint float_point; + if (sizeof(T) == SIZE_OF_FLOAT) { + float_point = EXAGEOSTAT_REAL_FLOAT; + } else if (sizeof(T) == SIZE_OF_DOUBLE) { + float_point = EXAGEOSTAT_REAL_DOUBLE; + } else { + throw runtime_error("Unsupported for now!"); + } + + int MBD = lts; + int NBD = lts; + int MD = full_problem_size; + int ND = MBD; +#ifdef USE_MPI + // Due to a bug in HiCMA with MPI, the first created descriptor is not seen. + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CD, is_OOC, nullptr, float_point, + lts, lts, lts * lts, full_problem_size, 1, 0, 0, full_problem_size, 1, + p_grid, q_grid); +#endif + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CD, is_OOC, nullptr, float_point, + MBD, NBD, MBD * NBD, MD, ND, 0, 0, MD, ND, p_grid, q_grid); + int MBUV = lts; + int NBUV = 2 * max_rank; + int MUV; + int N_over_lts_times_lts = full_problem_size / lts * lts; + if (N_over_lts_times_lts < full_problem_size) { + MUV = N_over_lts_times_lts + lts; + } else if (N_over_lts_times_lts == full_problem_size) { + MUV = N_over_lts_times_lts; + } else { + throw runtime_error("This case can't happens, N need to be >= lts*lts"); + } + int expr = MUV / lts; + int NUV = 2 * expr * max_rank; + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CUV, is_OOC, nullptr, float_point, + MBUV, NBUV, MBUV * NBUV, MUV, NUV, 0, 0, MUV, NUV, p_grid, q_grid); + auto *HICMA_descCUV = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CUV).hicma_desc; + int MBrk = 1; + int NBrk = 1; + int Mrk = HICMA_descCUV->mt; + int Nrk = HICMA_descCUV->mt; + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_CRK, is_OOC, nullptr, float_point, + MBrk, NBrk, MBrk * NBrk, Mrk, Nrk, 0, 0, Mrk, Nrk, p_grid, q_grid); + + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_Z, is_OOC, nullptr, float_point, + lts, lts, lts * lts, full_problem_size, 1, 0, 0, full_problem_size, 1, + p_grid, q_grid); + + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_Z_COPY, is_OOC, nullptr, float_point, + lts, lts, lts * lts, full_problem_size, 1, 0, 0, full_problem_size, 1, + p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_DETERMINANT, is_OOC, nullptr, + float_point, lts, lts, lts * lts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + + if (aConfigurations.GetIsNonGaussian()) { + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_PRODUCT, is_OOC, nullptr, + float_point, + lts, lts, lts * lts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + aData->GetDescriptorData()->SetDescriptor(common::HICMA_DESCRIPTOR, DESCRIPTOR_SUM, is_OOC, nullptr, + float_point, + lts, lts, lts * lts, 1, 1, 0, 0, 1, 1, p_grid, q_grid); + } +} + +template +T HicmaImplementation::ExaGeoStatMLETile(std::unique_ptr> &aData, + configurations::Configurations &aConfigurations, const double *theta, + T *apMeasurementsMatrix, const Kernel &aKernel) { + + if (!aData->GetDescriptorData()->GetIsDescriptorInitiated()) { + this->InitiateDescriptors(aConfigurations, *aData->GetDescriptorData(), aKernel.GetVariablesNumber(), + apMeasurementsMatrix); + } + // Create a Hicma sequence, if not initialized before through the same descriptors + RUNTIME_request_t request_array[2] = {HICMA_REQUEST_INITIALIZER, HICMA_REQUEST_INITIALIZER}; + if (!aData->GetDescriptorData()->GetSequence()) { + HICMA_sequence_t *sequence; + this->ExaGeoStatCreateSequence(&sequence); + aData->GetDescriptorData()->SetSequence(sequence); + aData->GetDescriptorData()->SetRequest(request_array); + } + auto pSequence = (HICMA_sequence_t *) aData->GetDescriptorData()->GetSequence(); + + //Initialization + T loglik, logdet, test_time, variance, variance1 = 1, variance2 = 1, variance3, dot_product, dot_product1, dot_product2, dot_product3, dzcpy_time, time_facto, time_solve, logdet_calculate, matrix_gen_time; + double accumulated_executed_time, accumulated_flops; + + int NRHS, i; + T flops = 0.0; + + int N; + int lts; + int max_rank = aConfigurations.GetMaxRank(); + int iter_count = aData->GetMleIterations(); + auto kernel_name = aConfigurations.GetKernelName(); + int num_params = aKernel.GetParametersNumbers(); + int acc = aConfigurations.GetAccuracy(); + + if (iter_count == 0) { + this->SetModelingDescriptors(aData, aConfigurations, aKernel.GetVariablesNumber()); + } + auto *HICMA_descCUV = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CUV).hicma_desc; + auto *HICMA_descC = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_C).hicma_desc; + auto *HICMA_descCD = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CD).hicma_desc; + auto *HICMA_descCrk = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_CRK).hicma_desc; + auto *HICMA_descZ = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z).hicma_desc; + auto *CHAM_descZ = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z).chameleon_desc; + auto *CHAM_descZcpy = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_COPY).chameleon_desc; + auto *HICMA_descZcpy = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_Z_COPY).hicma_desc; + auto *HICMA_desc_det = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_DETERMINANT).hicma_desc; + auto *CHAM_desc_product = aData->GetDescriptorData()->GetDescriptor(DescriptorType::CHAMELEON_DESCRIPTOR, + DescriptorName::DESCRIPTOR_PRODUCT).chameleon_desc; + auto *HICMA_desc_sum = aData->GetDescriptorData()->GetDescriptor(DescriptorType::HICMA_DESCRIPTOR, + DescriptorName::DESCRIPTOR_SUM).chameleon_desc; + N = HICMA_descCUV->m; + NRHS = HICMA_descZ->n; + lts = HICMA_descZ->mb; + + T *determinant = aData->GetDescriptorData()->GetDescriptorMatrix(HICMA_DESCRIPTOR, DESCRIPTOR_DETERMINANT); + *determinant = 0; + T *product = aData->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT); + *product = 0; + T *sum; + + string recovery_file = aConfigurations.GetRecoveryFile(); + if (recovery_file.empty() || + !(this->Recover((char *) (recovery_file.c_str()), iter_count, (T *) theta, &loglik, num_params))) { + if (iter_count == 0) { + // Copy dense matrix Z into tile low rank Z. + this->CopyDescriptors(CHAM_descZ, HICMA_descZ, N, CHAMELEON_TO_HICMA); + // Save a copy of descZ into descZcpy for restoring each iteration + this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, HICMA_descZ, HICMA_descZcpy); + // Save another copy into descZcpy for chameleon, This is in case of other operations after Modeling. ex: Prediction. + CHAMELEON_dlacpy_Tile(ChamUpperLower, CHAM_descZ, CHAM_descZcpy); + } + } + //Matrix generation part. + VERBOSE("LR:Generate New Covariance Matrix...") + START_TIMING(matrix_gen_time); + + HICMA_problem_t hicma_problem; + hicma_problem.theta = (double *) theta; + hicma_problem.noise = 1e-4; + hicma_problem.ndim = 2; + + hicma_problem.kernel_type = + aConfigurations.GetDistanceMetric() == common::GREAT_CIRCLE_DISTANCE ? STARSH_SPATIAL_MATERN2_GCD + : STARSH_SPATIAL_MATERN2_SIMD; + int hicma_data_type; + if (aConfigurations.GetIsNonGaussian()) { + hicma_data_type = HICMA_STARSH_PROB_GEOSTAT_NON_GAUSSIAN; + } else { + hicma_data_type = HICMA_STARSH_PROB_GEOSTAT; + } + + HICMA_zgenerate_problem(hicma_data_type, 'S', 0, N, lts, HICMA_descCUV->mt, HICMA_descCUV->nt, + &hicma_problem); + int compress_diag = 0; + HICMA_zgytlr_Tile(EXAGEOSTAT_LOWER, HICMA_descCUV, HICMA_descCD, HICMA_descCrk, 0, max_rank, pow(10, -1.0 * acc), + compress_diag, HICMA_descC); + + STOP_TIMING(matrix_gen_time); + VERBOSE("Done.") + //****************************** + VERBOSE("LR: re-Copy z...") + START_TIMING(test_time); + //re-store old Z + this->ExaGeoStatLapackCopyTile(EXAGEOSTAT_UPPER_LOWER, HICMA_descZcpy, HICMA_descZ); + STOP_TIMING(test_time); + VERBOSE("Done.") + + //Calculate Cholesky Factorization (C=LL-1) + VERBOSE("LR: Cholesky factorization of Sigma...") + START_TIMING(time_facto); + this->ExaGeoStatPotrfTile(EXAGEOSTAT_LOWER, HICMA_descCUV, 0, HICMA_descCD, HICMA_descCrk, max_rank, + pow(10, -1.0 * acc)); + + STOP_TIMING(time_facto); + flops = flops + flops_dpotrf(N); + VERBOSE("Done.") + + //Calculate log(|C|) --> log(square(|L|)) + VERBOSE("LR:Calculating the log determinant ...") + START_TIMING(logdet_calculate); + RuntimeFunctions::ExaGeoStatMeasureDetTileAsync(aConfigurations.GetComputation(), HICMA_descCD, pSequence, + &request_array[0], HICMA_desc_det); + ExaGeoStatSequenceWait(pSequence); + logdet = 2 * (*determinant); + STOP_TIMING(logdet_calculate); + VERBOSE("Done.") + + if (aConfigurations.GetIsNonGaussian()) { + VERBOSE("Transform Z vector to Gaussian field ...") + RuntimeFunctions::ExaGeoStatNonGaussianTransformTileAsync(aConfigurations.GetComputation(), HICMA_descZ, + (T *) theta, pSequence, &request_array[0]); + ExaGeoStatSequenceWait(pSequence); + + VERBOSE(" Done.") + sum = aData->GetDescriptorData()->GetDescriptorMatrix(HICMA_DESCRIPTOR, DESCRIPTOR_SUM); + *sum = 0; + + VERBOSE("LR:Calculating dot product...") + CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_descZ, CHAM_descZ, 0, CHAM_desc_product); + VERBOSE(" Done.") + +#ifdef USE_MPI + double global_sum; + double local_sum = *product; + MPI_Allreduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); +#endif + RuntimeFunctions::ExaGeoStatNonGaussianLogLikeTileAsync(aConfigurations.GetComputation(), HICMA_descZ, + HICMA_desc_sum, (T *) theta, pSequence, + &request_array[0]); + ExaGeoStatSequenceWait(pSequence); + VERBOSE(" Done.") + } + + //Solving Linear System (L*X=Z)--->inv(L)*Z + VERBOSE("LR:Solving the linear system ...") + START_TIMING(time_solve); + //Compute triangular solve LC*X = Z + this->ExaGeoStatTrsmTile(EXAGEOSTAT_LEFT, EXAGEOSTAT_LOWER, EXAGEOSTAT_NO_TRANS, EXAGEOSTAT_NON_UNIT, 1, + HICMA_descCUV, HICMA_descCD, HICMA_descCrk, HICMA_descZ, max_rank); + STOP_TIMING(time_solve); + flops = flops + flops_dtrsm(ChamLeft, N, NRHS); + VERBOSE("Done.") + + VERBOSE("Copy to chameleon") + this->CopyDescriptors(HICMA_descZ, CHAM_descZ, N, HICMA_TO_CHAMELEON); + + VERBOSE("LR:Calculating dot product...") + CHAMELEON_dgemm_Tile(ChamTrans, ChamNoTrans, 1, CHAM_descZ, CHAM_descZ, 0, CHAM_desc_product); + dot_product = *product; + loglik = -0.5 * dot_product - 0.5 * logdet; + if (aConfigurations.GetIsNonGaussian()) { + loglik = loglik - *sum - N * log(theta[3]) - (double) (N / 2.0) * log(2.0 * PI); + } else { + loglik = loglik - (double) (N / 2.0) * log(2.0 * PI); + } + VERBOSE("Done.") + + LOGGER("\t" << iter_count + 1 << " - Model Parameters (", true) + if (aConfigurations.GetLogger()) { + fprintf(aConfigurations.GetFileLogPath(), "\t %d- Model Parameters (", iter_count + 1); + } + if ((aConfigurations.GetKernelName() == "bivariate_matern_parsimonious_profile") || + (aConfigurations.GetKernelName() == "bivariate_matern_parsimonious2_profile")) { + LOGGER(setprecision(8) << variance1 << setprecision(8) << variance2) + if (aConfigurations.GetLogger()) { + fprintf(aConfigurations.GetFileLogPath(), "%.8f, %.8f,", variance1, variance2); + } + i = 2; + } else { + i = 0; + } + + for (; i < num_params; i++) { + LOGGER_PRECISION(theta[i]) + if (i < num_params - 1) { + LOGGER_PRECISION(", ") + } + if (aConfigurations.GetLogger()) { + fprintf(aConfigurations.GetFileLogPath(), "%.8f, ", theta[i]); + } + } + LOGGER_PRECISION(")----> LogLi: " << loglik << "\n", 18) + + if (aConfigurations.GetLogger()) { + fprintf(aConfigurations.GetFileLogPath(), ")----> LogLi: %.18f\n", loglik); + } + + VERBOSE(" ---- Facto Time: " << time_facto) + VERBOSE(" ---- Log Determent Time: " << logdet_calculate) + VERBOSE(" ---- dtrsm Time: " << time_solve) + VERBOSE(" ---- Matrix Generation Time: " << matrix_gen_time) + VERBOSE(" ---- Total Time: " << time_facto + logdet_calculate + time_solve) + VERBOSE(" ---- Gflop/s: " << flops / 1e9 / (time_facto + time_solve)) + + aData->SetMleIterations(aData->GetMleIterations() + 1); + + // for experiments and benchmarking + accumulated_executed_time = + Results::GetInstance()->GetTotalModelingExecutionTime() + time_facto + logdet_calculate + + time_solve; + Results::GetInstance()->SetTotalModelingExecutionTime(accumulated_executed_time); + accumulated_flops = + Results::GetInstance()->GetTotalModelingFlops() + (flops / 1e9 / (time_facto + time_solve)); + Results::GetInstance()->SetTotalModelingFlops(accumulated_flops); + + Results::GetInstance()->SetMLEIterations(iter_count + 1); + Results::GetInstance()->SetMaximumTheta(vector(theta, theta + num_params)); + Results::GetInstance()->SetLogLikValue(loglik); + + aConfigurations.SetEstimatedTheta(aConfigurations.GetStartingTheta()); + // Due to a leak in HiCMA in ZGEMM, We had to free the buffer manually. + mkl_free_buffers(); + + return loglik; +} + + +template +void HicmaImplementation::ExaGeoStatLapackCopyTile(const UpperLower &aUpperLower, void *apA, void *apB) { + int status = HICMA_dlacpy_Tile(aUpperLower, (HICMA_desc_t *) apA, (HICMA_desc_t *) apB); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("CHAMELEON_dlacpy_Tile Failed!"); + } +} + +template +void HicmaImplementation::ExaGeoStatSequenceWait(void *apSequence) { + HICMA_Sequence_Wait((HICMA_sequence_t *) apSequence); +} + +template +void HicmaImplementation::ExaGeoStatCreateSequence(void *apSequence) { + int status = HICMA_Sequence_Create((HICMA_sequence_t **) apSequence); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("HICMA_Sequence_Create Failed!"); + } +} + +template +void HicmaImplementation::ExaGeoStatPotrfTile(const common::UpperLower &aUpperLower, void *apA, int aBand, + void *apCD, void *apCrk, const int &aMaxRank, const int &aAcc) { + int status = HICMA_dpotrf_Tile(EXAGEOSTAT_LOWER, (HICMA_desc_t *) apA, (HICMA_desc_t *) apCD, + (HICMA_desc_t *) apCrk, aBand, aMaxRank, pow(10, -1.0 * aAcc)); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("HICMA_dpotrf_Tile Failed, Matrix is not positive definite"); + } + +} + +template +void HicmaImplementation::ExaGeoStatTrsmTile(const common::Side &aSide, const common::UpperLower &aUpperLower, + const common::Trans &aTrans, const common::Diag &aDiag, const T &aAlpha, + void *apA, void *apCD, void *apCrk, void *apZ, const int &aMaxRank) { + + int status = HICMA_dtrsmd_Tile(aSide, aUpperLower, aTrans, aDiag, aAlpha, (HICMA_desc_t *) apA, + (HICMA_desc_t *) apCD, (HICMA_desc_t *) apCrk, (HICMA_desc_t *) apZ, aMaxRank); + if (status != HICMA_SUCCESS) { + throw std::runtime_error("HICMA_dtrsmd_Tile Failed!"); + } +} diff --git a/src/prediction/CMakeLists.txt b/src/prediction/CMakeLists.txt index 63a1f946..1de78426 100644 --- a/src/prediction/CMakeLists.txt +++ b/src/prediction/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-06-08 diff --git a/src/prediction/Prediction.cpp b/src/prediction/Prediction.cpp index 1550c5df..2cf565c2 100644 --- a/src/prediction/Prediction.cpp +++ b/src/prediction/Prediction.cpp @@ -1,30 +1,36 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Prediction.cpp * @brief Contains the implementation of the Prediction class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-06-08 + * @date 2024-02-04 **/ +#include +#include + #include #include #include #include +using namespace std; + using namespace exageostat::prediction; -using namespace exageostat::configurations; using namespace exageostat::dataunits; +using namespace exageostat::results; +using namespace exageostat::configurations; template -void Prediction::PredictMissingData(const hardware::ExaGeoStatHardware &aHardware, ExaGeoStatData &aData, - Configurations &aConfigurations, T *apMeasurementsMatrix, - const kernels::Kernel &aKernel) { +void Prediction::PredictMissingData(unique_ptr> &aData, Configurations &aConfigurations, + T *apMeasurementsMatrix, const kernels::Kernel &aKernel, + Locations *apTrainLocations, Locations *apTestLocations) { int i, j; bool can_predict = true; @@ -35,112 +41,161 @@ void Prediction::PredictMissingData(const hardware::ExaGeoStatHardware &aHard break; } } - if (!can_predict && (aConfigurations.GetIsMLOEMMOM() || aConfigurations.GetIsMSPE() || aConfigurations.GetIsFisher())) { - throw std::runtime_error( + + if (!can_predict && + (aConfigurations.GetIsMLOEMMOM() || aConfigurations.GetIsMSPE() || aConfigurations.GetIsFisher())) { + throw runtime_error( "Can't predict without an estimated theta, please either pass --etheta or run the modeling module before prediction"); } int number_of_mspe = 3; - int p = aConfigurations.GetP(); - int z_miss_number = aConfigurations.GetUnknownObservationsNb(); - int n_z_obs = aConfigurations.CalculateZObsNumber(); + int p = aKernel.GetVariablesNumber(); + int z_miss_number, n_z_obs; + T *z_actual; + if (!apTrainLocations && !apTestLocations) { + z_miss_number = aConfigurations.GetUnknownObservationsNb(); + n_z_obs = aConfigurations.CalculateZObsNumber(); + z_actual = new T[z_miss_number * p]; + } else { + z_miss_number = apTestLocations->GetSize(); + n_z_obs = apTrainLocations->GetSize(); + z_actual = nullptr; + } + aConfigurations.SetObservationNumber(n_z_obs); auto linear_algebra_solver = linearAlgebra::LinearAlgebraFactory::CreateLinearAlgebraSolver(common::EXACT_DENSE); - //FISHER Prediction Function Call - if (aConfigurations.GetIsFisher()) { - LOGGER("---- Using Prediction Function Fisher ----") - auto fisher_results = new T[num_params * num_params]; - fisher_results = linear_algebra_solver->ExaGeoStatFisherTile(aConfigurations, aData, aHardware, (T *) aConfigurations.GetEstimatedTheta().data(), aKernel); - - LOGGER("- Sd of sigma2, alpha, nu: " << sqrt(fisher_results[0]) << " " << sqrt(fisher_results[4]) << " " << sqrt(fisher_results[8])) - LOGGER("- CI for sigma2: " << aConfigurations.GetEstimatedTheta()[0] - Q_NORM * sqrt(fisher_results[0]) << " " << aConfigurations.GetEstimatedTheta()[0] + Q_NORM * sqrt(fisher_results[0])) + VERBOSE("\t- Total number of Z: " << aConfigurations.GetProblemSize()) + LOGGER("\t- Number of Z Miss: " << z_miss_number) + LOGGER("\t- Number of Z observations: " << n_z_obs) - LOGGER("- CI for alpha: " << aConfigurations.GetEstimatedTheta()[1] - Q_NORM * sqrt(fisher_results[4]) << " " << aConfigurations.GetEstimatedTheta()[1] + Q_NORM * sqrt(fisher_results[4])) - LOGGER("- CI for nu: " << aConfigurations.GetEstimatedTheta()[2] - Q_NORM * sqrt(fisher_results[8]) << " " << aConfigurations.GetEstimatedTheta()[2] + Q_NORM * sqrt(fisher_results[8])) - - LOGGER("- Fisher Matrix:") - for (i = 0; i < num_params; i ++){ - LOGGER(" ", true) - for (j = 0; j < num_params; j++){ - LOGGER_PRECISION(fisher_results[i * num_params + j] , 18) + // FISHER Prediction Function Call + if (aConfigurations.GetIsFisher()) { + LOGGER("\t---- Using Prediction Function Fisher ----") + T *fisher_results; + fisher_results = linear_algebra_solver->ExaGeoStatFisherTile(aConfigurations, aData, + (T *) aConfigurations.GetEstimatedTheta().data(), + aKernel); + vector fisher_vector; + fisher_vector.reserve(num_params * num_params); // Reserve memory in advance for efficiency + for (size_t idx = 0; idx < num_params * num_params; ++idx) { + fisher_vector.push_back(fisher_results[idx]); + } + Results::GetInstance()->SetFisherMatrix(fisher_vector); + VERBOSE("\t\t- Sd of sigma2, alpha, nu: " << sqrt(fisher_results[0]) << " " << sqrt(fisher_results[4]) << " " + << sqrt(fisher_results[8])) + VERBOSE("\t\t- CI for sigma2: " << aConfigurations.GetEstimatedTheta()[0] - Q_NORM * sqrt(fisher_results[0]) + << " " + << aConfigurations.GetEstimatedTheta()[0] + Q_NORM * sqrt(fisher_results[0])) + + VERBOSE("\t\t- CI for alpha: " << aConfigurations.GetEstimatedTheta()[1] - Q_NORM * sqrt(fisher_results[4]) + << " " + << aConfigurations.GetEstimatedTheta()[1] + Q_NORM * sqrt(fisher_results[4])) + VERBOSE("\t\t- CI for nu: " << aConfigurations.GetEstimatedTheta()[2] - Q_NORM * sqrt(fisher_results[8]) << " " + << aConfigurations.GetEstimatedTheta()[2] + Q_NORM * sqrt(fisher_results[8])) + + LOGGER("\t\t- Fisher Matrix:") + for (i = 0; i < num_params; i++) { + LOGGER("\t\t ", true) + for (j = 0; j < num_params; j++) { + LOGGER_PRECISION(fisher_results[i * num_params + j], 18) if (j != num_params - 1) { LOGGER_PRECISION(", ") } } LOGGER("") } - LOGGER("") delete[] fisher_results; } - if (z_miss_number <= 0){ + if (z_miss_number <= 0) { return; } - LOGGER("- Number of Z observations: " << aConfigurations.GetP() * n_z_obs) - results::Results::GetInstance()->SetZMiss(aConfigurations.GetP() * n_z_obs); - T *z_obs = new T[p * n_z_obs]; - T *z_miss = new T[p * z_miss_number]; - T *z_actual = new T[p * z_miss_number]; - std::vector avg_pred_value(number_of_mspe); - auto miss_locations = new Locations(z_miss_number, aData.GetLocations()->GetDimension()); - auto obs_locations = new Locations(n_z_obs, aData.GetLocations()->GetDimension()); - // We Predict date with only Exact computation. This is a pre-request. + Results::GetInstance()->SetZMiss(z_miss_number); + aConfigurations.SetUnknownObservationsNb(z_miss_number); + T *z_obs = new T[n_z_obs * p]; + T *z_miss = new T[z_miss_number]; + vector avg_pred_value(number_of_mspe); + auto miss_locations = new Locations(z_miss_number, aConfigurations.GetDimension()); + // Prediction is only supported with 2D. + auto obs_locations = new Locations(n_z_obs, aConfigurations.GetDimension()); + + // We Predict date with only Exact computation. This is a pre-request. InitializePredictionArguments(aConfigurations, aData, linear_algebra_solver, z_obs, z_actual, *miss_locations, - *obs_locations, apMeasurementsMatrix); + *obs_locations, apMeasurementsMatrix, p, apTrainLocations, apTestLocations); // MLOE MMOM Auxiliary Function Call if (aConfigurations.GetIsMLOEMMOM()) { LOGGER("---- Using Auxiliary Function MLOE MMOM ----") - linear_algebra_solver->ExaGeoStatMLETileMLOEMMOM(aConfigurations, aData, aHardware, + linear_algebra_solver->ExaGeoStatMLETileMLOEMMOM(aConfigurations, aData, (T *) aConfigurations.GetInitialTheta().data(), (T *) aConfigurations.GetEstimatedTheta().data(), *miss_locations, *obs_locations, aKernel); - LOGGER(" ---- mloe_mmom Time(main): %6.2f seconds") } // IDW Auxiliary Function Call if (aConfigurations.GetIsIDW()) { - LOGGER("---- Using Auxiliary Function IDW ----") + LOGGER("\t---- Using Auxiliary Function IDW ----") T *mspe = new T[number_of_mspe]; + + if (!z_actual) { + z_actual = new T[z_miss_number * p]; + memcpy(z_actual, apMeasurementsMatrix + n_z_obs, z_miss_number * sizeof(T)); + } + PredictionAuxiliaryFunctions::PredictIDW(z_miss, z_actual, z_obs, z_miss_number, n_z_obs, *miss_locations, *obs_locations, mspe); - LOGGER("- Average prediction Error (IDW): ", true) - for (i = 0; i < number_of_mspe; i++) { - avg_pred_value[i] += mspe[i]; - LOGGER_PRECISION(avg_pred_value[i], 9) - if (i != number_of_mspe - 1) { - LOGGER_PRECISION(", ") - } + vector idw_error; + idw_error.reserve(number_of_mspe); // Reserve memory in advance for efficiency + for (size_t idx = 0; idx < number_of_mspe; ++idx) { + idw_error.push_back(mspe[idx]); } - results::Results::GetInstance()->SetIDWError( - std::vector(avg_pred_value.data(), avg_pred_value.data() + number_of_mspe)); - LOGGER("") + + Results::GetInstance()->SetIDWError(idw_error); delete[] mspe; } // MSPE Prediction Function Call if (aConfigurations.GetIsMSPE()) { - LOGGER("---- Using MSPE ----") - T *prediction_error_mspe = linear_algebra_solver->ExaGeoStatMLEPredictTile(aData, - (T *) aConfigurations.GetEstimatedTheta().data(), - z_miss_number, n_z_obs, z_obs, - z_actual, z_miss, aHardware, - aConfigurations, *miss_locations, - *obs_locations, aKernel); + LOGGER("\t---- Using MSPE ----") + T *prediction_error_mspe; + if (aConfigurations.GetIsNonGaussian()) { + prediction_error_mspe = linear_algebra_solver->ExaGeoStatMLENonGaussianPredictTile(aData, + (T *) aConfigurations.GetEstimatedTheta().data(), + z_miss_number, n_z_obs, + z_obs, z_actual, z_miss, + aConfigurations, + *miss_locations, + *obs_locations, aKernel); + } else { + prediction_error_mspe = linear_algebra_solver->ExaGeoStatMLEPredictTile(aData, + (T *) aConfigurations.GetEstimatedTheta().data(), + z_miss_number, n_z_obs, z_obs, + z_actual, z_miss, aConfigurations, + *miss_locations, *obs_locations, + aKernel); + } for (i = 0; i < number_of_mspe; i++) { avg_pred_value[i] += prediction_error_mspe[i]; } - LOGGER("- Average prediction Error (mspe): ", true) - for (i = 0; i < number_of_mspe; i++) { - LOGGER_PRECISION(avg_pred_value[i] << "\t", 8) + vector z_miss_vector; + z_miss_vector.reserve(z_miss_number); // Reserve memory in advance for efficiency + for (size_t idx = 0; idx < z_miss_number; ++idx) { + z_miss_vector.push_back(z_miss[idx]); + } + Results::GetInstance()->SetPredictedMissedValues(z_miss_vector); + if (z_actual) { + LOGGER("\t\t- MSPE: " << avg_pred_value[0]) } - LOGGER("") delete[] prediction_error_mspe; } + + // Due to a leak in Chameleon, exactly trsm We had to free the buffer manually. + mkl_free_buffers(); + delete[] z_obs; delete[] z_miss; delete[] z_actual; @@ -149,15 +204,31 @@ void Prediction::PredictMissingData(const hardware::ExaGeoStatHardware &aHard } template -void Prediction::InitializePredictionArguments(Configurations &aConfigurations, ExaGeoStatData &aData, - std::unique_ptr> &aLinearAlgebraSolver, +void Prediction::InitializePredictionArguments(Configurations &aConfigurations, unique_ptr> &aData, + unique_ptr> &aLinearAlgebraSolver, T *apZObs, T *apZActual, Locations &aMissLocation, - Locations &aObsLocation, T *apMeasurementsMatrix) { - - int N = aConfigurations.GetProblemSize(); - T *z = new T[N]; - - aLinearAlgebraSolver->ExaGeoStatGetZObs(aConfigurations, z, N, *aData.GetDescriptorData(), apMeasurementsMatrix); - PredictionHelpers::PickRandomPoints(aConfigurations, aData, apZObs, apZActual, z, aMissLocation, aObsLocation); + Locations &aObsLocation, T *apMeasurementsMatrix, const int &aP, + Locations *apTrainLocations, Locations *apTestLocations) { + + int full_problem_size = aConfigurations.GetProblemSize() * aP; + T *z = new T[full_problem_size]; + + aLinearAlgebraSolver->ExaGeoStatGetZObs(aConfigurations, z, full_problem_size, *aData->GetDescriptorData(), + apMeasurementsMatrix, aP); + + if (!apTrainLocations && !apTestLocations) { + PredictionHelpers::PickRandomPoints(aConfigurations, aData, apZObs, apZActual, z, aMissLocation, + aObsLocation, aP); + } else { + for (int i = 0; i < apTrainLocations->GetSize(); ++i) { + aObsLocation.GetLocationX()[i] = apTrainLocations->GetLocationX()[i]; + aObsLocation.GetLocationY()[i] = apTrainLocations->GetLocationY()[i]; + } + for (int i = 0; i < apTestLocations->GetSize(); ++i) { + aMissLocation.GetLocationX()[i] = apTestLocations->GetLocationX()[i]; + aMissLocation.GetLocationY()[i] = apTestLocations->GetLocationY()[i]; + } + memcpy(apZObs, apMeasurementsMatrix, aObsLocation.GetSize() * sizeof(T)); + } delete[] z; } \ No newline at end of file diff --git a/src/prediction/PredictionAuxiliaryFunctions.cpp b/src/prediction/PredictionAuxiliaryFunctions.cpp index fb89d847..1dc84d28 100644 --- a/src/prediction/PredictionAuxiliaryFunctions.cpp +++ b/src/prediction/PredictionAuxiliaryFunctions.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file PredictionAuxiliaryFunctions.cpp * @brief Contains the implementation of the PredictionAuxiliaryFunctions class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -16,7 +16,7 @@ #include #include -#include +#include using namespace exageostat::prediction; using namespace exageostat::dataunits; @@ -57,8 +57,9 @@ void PredictionAuxiliaryFunctions::PredictIDW(T *apZMiss, T *apZActual, T *ap apMSPE[1] = error1 / (aZMissNumber / 2); apMSPE[2] = error2 / (aZMissNumber / 2); - LOGGER("- Z Actual .. Z Miss") - for (int index = 0; index < aZMissNumber; index++) - LOGGER(" (" << apZActual[index] << ", " << apZMiss[index] << ")") - LOGGER("- Prediction Error (IDW): " << apMSPE[0] << " - " << apMSPE[1] << " - " << apMSPE[2]) + VERBOSE("- Z Actual .. Z Miss") + for (int index = 0; index < aZMissNumber; index++) { + VERBOSE(" (" << apZActual[index] << ", " << apZMiss[index] << ")") + } + LOGGER("\t\t- Prediction Error (IDW): " << apMSPE[0] << " - " << apMSPE[1] << " - " << apMSPE[2]) } \ No newline at end of file diff --git a/src/prediction/PredictionHelpers.cpp b/src/prediction/PredictionHelpers.cpp index 7acf4c3c..e4d1b8e9 100644 --- a/src/prediction/PredictionHelpers.cpp +++ b/src/prediction/PredictionHelpers.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file PredictionHelpers.cpp * @brief Contains the implementation of the PredictionHelpers class. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-06-08 @@ -21,23 +21,23 @@ using namespace exageostat::configurations; using namespace exageostat::dataunits; template -void PredictionHelpers::PickRandomPoints(Configurations &aConfigurations, ExaGeoStatData &aData, T *apZObs, +void PredictionHelpers::PickRandomPoints(Configurations &aConfigurations, + std::unique_ptr> &aData, T *apZObs, T *apZActual, T *apZ, Locations &aMissLocation, - Locations &aObsLocation) { + Locations &aObsLocation, const int &aP) { int i; int j; - int N = aConfigurations.GetProblemSize(); + int full_problem_size = aConfigurations.GetProblemSize() * aP; int z_miss_number = aConfigurations.GetUnknownObservationsNb(); int z_obs_number = aConfigurations.CalculateZObsNumber(); - auto l = new Locations(N, aData.GetLocations()->GetDimension()); - - int p = aConfigurations.GetP(); bool is_shuffle = true; + int p = aP; + auto l = new Locations(aConfigurations.GetProblemSize(), aData->GetLocations()->GetDimension()); - if (aConfigurations.GetIsMLOEMMOM() && aConfigurations.GetP() == 2) { + if (aConfigurations.GetIsMLOEMMOM() && aP == 2) { p = 1; - N /= 2; + full_problem_size /= 2; is_shuffle = false; } @@ -45,30 +45,35 @@ void PredictionHelpers::PickRandomPoints(Configurations &aConfigurations, Exa T **Z_parts = new T *[p]; // Allocate memory for each row of the 2D array for (i = 0; i < p; i++) { - Z_parts[i] = new T[N / p]; + Z_parts[i] = new T[full_problem_size / p]; } if (p > 1) { // Partition Z into p parts for (i = 0; i < p; i++) { - for (j = 0; j < N; j += p) { - Z_parts[i][j] = apZ[i + j]; + int m = 0; + for (j = 0; j < full_problem_size; j += p) { + Z_parts[i][m] = apZ[i + j]; + m++; } } } - for (i = 0; i < N / p; i++) { - l->GetLocationX()[i] = aData.GetLocations()->GetLocationX()[i]; - l->GetLocationY()[i] = aData.GetLocations()->GetLocationY()[i]; + for (i = 0; i < full_problem_size / p; i++) { + l->GetLocationX()[i] = aData->GetLocations()->GetLocationX()[i]; + l->GetLocationY()[i] = aData->GetLocations()->GetLocationY()[i]; + if (aConfigurations.GetDimension() != common::Dimension2D) { + l->GetLocationZ()[i] = aData->GetLocations()->GetLocationZ()[i]; + } } if (is_shuffle) { if (p == 1) { - Shuffle(apZ, *l, N); + Shuffle(apZ, *l, full_problem_size); } else if (p == 2) { - Shuffle(Z_parts[0], Z_parts[1], *l, N); + Shuffle(Z_parts[0], Z_parts[1], *l, full_problem_size / p); } else if (p == 3) { - Shuffle(Z_parts[0], Z_parts[1], Z_parts[2], *l, N); + Shuffle(Z_parts[0], Z_parts[1], Z_parts[2], *l, full_problem_size / p); } } @@ -107,11 +112,17 @@ void PredictionHelpers::PickRandomPoints(Configurations &aConfigurations, Exa for (i = 0; i < z_miss_number; i++) { aMissLocation.GetLocationX()[i] = l->GetLocationX()[i]; aMissLocation.GetLocationY()[i] = l->GetLocationY()[i]; + if (aConfigurations.GetDimension() != common::Dimension2D) { + aMissLocation.GetLocationZ()[i] = l->GetLocationZ()[i]; + } } for (i = 0; i < z_obs_number; i++) { aObsLocation.GetLocationX()[i] = l->GetLocationX()[z_miss_number + i]; aObsLocation.GetLocationY()[i] = l->GetLocationY()[z_miss_number + i]; + if (aConfigurations.GetDimension() != common::Dimension2D) { + aObsLocation.GetLocationZ()[i] = l->GetLocationZ()[z_miss_number + i]; + } } if (p == 1) { @@ -146,6 +157,12 @@ void PredictionHelpers::Shuffle(T *apArray, Locations &aLocations, int aSi aLocations.GetLocationY()[j] = aLocations.GetLocationY()[i]; aLocations.GetLocationY()[i] = y_temp; + if (aLocations.GetDimension() != common::Dimension2D) { + T z_temp = aLocations.GetLocationZ()[j]; + aLocations.GetLocationZ()[j] = aLocations.GetLocationZ()[i]; + aLocations.GetLocationZ()[i] = z_temp; + } + } } } @@ -174,6 +191,12 @@ void PredictionHelpers::Shuffle(T *apArray1, T *apArray2, Locations &aLoca aLocations.GetLocationY()[j] = aLocations.GetLocationY()[i]; aLocations.GetLocationY()[i] = y_temp; + if (aLocations.GetDimension() != common::Dimension2D) { + T z_temp = aLocations.GetLocationZ()[j]; + aLocations.GetLocationZ()[j] = aLocations.GetLocationZ()[i]; + aLocations.GetLocationZ()[i] = z_temp; + } + } } @@ -207,6 +230,11 @@ void PredictionHelpers::Shuffle(T *apArray1, T *apArray2, T *apArray3, Locati aLocations.GetLocationY()[j] = aLocations.GetLocationY()[i]; aLocations.GetLocationY()[i] = y_temp; + if (aLocations.GetDimension() != common::Dimension2D) { + T z_temp = aLocations.GetLocationZ()[j]; + aLocations.GetLocationZ()[j] = aLocations.GetLocationZ()[i]; + aLocations.GetLocationZ()[i] = z_temp; + } } } diff --git a/src/results/CMakeLists.txt b/src/results/CMakeLists.txt index 8b7adbbc..e77a4d86 100644 --- a/src/results/CMakeLists.txt +++ b/src/results/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-09-14 diff --git a/src/results/Results.cpp b/src/results/Results.cpp index 3a919d18..3637fe66 100644 --- a/src/results/Results.cpp +++ b/src/results/Results.cpp @@ -1,21 +1,25 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file Results.cpp * @brief Defines the Results class for storing and accessing result data. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy - * @date 2023-09-14 + * @date 2024-02-04 **/ #include -#include +#include +#include using namespace exageostat::results; using namespace exageostat::common; +using namespace exageostat::configurations; + +using namespace std; Results *Results::GetInstance() { @@ -37,102 +41,84 @@ void Results::SetIsLogger(bool aIsLogger) { this->mIsLogger = aIsLogger; } -void Results::SetLoggerPath(const std::string &aLoggerPath) { +void Results::SetLoggerPath(const string &aLoggerPath) { this->mLoggerPath = aLoggerPath; } void Results::PrintEndSummary() { - Verbose temp = exageostat::configurations::Configurations::GetVerbosity(); - exageostat::configurations::Configurations::SetVerbosity(STANDARD_MODE); - LOGGER("") + Verbose temp = Configurations::GetVerbosity(); + Configurations::SetVerbosity(STANDARD_MODE); LOGGER("********************SUMMARY**********************") - auto locations_number = mGeneratedLocationsNumber; + auto locations_number = this->mGeneratedLocationsNumber; if (locations_number > 0) { - LOGGER("---- Data Generation Results ----") - if (mIsSynthetic) { - LOGGER(" #Synthetic Dataset") - } else { - LOGGER(" #Real Dataset") - } - LOGGER(" #Number of Locations: " << locations_number) - if (mIsLogger && mIsSynthetic) { + LOGGER("#Number of Locations: " << locations_number) + if (this->mIsLogger && this->mIsSynthetic) { LOGGER(" #Data is written to file (", true) - if (mLoggerPath.empty()) { - mLoggerPath = LOG_PATH; + if (this->mLoggerPath.empty()) { + this->mLoggerPath = LOG_PATH; } - LOGGER_PRECISION(mLoggerPath << ").") + LOGGER_PRECISION(this->mLoggerPath << ").") LOGGER("") } - LOGGER(" #Total Data Generation Execution Time: " << mExecutionTimeDataGeneration) - LOGGER(" #Total Data Generation Gflop/s: " << mFlopsDataGeneration) - LOGGER("") + VERBOSE("#Total Data Generation Execution Time: " << this->mExecutionTimeDataGeneration) + VERBOSE("#Total Data Generation Gflop/s: " << this->mFlopsDataGeneration) } - if (mMLEIterations > 0) { - LOGGER("---- Data Modeling Results ----") - LOGGER(" #Number of MLE Iterations till reach Maximum: " << mMLEIterations) - LOGGER(" #Found Maximum Theta at: ", true) - for (double i: mMaximumTheta) { + if (this->mMLEIterations > 0) { + LOGGER("#Number of MLE Iterations: " << this->mMLEIterations) + LOGGER("#Found Maximum Theta at: ", true) + for (double i: this->mMaximumTheta) { LOGGER_PRECISION(i << " ", 8) } LOGGER("") - LOGGER(" #Final Log Likelihood value: " << mLogLikValue) - LOGGER(" #Average Time Modeling per Iteration: " << this->GetAverageModelingExecutionTime()) - LOGGER(" #Average Flops per Iteration: " << this->GetAverageModelingFlops()) - LOGGER(" #Total MLE Execution time: " << mTotalModelingExecutionTime) - LOGGER(" #Total MLE Gflop/s: " << mTotalModelingFlops) - LOGGER("") + LOGGER("#Final Log Likelihood value: " << this->mLogLikValue) + VERBOSE("#Average Time Modeling per Iteration: " << this->GetAverageModelingExecutionTime()) + VERBOSE("#Average Flops per Iteration: " << this->GetAverageModelingFlops()) + VERBOSE("#Total MLE Execution time: " << this->mTotalModelingExecutionTime) + VERBOSE("#Total MLE GFlop/s: " << this->mTotalModelingFlops) } - if (mZMiss > 0) { - LOGGER("---- Data Prediction Results ----") - LOGGER(" #Number of Missing Observations: " << mZMiss) - if (mMSPEError > 0) { - LOGGER(" #MSPE") - LOGGER(" #MSPE Prediction Execution Time: " << mExecutionTimeMSPE) - LOGGER(" #MSPE Gflop/s: " << mFlopsMSPE) - LOGGER(" #Mean Square Error MSPE: " << mMSPEError) + if (this->mZMiss > 0) { + LOGGER("#Number of Missing Observations: " << this->mZMiss) + if (this->mMSPEError > 0) { + VERBOSE("#MSPE Prediction Execution Time: " << this->mExecutionTimeMSPE) + VERBOSE("#MSPE Gflop/s: " << this->mFlopsMSPE) + LOGGER("#Mean Square Error MSPE: " << this->mMSPEError) } - if (!mIDWError.empty()) { - LOGGER(" #IDW") - LOGGER(" #IDW Error: ( ", true) + if (!this->mIDWError.empty()) { + LOGGER("#IDW Error: ( ", true) for (int i = 0; i < 3; i++) { - LOGGER_PRECISION(mIDWError[i] << " ", 8) + LOGGER_PRECISION(this->mIDWError[i] << " ", 8) } LOGGER_PRECISION(").") LOGGER("") } - if (mMLOE > 0 || mMMOM > 0) { - LOGGER(" #MLOE MMOM") - LOGGER(" #MLOE: " << mMLOE) - LOGGER(" #MMOM: " << mMMOM) - LOGGER(" #MLOE-MMOM Execution Time: " << mExecutionTimeMLOEMMOM) - LOGGER(" #MLOE-MMOM Matrix Generation Time: " << mGenerationTimeMLOEMMOM) - LOGGER(" #MLOE-MMOM Cholesky Factorization Time: " << mFactoTimeMLOEMMOM) - LOGGER(" #MLOE-MMOM Loop Time: " << mLoopTimeMLOEMMOM) - LOGGER(" #MLOE-MMOM Number of flops: " << mFlopsMLOEMMOM) - LOGGER("") + if (this->mMLOE > 0 || this->mMMOM > 0) { + LOGGER("#MLOE: " << this->mMLOE << "\t\t#MMOM: " << this->mMMOM) + VERBOSE("#MLOE-MMOM Execution Time: " << this->mExecutionTimeMLOEMMOM) + VERBOSE("#MLOE-MMOM Matrix Generation Time: " << this->mGenerationTimeMLOEMMOM) + VERBOSE("#MLOE-MMOM Cholesky Factorization Time: " << this->mFactoTimeMLOEMMOM) + VERBOSE("#MLOE-MMOM Loop Time: " << this->mLoopTimeMLOEMMOM) + VERBOSE("#MLOE-MMOM Number of flops: " << this->mFlopsMLOEMMOM) } } - if(mFisher00 != 0){ - LOGGER(" #Fisher") - LOGGER(" #Sd For Sigma2: " << mFisher00) - LOGGER(" #Sd For Alpha: " << mFisher11) - LOGGER(" #Sd For Nu: " << mFisher22) - LOGGER(" #Fisher Execution Time: " << mTotalFisherTime) - LOGGER("") + if (!this->mFisherMatrix.empty()) { + LOGGER("#Sd For Sigma2: " << this->mFisherMatrix[0]) + LOGGER("#Sd For Alpha: " << this->mFisherMatrix[1]) + LOGGER("#Sd For Nu: " << this->mFisherMatrix[2]) + VERBOSE("#Fisher Execution Time: " << this->mTotalFisherTime) } LOGGER("*************************************************") - exageostat::configurations::Configurations::SetVerbosity(temp); + Configurations::SetVerbosity(temp); } void Results::SetMLEIterations(int aIterationsNumber) { this->mMLEIterations = aIterationsNumber; } -void Results::SetMaximumTheta(const std::vector &aMaximumTheta) { +void Results::SetMaximumTheta(const vector &aMaximumTheta) { this->mMaximumTheta = aMaximumTheta; } @@ -148,7 +134,7 @@ void Results::SetMSPEError(double aMSPEError) { this->mMSPEError = aMSPEError; } -void Results::SetIDWError(const std::vector &aIDWError) { +void Results::SetIDWError(const vector &aIDWError) { this->mIDWError = aIDWError; } @@ -180,14 +166,14 @@ double Results::GetAverageModelingExecutionTime() const { if (this->mMLEIterations) { return this->mTotalModelingExecutionTime / this->mMLEIterations; } - throw std::runtime_error("Number of MLE Iterations is not set!"); + throw runtime_error("Number of MLE Iterations is not set!"); } double Results::GetAverageModelingFlops() const { if (this->mMLEIterations) { return this->mTotalModelingFlops / this->mMLEIterations; } - throw std::runtime_error("Number of MLE Iterations is not set!"); + throw runtime_error("Number of MLE Iterations is not set!"); } void Results::SetTotalModelingFlops(double aTime) { @@ -232,14 +218,34 @@ void Results::SetTotalFisherTime(double aTime) { this->mTotalFisherTime = aTime; } -void Results::SetFisher00(double aFisher00) { - this->mFisher00 = aFisher00; +void Results::SetFisherMatrix(vector aFisherMatrix) { + this->mFisherMatrix = std::move(aFisherMatrix); +} + +void Results::SetPredictedMissedValues(vector aPredictedValues) { + this->mPredictedMissedValues = std::move(aPredictedValues); +} + +double Results::GetMLOE() const { + return this->mMLOE; +} + +double Results::GetMSPEError() const { + return this->mMSPEError; +} + +vector Results::GetIDWError() const { + return this->mIDWError; +} + +double Results::GetMMOM() const { + return this->mMMOM; } -void Results::SetFisher11(double aFisher11) { - this->mFisher11 = aFisher11; +std::vector Results::GetFisherMatrix() const { + return this->mFisherMatrix; } -void Results::SetFisher22(double aFisher22) { - this->mFisher22 = aFisher22; +std::vector Results::GetPredictedMissedValues() const { + return this->mPredictedMissedValues; } \ No newline at end of file diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt new file mode 100644 index 00000000..74d34df3 --- /dev/null +++ b/src/runtime/CMakeLists.txt @@ -0,0 +1,25 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @brief CMake build script for StarPu functions +# @author Mahmoud ElKarargy +# @date 2024-03-10 + +# Include runtime directory,based on runtime flag. +if ("${RUNTIME_TYPE}" STREQUAL "parsec") + add_subdirectory(parsec) +else () + #by default use StarPu runtime. + add_subdirectory(starpu) +endif () + +# Define the sources for the library +set(SOURCES + ${SOURCES} + PARENT_SCOPE + ) + diff --git a/src/runtime/parsec/CMakeLists.txt b/src/runtime/parsec/CMakeLists.txt new file mode 100644 index 00000000..f1b427db --- /dev/null +++ b/src/runtime/parsec/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @brief CMake build script for Parsec runtime +# @author Mahmoud ElKarargy +# @date 2024-03-10 + +# Define the sources for the library +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/ParsecFunctions.cpp + ${SOURCES} + PARENT_SCOPE + ) \ No newline at end of file diff --git a/src/runtime/parsec/ParsecFunctions.cpp b/src/runtime/parsec/ParsecFunctions.cpp new file mode 100644 index 00000000..65b0073d --- /dev/null +++ b/src/runtime/parsec/ParsecFunctions.cpp @@ -0,0 +1,87 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ParsecFunctions.cpp + * @brief A class for static functions used in Parsec runtime + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-03-10 +**/ + +#include + +using namespace std; +using namespace exageostat::common; +using namespace exageostat::runtime; +using namespace exageostat::dataunits; + +//TODO: implement parsec functions +template +void RuntimeFunctions::CovarianceMatrix(DescriptorData &aDescriptorData, void *apDescriptor, + const int &aTriangularPart, Locations *apLocation1, + Locations *apLocation2, Locations *apLocation3, + T *apLocalTheta, const int &aDistanceMetric, + const kernels::Kernel *apKernel, void *apContext) {} + +template +void RuntimeFunctions::ExaGeoStatMLETileAsyncMLOEMMOM(void *apDescExpr1, void *apDescExpr2, void *apDescExpr3, + void *apDescMLOE, void *apDescMMOM, void *apSequence, + void *apRequest, void *apContext) {} + +template +void RuntimeFunctions::ExaGeoStatMLEMSPETileAsync(void *apDescZPredict, void *apDescZMiss, void *apDescError, + void *apSequence, void *apRequest, void *apContext) {} + +template +void RuntimeFunctions::CopyDescriptorZ(DescriptorData &aDescriptorData, void *apDescriptor, T *apDoubleVector, + void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatGaussianToNonTileAsync(DescriptorData &aDescriptorData, void *apDesc, T *apTheta, + void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatMeasureDetTileAsync(const Computation &aComputation, void *apDescA, void *apSequence, + void *apRequest, void *apDescDet, void *apContext) {} + +template +void RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, + void *apDescC, void *apSequence, void *apRequest, + void *apContext) {} + +template +void RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apDescD, + void *apSequence, void *apRequest, void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatMLETraceTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescNum, + void *apDescTrace, void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatDoubleDotProduct(void *apDescA, void *apDescProduct, void *apSequence, + void *apRequest, + void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatMLEMSPEBivariateTileAsync(void *apDescZPre, void *apDescZMiss, void *apDescsError1, + void *apDescsError2, void *apDescsError, void *apSequence, + void *apRequest, void *apContext) {} + +template +void RuntimeFunctions::ExaGeoStatNonGaussianLogLikeTileAsync(const Computation &aComputation, void *apDescZ, + void *apDescSum, const T *apTheta, void *apSequence, + void *apRequest, void *apContext) {} + +template +void +RuntimeFunctions::ExaGeoStatNonGaussianTransformTileAsync(const Computation &aComputation, void *apDescZ, + const T *apTheta, + void *apSequence, void *apRequest, void *apContext) {} diff --git a/src/runtime/starpu/CMakeLists.txt b/src/runtime/starpu/CMakeLists.txt new file mode 100644 index 00000000..1fce6410 --- /dev/null +++ b/src/runtime/starpu/CMakeLists.txt @@ -0,0 +1,55 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @brief CMake build script for StarPu runtime +# @author Mahmoud ElKarargy +# @date 2024-02-19 + +# Include the concrete implementations of the StarPu codelets classes +file(GLOB ALL_CODELETS ${CMAKE_CURRENT_SOURCE_DIR}/concrete/*.cpp) + +# Include StarPu helpers. +add_subdirectory(helpers) + +# Define the sources for the library +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/StarPuFunctions.cpp + ${ALL_CODELETS} + ${SOURCES} + PARENT_SCOPE + ) + +# Automatically add new codelets header files to StarPuCodeletsHeaders.hpp + +# File documentation +set(DOCUMENTATION_STRING " +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuCodelets.hpp + * @brief Header file to include all codelet classes. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +") + +set(PATH_TO_CODELETS_HEADERS "${PROJECT_SOURCE_DIR}/inst/include/runtime/starpu") +set(GENERATED_INCLUDES "${PATH_TO_CODELETS_HEADERS}/StarPuCodeletsHeaders.hpp") + +file(GLOB_RECURSE HEADER_FILES "${PATH_TO_CODELETS_HEADERS}/concrete/*.hpp") +file(WRITE ${GENERATED_INCLUDES} ${DOCUMENTATION_STRING}) + +foreach (HEADER_FILE ${HEADER_FILES}) + # Construct the include directive by stripping the known base directory part from the full path + string(REPLACE "${PATH_TO_CODELETS_HEADERS}" "" HEADER_RELATIVE_PATH ${HEADER_FILE}) + # Use angle brackets and the desired base path for the include directive + file(APPEND ${GENERATED_INCLUDES} "#include \n") +endforeach () diff --git a/src/runtime/starpu/StarPuFunctions.cpp b/src/runtime/starpu/StarPuFunctions.cpp new file mode 100644 index 00000000..315c1df6 --- /dev/null +++ b/src/runtime/starpu/StarPuFunctions.cpp @@ -0,0 +1,258 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuFunctions.cpp + * @brief A class for static functions that make use of starpu_codelets. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-28 +**/ + +#include +#include +#include +#include + +using namespace exageostat::common; +using namespace exageostat::runtime; +using namespace exageostat::dataunits; + +template +void RuntimeFunctions::CovarianceMatrix(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, + const int &aTriangularPart, + dataunits::Locations *apLocation1, dataunits::Locations *apLocation2, + dataunits::Locations *apLocation3, T *apLocalTheta, + const int &aDistanceMetric, + const kernels::Kernel *apKernel) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, aDescriptorData.GetSequence(), + aDescriptorData.GetRequest()); + + DCMGCodelet cl; + cl.InsertTask(apDescriptor, aTriangularPart, apLocation1, apLocation2, apLocation3, apLocalTheta, aDistanceMetric, + apKernel); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatMLETileAsyncMLOEMMOM(void *apDescExpr1, void *apDescExpr2, void *apDescExpr3, + void *apDescMLOE, + void *apDescMMOM, void *apSequence, void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DmloeMmomCodelet cl; + cl.InsertTask(apDescExpr1, apDescExpr2, apDescExpr3, apDescMLOE, apDescMMOM); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatMLEMSPETileAsync(void *apDescZPredict, void *apDescZMiss, void *apDescError, + void *apSequence, + void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DMSECodelet cl; + cl.InsertTask(apDescError, apDescZPredict, apDescZMiss); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::CopyDescriptorZ(dataunits::DescriptorData &aDescriptorData, void *apDescriptor, + T *apDoubleVector) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, aDescriptorData.GetSequence(), + aDescriptorData.GetRequest()); + + DZCPYCodelet cl; + cl.InsertTask(apDescriptor, apDoubleVector); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatGaussianToNonTileAsync(dataunits::DescriptorData &aDescriptorData, void *apDesc, + T *apTheta) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, aDescriptorData.GetSequence(), + aDescriptorData.GetRequest()); + + GaussianCodelet cl; + cl.InsertTask(apDesc, apTheta); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void +RuntimeFunctions::ExaGeoStatMeasureDetTileAsync(const common::Computation &aComputation, void *apDescA, + void *apSequence, void *apRequest, + void *apDescDet) { + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(aComputation); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DMDETCodelet cl; + cl.InsertTask(aComputation, apDescA, apDescDet, starpu_helper); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apSequence, + void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + STRIDEVECCodelet cl; + cl.InsertTask(apDescA, apDescB, apDescC); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStaStrideVectorTileAsync(void *apDescA, void *apDescB, void *apDescC, void *apDescD, + void *apSequence, + void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + TriStrideVecCodelet cl; + cl.InsertTask(apDescA, apDescB, apDescC, apDescD); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatMLETraceTileAsync(void *apDescA, void *apSequence, void *apRequest, void *apDescNum, + void *apDescTrace) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DTRACECodelet cl; + cl.InsertTask(apDescA, apDescNum, apDescTrace); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void +RuntimeFunctions::ExaGeoStatDoubleDotProduct(void *apDescA, void *apDescProduct, void *apSequence, void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DDOTPCodelet cl; + cl.InsertTask(apDescA, apDescProduct); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatMLEMSPEBivariateTileAsync(void *apDescZPre, void *apDescZMiss, void *apDescError1, + void *apDescError2, + void *apDescError, void *apSequence, void *apRequest) { + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(EXACT_DENSE); + auto *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + DMSEBivariateCodelet cl; + cl.InsertTask(apDescZPre, apDescError, apDescError1, apDescError2, apDescZMiss); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void RuntimeFunctions::ExaGeoStatNonGaussianLogLikeTileAsync(const common::Computation &aComputation, void *apDescZ, + void *apDescSum, + const T *apTheta, void *apSequence, void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(aComputation); + void *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + NonGaussianLoglike cl; + cl.InsertTask(apDescZ, apDescSum, apTheta, starpu_helper); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} + +template +void +RuntimeFunctions::ExaGeoStatNonGaussianTransformTileAsync(const common::Computation &aComputation, void *apDescZ, + const T *apTheta, + void *apSequence, void *apRequest) { + + auto starpu_helper = StarPuHelpersFactory::CreateStarPuHelper(aComputation); + void *pOptions = starpu_helper->GetOptions(); + starpu_helper->ExaGeoStatOptionsInit(pOptions, apSequence, apRequest); + + NonGaussianTransform cl; + cl.InsertTask(apDescZ, apTheta, starpu_helper); + + starpu_helper->ExaGeoStatOptionsFree(pOptions); + starpu_helper->ExaGeoStatOptionsFinalize(pOptions); + starpu_helper->DeleteOptions(pOptions); + +} diff --git a/src/runtime/starpu/concrete/dcmg-codelet.cpp b/src/runtime/starpu/concrete/dcmg-codelet.cpp new file mode 100644 index 00000000..71827f84 --- /dev/null +++ b/src/runtime/starpu/concrete/dcmg-codelet.cpp @@ -0,0 +1,90 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dcmg-codelet.cpp + * @brief A class for starpu codelet dcmg. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-19 +**/ + +#include +#include + +using namespace exageostat::runtime; +using namespace exageostat::dataunits; +using namespace exageostat::kernels; + +template +struct starpu_codelet DCMGCodelet::cl_dcmg = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dcmg_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dcmg_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 1, + .modes = {STARPU_W}, + .name = "dcmg" +}; + +template +void DCMGCodelet::InsertTask(void *apDescriptor, const int &aTriangularPart, Locations *apLocation1, + Locations *apLocation2, Locations *apLocation3, T *apLocalTheta, + const int &aDistanceMetric, const Kernel *apKernel) { + int rows_num, cols_num, row, col, tile_row = 0, tile_col = 0; + auto *CHAM_apDescriptor = (CHAM_desc_t *) apDescriptor; + + for (col = 0; col < CHAM_apDescriptor->nt; col++) { + cols_num = col == CHAM_apDescriptor->nt - 1 ? CHAM_apDescriptor->n - col * CHAM_apDescriptor->nb + : CHAM_apDescriptor->nb; + if (aTriangularPart == ChamUpperLower) { + row = 0; + } else { + row = CHAM_apDescriptor->m == CHAM_apDescriptor->n ? col : 0; + } + for (; row < CHAM_apDescriptor->mt; row++) { + rows_num = row == CHAM_apDescriptor->mt - 1 ? CHAM_apDescriptor->m - row * CHAM_apDescriptor->mb + : CHAM_apDescriptor->mb; + tile_row = row * CHAM_apDescriptor->mb; + tile_col = col * CHAM_apDescriptor->nb; + starpu_insert_task(&this->cl_dcmg, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_VALUE, &cols_num, sizeof(int), + STARPU_VALUE, &tile_row, sizeof(int), + STARPU_VALUE, &tile_col, sizeof(int), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(CHAM_apDescriptor, row, col), + STARPU_VALUE, &apLocation1, sizeof(Locations *), + STARPU_VALUE, &apLocation2, sizeof(Locations *), + STARPU_VALUE, &apLocation3, sizeof(Locations *), + STARPU_VALUE, &apLocalTheta, sizeof(double *), + STARPU_VALUE, &aDistanceMetric, sizeof(int), + STARPU_VALUE, &apKernel, sizeof(kernels::Kernel *), + 0); + } + } +} + +template +void DCMGCodelet::cl_dcmg_function(void *apBuffers[], void *apCodeletArguments) { + int rows_num, cols_num, tile_row, tile_col, distance_metric; + Locations *pLocation1, *pLocation2, *pLocation3; + T *pLocal_theta, *pDescriptor_A; + Kernel *pKernel; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &cols_num, &tile_row, &tile_col, &pLocation1, &pLocation2, + &pLocation3, &pLocal_theta, + &distance_metric, &pKernel); + pKernel->GenerateCovarianceMatrix(pDescriptor_A, rows_num, cols_num, tile_row, tile_col, *pLocation1, *pLocation2, + *pLocation3, pLocal_theta, distance_metric); +} diff --git a/src/runtime/starpu/concrete/ddotp-codelet.cpp b/src/runtime/starpu/concrete/ddotp-codelet.cpp new file mode 100644 index 00000000..1057e8a3 --- /dev/null +++ b/src/runtime/starpu/concrete/ddotp-codelet.cpp @@ -0,0 +1,72 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ddotp-codelet.cpp + * @brief A class for starpu codelet ddotp. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DDOTPCodelet::cl_ddotp = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_ddotp_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_ddotp_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 2, + .modes = {STARPU_W, STARPU_W}, + .name = "ddotp" +}; + +template +void DDOTPCodelet::InsertTask(void *apDescA, void *apDescProduct) { + + int row, rows_num; + auto pDesc_A = (CHAM_desc_t *) apDescA; + auto pDesc_product = (CHAM_desc_t *) apDescProduct; + + auto desc_mt = pDesc_A->mt; + auto desc_m = pDesc_A->m; + auto desc_mb = pDesc_A->mb; + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + + starpu_insert_task(&this->cl_ddotp, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(pDesc_product, 0, 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(pDesc_A, row, 0), + 0); + } +} + +template +void DDOTPCodelet::cl_ddotp_function(void *apBuffers[], void *apCodeletArguments) { + int rows_num; + T *pDescriptor_A, *pDot_product; + + pDot_product = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + T local_dot = cblas_ddot(rows_num, (double *) pDescriptor_A, 1, (double *) pDescriptor_A, 1); + *pDot_product += local_dot; +} diff --git a/src/runtime/starpu/concrete/dmdet-codelet.cpp b/src/runtime/starpu/concrete/dmdet-codelet.cpp new file mode 100644 index 00000000..b89fc204 --- /dev/null +++ b/src/runtime/starpu/concrete/dmdet-codelet.cpp @@ -0,0 +1,80 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmdet-codelet.cpp + * @brief A class for starpu codelet dmdet. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-21 +**/ + +#include + +#include + +using namespace exageostat::runtime; +using namespace exageostat::common; + +template +struct starpu_codelet DMDETCodelet::cl_dmdet{ +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dmdet_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dmdet_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 2, + .modes = {STARPU_W, STARPU_W}, + .name = "dmdet" +}; + +template +void DMDETCodelet::InsertTask(const Computation &aComputation, void *apDescA, void *apDescDet, + std::unique_ptr &aStarPuHelpers) { + int row, rows_num; + auto desc_mt = aStarPuHelpers->GetMT(apDescA); + auto desc_m = aStarPuHelpers->GetM(apDescA); + auto desc_mb = aStarPuHelpers->GetMB(apDescA); + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_dmdet, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_W, + aStarPuHelpers->ExaGeoStatDataGetAddr(apDescA, row, aComputation != TILE_LOW_RANK ? row : 0), + STARPU_W, aStarPuHelpers->ExaGeoStatDataGetAddr(apDescDet, 0, 0), + 0); + } +} + +template +void DMDETCodelet::cl_dmdet_function(void *apBuffers[], void *apCodeletArguments) { + int rows_num; + T *pDescriptor_A, *pDeterminant; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pDeterminant = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + T local_det = core_dmdet(pDescriptor_A, rows_num); + *pDeterminant += local_det; +} + +template +T DMDETCodelet::core_dmdet(const T *apDescriptor, const int &aSize) { + T result = 0.0; + for (int i = 0; i < aSize; i++) { + if (apDescriptor[i + i * aSize] > 0) + result += log(apDescriptor[i + i * aSize]); + } + return result; +} diff --git a/src/runtime/starpu/concrete/dmloe-mmom-codelet.cpp b/src/runtime/starpu/concrete/dmloe-mmom-codelet.cpp new file mode 100644 index 00000000..e7986d6c --- /dev/null +++ b/src/runtime/starpu/concrete/dmloe-mmom-codelet.cpp @@ -0,0 +1,103 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmloe-mmom-codelet.cpp + * @brief A class for starpu codelet dmloe-mmom. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DmloeMmomCodelet::cl_dmloe_mmom = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dmloe_mmom_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dmloe_mmom_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 5, + .modes = {STARPU_W, STARPU_W, STARPU_W, STARPU_W, STARPU_W}, + .name = "dmloe_mmom" +}; + +template +void DmloeMmomCodelet::InsertTask(void *apDescExpr1, void *apDescExpr2, void *apDescExpr3, void *apDescMLOE, + void *apDescMMOM) { + int row, col, rows_num, cols_num; + + for (col = 0; col < ((CHAM_desc_t *) apDescExpr1)->nt; col++) { + cols_num = col == ((CHAM_desc_t *) apDescExpr1)->nt - 1 ? ((CHAM_desc_t *) apDescExpr1)->n - + col * ((CHAM_desc_t *) apDescExpr1)->nb + : ((CHAM_desc_t *) apDescExpr1)->nb; + for (row = 0; row < ((CHAM_desc_t *) apDescExpr1)->mt; row++) { + + rows_num = row == ((CHAM_desc_t *) apDescExpr1)->mt - 1 ? ((CHAM_desc_t *) apDescExpr1)->m - + row * ((CHAM_desc_t *) apDescExpr1)->mb + : ((CHAM_desc_t *) apDescExpr1)->mb; + starpu_insert_task(&this->cl_dmloe_mmom, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_VALUE, &cols_num, sizeof(int), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr1, row, col), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr2, row, col), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescExpr3, row, col), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescMLOE, row, col), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescMMOM, row, col), + 0); + } + } +} + +template +void DmloeMmomCodelet::cl_dmloe_mmom_function(void **apBuffers, void *apCodeletArguments) { + int rows_num, cols_num; + T *pExpr1, *pExpr2, *pExpr3, *pMloe, *pMmom; + + pExpr1 = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pExpr2 = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pExpr3 = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + pMloe = (T *) STARPU_MATRIX_GET_PTR(apBuffers[3]); + pMmom = (T *) STARPU_MATRIX_GET_PTR(apBuffers[4]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &cols_num); + T expr1_ = 0, expr2_ = 0, expr3_ = 0; + + for (int i = 0; i < rows_num * cols_num; i += 2) { + expr1_ += pExpr1[i]; + expr2_ += pExpr2[i]; + expr3_ += pExpr3[i]; + } + + if (expr2_ == 0.0) { + *pMloe -= 1.0; + } else { + *pMloe += (expr1_ / expr2_) - 1.0; + } + + if (expr2_ == 0.0) { + *pMmom -= 1.0; + } else { + *pMmom += (expr3_ / expr1_) - 1.0; + } +} diff --git a/src/runtime/starpu/concrete/dmse-bivariate-codelet.cpp b/src/runtime/starpu/concrete/dmse-bivariate-codelet.cpp new file mode 100644 index 00000000..badbfa71 --- /dev/null +++ b/src/runtime/starpu/concrete/dmse-bivariate-codelet.cpp @@ -0,0 +1,87 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmse-bivariate-codelet.cpp + * @brief A class for starpu codelet dmse-bivariate. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DMSEBivariateCodelet::cl_dmse_bivariate = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dmse_bivariate_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dmse_bivariate_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 5, + .modes = {STARPU_RW, STARPU_RW, STARPU_RW, STARPU_R, STARPU_R}, + .name = "dmse-bivariate" +}; + +template +void DMSEBivariateCodelet::InsertTask(void *apDescZMiss, void *apDescZPre, void *apDescsError, void *apDescsError1, + void *apDescsError2) { + int row, rows_num; + + auto pDesc_ZPre = (CHAM_desc_t *) apDescZPre; + auto desc_mt = pDesc_ZPre->mt; + auto desc_m = pDesc_ZPre->m; + auto desc_mb = pDesc_ZPre->mb; + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_dmse_bivariate, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescsError1, 0, 0), + STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescsError2, 0, 0), + STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescsError, 0, 0), + STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZPre, row, 0), + STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZMiss, row, 0), + 0); + } +} + +template +void DMSEBivariateCodelet::cl_dmse_bivariate_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pZpre, *pZmiss, *pSerror1, *pSerror2, *pSerror; + T local_serror1 = 0.0, local_serror2 = 0.0, local_serror = 0.0; + + pSerror1 = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pSerror2 = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pSerror = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + pZpre = (T *) STARPU_MATRIX_GET_PTR(apBuffers[3]); + pZmiss = (T *) STARPU_MATRIX_GET_PTR(apBuffers[4]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + + for (int i = 0; i < rows_num; i++) { + if (i % 2 == 0) { + local_serror1 += pow((pZpre[i] - pZmiss[i]), 2); + } else + local_serror2 += pow((pZpre[i] - pZmiss[i]), 2); + local_serror += pow((pZpre[i] - pZmiss[i]), 2); + } + *pSerror1 += local_serror1; + *pSerror2 += local_serror2; + *pSerror += local_serror; +} diff --git a/src/runtime/starpu/concrete/dmse-codelet.cpp b/src/runtime/starpu/concrete/dmse-codelet.cpp new file mode 100644 index 00000000..79941c50 --- /dev/null +++ b/src/runtime/starpu/concrete/dmse-codelet.cpp @@ -0,0 +1,73 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dmse-codelet.cpp + * @brief A class for starpu codelet dmse. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-21 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DMSECodelet::cl_dmse = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dmse_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dmse_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 3, + .modes = {STARPU_W, STARPU_W, STARPU_W}, + .name = "dmse" +}; + +template +void DMSECodelet::InsertTask(void *apDescError, void *apDescZPredict, void *apDescZMiss) { + int row, rows_num; + auto pDesc_Z_predict = (CHAM_desc_t *) apDescZPredict; + + for (row = 0; row < pDesc_Z_predict->mt; row++) { + rows_num = + row == pDesc_Z_predict->mt - 1 ? pDesc_Z_predict->m - row * pDesc_Z_predict->mb : pDesc_Z_predict->mb; + starpu_insert_task(&this->cl_dmse, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescError, 0, 0), + STARPU_W, + (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZPredict, row, 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescZMiss, row, 0), + 0); + } +} + +template +void DMSECodelet::cl_dmse_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pZPredict, *pZMiss, *pError; + T local_error = 0.0; + + pError = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pZPredict = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pZMiss = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + for (int i = 0; i < rows_num; i++) { + local_error += pow((pZPredict[i] - pZMiss[i]), 2); + } + *pError += local_error; +} diff --git a/src/runtime/starpu/concrete/dtrace-codelet.cpp b/src/runtime/starpu/concrete/dtrace-codelet.cpp new file mode 100644 index 00000000..0d840302 --- /dev/null +++ b/src/runtime/starpu/concrete/dtrace-codelet.cpp @@ -0,0 +1,78 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dtrace-codelet.cpp + * @brief A class for starpu codelet dtrace. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DTRACECodelet::cl_dtrace = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dtrace_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dtrace_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 3, + .modes = {STARPU_W, STARPU_W, STARPU_W}, + .name = "dtrace" +}; + +template +void DTRACECodelet::InsertTask(void *apDescA, void *apDescNum, void *apDescTrace) { + int row, rows_num; + auto pDescriptor_A = (CHAM_desc_t *) apDescA; + + for (row = 0; row < pDescriptor_A->mt; row++) { + rows_num = row == pDescriptor_A->mt - 1 ? pDescriptor_A->m - row * pDescriptor_A->mb : pDescriptor_A->mb; + starpu_insert_task(&this->cl_dtrace, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescA, row, row), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescNum, 0, 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr((CHAM_desc_t *) apDescTrace, row, 0), + 0); + } +} + +template +void DTRACECodelet::cl_dtrace_function(void *apBuffers[], void *apCodeletArguments) { + int rows_num; + T *pDescriptor_A, *pSum, *pTrace; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pSum = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pTrace = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + T local_sum = core_dtrace(pDescriptor_A, rows_num, pTrace); + *pSum += local_sum; +} + +template +double DTRACECodelet::core_dtrace(const T *pDescriptor, const int &aSize, T *pTrace) { + T result = 0.0; + for (int i = 0; i < aSize; i++) { + result += pDescriptor[i + i * aSize]; + pTrace[i] = pDescriptor[i + i * aSize]; + } + return result; +} diff --git a/src/runtime/starpu/concrete/dzcpy-codelet.cpp b/src/runtime/starpu/concrete/dzcpy-codelet.cpp new file mode 100644 index 00000000..6c213f2e --- /dev/null +++ b/src/runtime/starpu/concrete/dzcpy-codelet.cpp @@ -0,0 +1,65 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file dzcpy-codelet.cpp + * @brief A class for starpu codelet dzcpy. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet DZCPYCodelet::cl_dzcpy = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_dzcpy_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_dzcpy_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 1, + .modes = {STARPU_W}, + .name = "dzcpy" +}; + +template +void DZCPYCodelet::InsertTask(void *apDescriptor, void *apDoubleVector) { + int row, tile_row, rows_num; + auto pDescriptor_A = (CHAM_desc_t *) apDescriptor; + + for (row = 0; row < pDescriptor_A->mt; row++) { + rows_num = row == pDescriptor_A->mt - 1 ? pDescriptor_A->m - row * pDescriptor_A->mb : pDescriptor_A->mb; + tile_row = row * pDescriptor_A->mb; + starpu_insert_task(&this->cl_dzcpy, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_VALUE, &tile_row, sizeof(int), + STARPU_VALUE, &apDoubleVector, sizeof(double), + STARPU_W, RUNTIME_data_getaddr(pDescriptor_A, row, 0), + 0); + } +} + +template +void DZCPYCodelet::cl_dzcpy_function(void **apBuffers, void *apCodeletArguments) { + int rows_num, tile_row; + T *pDescriptor_A, *pR; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &tile_row, &pR); + memcpy(pDescriptor_A, &pR[tile_row], rows_num * sizeof(T)); +} diff --git a/src/runtime/starpu/concrete/gaussian-to-non-codelet.cpp b/src/runtime/starpu/concrete/gaussian-to-non-codelet.cpp new file mode 100644 index 00000000..81db6fd3 --- /dev/null +++ b/src/runtime/starpu/concrete/gaussian-to-non-codelet.cpp @@ -0,0 +1,98 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file gaussian-to-non-codelet.cpp + * @brief A class for starpu codelet gaussian-to-non. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet GaussianCodelet::cl_gaussian_to_non = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_gaussian_to_non_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where = STARPU_CPU, + .cpu_funcs = {cl_gaussian_to_non_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#endif + .nbuffers = 1, + .modes = {STARPU_RW}, + .name = "gaussian_to_non" +}; + +template +void GaussianCodelet::InsertTask(void *apDesc, T *apTheta) { + int row, rows_num; + auto pDescriptor_Z = (CHAM_desc_t *) apDesc; + + for (row = 0; row < pDescriptor_Z->mt; row++) { + rows_num = row == pDescriptor_Z->mt - 1 ? pDescriptor_Z->m - row * pDescriptor_Z->mb : pDescriptor_Z->mb; + starpu_insert_task(&this->cl_gaussian_to_non, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_RW, (starpu_data_handle_t) RUNTIME_data_getaddr(pDescriptor_Z, row, 0), + STARPU_VALUE, &apTheta[0], sizeof(T), + STARPU_VALUE, &apTheta[1], sizeof(T), + STARPU_VALUE, &apTheta[2], sizeof(T), + STARPU_VALUE, &apTheta[3], sizeof(T), + STARPU_VALUE, &apTheta[4], sizeof(T), + STARPU_VALUE, &apTheta[5], sizeof(T), + 0); + } +} + +template +void GaussianCodelet::cl_gaussian_to_non_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pDescriptorZ, *pTheta; + + pTheta = new T[6]; + pDescriptorZ = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &pTheta[0], &pTheta[1], &pTheta[2], &pTheta[3], + &pTheta[4], + &pTheta[5]); + //core function to convert Z tile from Gaussian to non-Gaussian. + core_gaussian_to_non(pDescriptorZ, pTheta, rows_num); + delete[] pTheta; +} + +template +void GaussianCodelet::core_gaussian_to_non(T *apDescriptorZ, const T *apLocalTheta, const int &aSize) { + + T xi = apLocalTheta[2]; + T omega = apLocalTheta[3]; + T g = apLocalTheta[4]; + T h = apLocalTheta[5]; + + int i; + if (h < 0) { + throw std::runtime_error("The kurtosis parameter cannot be negative"); + } + if (g == 0) { + for (i = 0; i < aSize; i++) + apDescriptorZ[i] = xi + omega * apDescriptorZ[i] * (exp(0.5 * h * pow(apDescriptorZ[i], 2))); + } else { + for (i = 0; i < aSize; i++) + apDescriptorZ[i] = + xi + omega * (exp(g * apDescriptorZ[i]) - 1) * (exp(0.5 * h * pow(apDescriptorZ[i], 2))) / g; + } +} + + diff --git a/src/runtime/starpu/concrete/non-gaussian-loglike-codelet.cpp b/src/runtime/starpu/concrete/non-gaussian-loglike-codelet.cpp new file mode 100644 index 00000000..d425ca7e --- /dev/null +++ b/src/runtime/starpu/concrete/non-gaussian-loglike-codelet.cpp @@ -0,0 +1,101 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file non-gaussian-codelet-loglike-codelet.cpp + * @brief A class for starpu codelet non-gaussian-loglike. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-26 +**/ + +#include + +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet NonGaussianLoglike::cl_non_gaussian_loglike = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_non_gaussian_loglike_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_non_gaussian_loglike_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 2, + .modes = {STARPU_R, STARPU_RW}, + .name = "non_gaussian_loglike" +}; + +template +void NonGaussianLoglike::InsertTask(void *apDescZ, void *apDescSum, const T *apTheta, + std::unique_ptr &aStarPuHelpers) { + auto desc_mt = aStarPuHelpers->GetMT(apDescZ); + auto desc_m = aStarPuHelpers->GetM(apDescZ); + auto desc_mb = aStarPuHelpers->GetMB(apDescZ); + + int row, rows_num; + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_non_gaussian_loglike, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_R, aStarPuHelpers->ExaGeoStatDataGetAddr(apDescZ, row, 0), + STARPU_RW, aStarPuHelpers->ExaGeoStatDataGetAddr(apDescSum, 0, 0), + STARPU_VALUE, &apTheta[0], sizeof(double), + STARPU_VALUE, &apTheta[1], sizeof(double), + STARPU_VALUE, &apTheta[2], sizeof(double), + STARPU_VALUE, &apTheta[3], sizeof(double), + STARPU_VALUE, &apTheta[4], sizeof(double), + STARPU_VALUE, &apTheta[5], sizeof(double), + 0); + } +} + +template +void NonGaussianLoglike::cl_non_gaussian_loglike_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pDescriptor_Z, *pDescriptor_sum; + + auto *pTheta = new T[6]; + pDescriptor_Z = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pDescriptor_sum = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &pTheta[0], &pTheta[1], &pTheta[2], &pTheta[3], + &pTheta[4], + &pTheta[5]); + T local_sum = core_non_gaussian_loglike_helper(pDescriptor_Z, pTheta, rows_num); + *pDescriptor_sum += local_sum; + delete[] pTheta; +} + +template +double NonGaussianLoglike::core_non_gaussian_loglike_helper(const T *apDescriptorZ, const T *apLocalTheta, + const int &aSize) { + T g = apLocalTheta[4]; + T h = apLocalTheta[5]; + + int i; + T sum = 0.0; + if (h < 0) { + throw std::runtime_error("The kurtosis parameter cannot be negative"); + + } + for (i = 0; i < aSize; i++) { + if (g == 0) + sum += log(1 + h * pow(apDescriptorZ[i], 2)) + 0.5 * h * pow(apDescriptorZ[i], 2); + else { + sum += log(exp(g * apDescriptorZ[i]) + (exp(g * apDescriptorZ[i]) - 1) * h * apDescriptorZ[i] / g) + + 0.5 * h * pow(apDescriptorZ[i], 2); + } + } + return sum; +} diff --git a/src/runtime/starpu/concrete/non-gaussian-transform-codelet.cpp b/src/runtime/starpu/concrete/non-gaussian-transform-codelet.cpp new file mode 100644 index 00000000..0cce4daf --- /dev/null +++ b/src/runtime/starpu/concrete/non-gaussian-transform-codelet.cpp @@ -0,0 +1,136 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file non-gaussian-codelet-transform-codelet.cpp + * @brief A class for starpu codelet non-gaussian-transform. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-26 +**/ + +#include +#include + +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet NonGaussianTransform::cl_non_gaussian_transform = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_non_gaussian_transform_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_non_gaussian_transform_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 1, + .modes = {STARPU_RW}, + .name = "non_gaussian_transform" +}; + +template +void +NonGaussianTransform::InsertTask(void *apDescZ, const T *apTheta, std::unique_ptr &apStarPuHelpers) { + int row, rows_num; + + auto desc_mt = apStarPuHelpers->GetMT(apDescZ); + auto desc_m = apStarPuHelpers->GetM(apDescZ); + auto desc_mb = apStarPuHelpers->GetMB(apDescZ); + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_non_gaussian_transform, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_RW, apStarPuHelpers->ExaGeoStatDataGetAddr(apDescZ, row, 0), + STARPU_VALUE, &apTheta[0], sizeof(double), + STARPU_VALUE, &apTheta[1], sizeof(double), + STARPU_VALUE, &apTheta[2], sizeof(double), + STARPU_VALUE, &apTheta[3], sizeof(double), + STARPU_VALUE, &apTheta[4], sizeof(double), + STARPU_VALUE, &apTheta[5], sizeof(double), + 0); + } +} + +template +void NonGaussianTransform::cl_non_gaussian_transform_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pDescriptorZ, *pTheta; + + pTheta = new T[6]; + pDescriptorZ = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num, &pTheta[0], &pTheta[1], &pTheta[2], &pTheta[3], + &pTheta[4], + &pTheta[5]); + core_non_gaussian_transform_helper(pDescriptorZ, pTheta, rows_num); + delete[] pTheta; +} + +template +void +NonGaussianTransform::core_non_gaussian_transform_helper(T *apDescripZ, const T *apLocalTheta, const int &aSize) { + + T xi = apLocalTheta[2]; + T omega = apLocalTheta[3]; + T g = apLocalTheta[4]; + T h = apLocalTheta[5]; + T eps = 1.0e-5; + + for (int i = 0; i < aSize; i++) + apDescripZ[i] = newton_raphson(apDescripZ[i], xi, omega, g, h, eps); +} + +template +double +NonGaussianTransform::newton_raphson(const T apDescriptorZ, const T aTransLocation, const T aTransScale, + const T aTransShape, const T aTransKurtosis, const T aEpsilon) { + int itr, max_itr; + T x0 = 0, x1, all_err, diff; + all_err = aEpsilon; + max_itr = 1000; + for (itr = 1; itr <= max_itr; itr++) { + diff = tukeyGHTransfor(apDescriptorZ, x0, aTransLocation, aTransScale, aTransShape, aTransKurtosis) / + tukeyGHDiferencial(x0, aTransScale, aTransShape, aTransKurtosis); + x1 = x0 - diff; + if (fabs(diff) < all_err) + return x1; + x0 = x1; + } + return x1; +} + +template +double NonGaussianTransform::tukeyGHTransfor(const T aOriginalValue, const T aCurrentValue, const T aTransLocation, + const T aTransScale, const T aTransShape, const T aTransKurtosis) { + if (aTransShape == 0) + return aOriginalValue - aTransLocation - + aTransScale * aCurrentValue * exp(0.5 * aTransKurtosis * aCurrentValue * aCurrentValue); + else + return aOriginalValue - aTransLocation - (aTransScale * (exp(aTransShape * aCurrentValue) - 1) * + (exp(0.5 * aTransKurtosis * aCurrentValue * aCurrentValue)) / + aTransShape); +} + +template +double NonGaussianTransform::tukeyGHDiferencial(const T aCurrentValue, const T aTransScale, const T aTransShape, + const T aTransKurtosis) { + if (aTransShape == 0) + return -aTransScale * exp((aTransKurtosis * aCurrentValue * aCurrentValue) / 2.0) - + aTransScale * aTransKurtosis * aCurrentValue * aCurrentValue * + exp((aTransKurtosis * aCurrentValue * aCurrentValue) / 2.0); + else + return -aTransScale * exp(aTransShape * aCurrentValue) * + exp((aTransKurtosis * aCurrentValue * aCurrentValue) / 2.0) - + (aTransKurtosis * aCurrentValue * exp((aTransKurtosis * aCurrentValue * aCurrentValue) / 2.0) * + (aTransScale * exp(aTransShape * aCurrentValue) - aTransScale)) / aTransShape; +} diff --git a/src/runtime/starpu/concrete/stride-vec-codelet.cpp b/src/runtime/starpu/concrete/stride-vec-codelet.cpp new file mode 100644 index 00000000..5c8774e9 --- /dev/null +++ b/src/runtime/starpu/concrete/stride-vec-codelet.cpp @@ -0,0 +1,76 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file stride-vec-codelet.cpp + * @brief A class for starpu codelet stride-vec. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet STRIDEVECCodelet::cl_stride_vec = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_stride_vec_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_stride_vec_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 3, + .modes = {STARPU_R, STARPU_W, STARPU_W}, + .name = "stride_vec" +}; + +template +void STRIDEVECCodelet::InsertTask(const void *apDescA, void *apDescB, void *apDescC) { + int row, rows_num; + const auto desc_A = (CHAM_desc_t *) apDescA; + auto desc_B = (CHAM_desc_t *) apDescB; + auto desc_C = (CHAM_desc_t *) apDescC; + + auto desc_mt = desc_A->mt; + auto desc_m = desc_A->m; + auto desc_mb = desc_A->mb; + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_stride_vec, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_A, row, 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_B, (int) floor(row / 2.0), 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_C, (int) floor(row / 2.0), 0), + 0); + } +} + +template +void STRIDEVECCodelet::cl_stride_vec_function(void **apBuffers, void *apCodeletArguments) { + int rows_num; + T *pDescriptor_A, *pDescriptor_B, *pDescriptor_C; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pDescriptor_B = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pDescriptor_C = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + + for (int i = 0, j = 0; i < rows_num - 1; i += 2, j++) { + pDescriptor_B[j] = pDescriptor_A[i]; + pDescriptor_C[j] = pDescriptor_A[i + 1]; + } +} diff --git a/src/runtime/starpu/concrete/tri-stride-vec-codelet.cpp b/src/runtime/starpu/concrete/tri-stride-vec-codelet.cpp new file mode 100644 index 00000000..44dc080d --- /dev/null +++ b/src/runtime/starpu/concrete/tri-stride-vec-codelet.cpp @@ -0,0 +1,83 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file tri-stride-vec-codelet.cpp + * @brief A class for starpu codelet tri-stride-vec. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @author Sameh Abdulah + * @date 2024-02-25 +**/ + +#include + +#include +#include + +using namespace exageostat::runtime; + +template +struct starpu_codelet TriStrideVecCodelet::cl_tri_stride_vec = { +#ifdef USE_CUDA + .where= STARPU_CPU | STARPU_CUDA, + .cpu_funcs={cl_tri_stride_vec_function}, + .cuda_funcs={}, + .cuda_flags={0}, +#else + .where=STARPU_CPU, + .cpu_funcs={cl_tri_stride_vec_function}, + .cuda_funcs={}, + .cuda_flags={(0)}, +#endif + .nbuffers = 4, + .modes = {STARPU_R, STARPU_W, STARPU_W, STARPU_W}, + .name = "tri_stride_vec" +}; + +template +void TriStrideVecCodelet::InsertTask(const void *apDescA, void *apDescB, void *apDescC, void *apDescD) { + int row, rows_num; + const auto desc_A = (CHAM_desc_t *) apDescA; + auto desc_B = (CHAM_desc_t *) apDescB; + auto desc_C = (CHAM_desc_t *) apDescC; + auto desc_D = (CHAM_desc_t *) apDescD; + + auto desc_mt = desc_A->mt; + auto desc_m = desc_A->m; + auto desc_mb = desc_A->mb; + + for (row = 0; row < desc_mt; row++) { + rows_num = row == desc_mt - 1 ? desc_m - row * desc_mb : desc_mb; + starpu_insert_task(&this->cl_tri_stride_vec, + STARPU_VALUE, &rows_num, sizeof(int), + STARPU_R, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_A, row, 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_B, (int) floor(row / 3.0), 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_C, (int) floor(row / 3.0), 0), + STARPU_W, (starpu_data_handle_t) RUNTIME_data_getaddr(desc_D, (int) floor(row / 3.0), 0), + 0); + } +} + +template +void TriStrideVecCodelet::cl_tri_stride_vec_function(void *apBuffers[], void *apCodeletArguments) { + + int rows_num; + T *pDescriptor_A, *pDescriptor_B, *pDescriptor_C, *pDescriptor_D; + + pDescriptor_A = (T *) STARPU_MATRIX_GET_PTR(apBuffers[0]); + pDescriptor_B = (T *) STARPU_MATRIX_GET_PTR(apBuffers[1]); + pDescriptor_C = (T *) STARPU_MATRIX_GET_PTR(apBuffers[2]); + pDescriptor_D = (T *) STARPU_MATRIX_GET_PTR(apBuffers[3]); + + starpu_codelet_unpack_args(apCodeletArguments, &rows_num); + + //accept only temp divided by three (should be optimized) + for (int j = 0, i = 0; i < rows_num - 1; i += 3, j++) { + pDescriptor_B[j] = pDescriptor_A[i]; + pDescriptor_C[j] = pDescriptor_A[i + 1]; + pDescriptor_D[j] = pDescriptor_A[i + 2]; + } +} diff --git a/src/runtime/starpu/helpers/CMakeLists.txt b/src/runtime/starpu/helpers/CMakeLists.txt new file mode 100644 index 00000000..295fba30 --- /dev/null +++ b/src/runtime/starpu/helpers/CMakeLists.txt @@ -0,0 +1,23 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @brief CMake build script for StarPu functions +# @author Mahmoud ElKarargy +# @date 2024-02-19 + +# Include the concrete implementations of the StarPu helpers classes and StarPu Helpes Factory +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/StarPuHelpersFactory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/concrete/ChameleonStarPuHelpers.cpp + ${SOURCES} + ) + +if (USE_HICMA) + list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/concrete/HicmaStarPuHelpers.cpp) +endif () + +set(SOURCES ${SOURCES} PARENT_SCOPE) diff --git a/src/runtime/starpu/helpers/StarPuHelpersFactory.cpp b/src/runtime/starpu/helpers/StarPuHelpersFactory.cpp new file mode 100644 index 00000000..fdb866fa --- /dev/null +++ b/src/runtime/starpu/helpers/StarPuHelpersFactory.cpp @@ -0,0 +1,38 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file StarPuHelpersFactory.cpp + * @brief Factory for StarPu helpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#include +#include + +#ifdef USE_HICMA + +#include + +#endif + +using namespace std; +using namespace exageostat::common; +using namespace exageostat::runtime; + +unique_ptr StarPuHelpersFactory::CreateStarPuHelper(const Computation &aComputation) { + if (aComputation == EXACT_DENSE || aComputation == DIAGONAL_APPROX) { + return make_unique(); + } else if (aComputation == TILE_LOW_RANK) { +#ifdef USE_HICMA + return make_unique(); +#else + throw runtime_error("Tile low rank generation isn't supported without enabling HiCMA. Use -DUSE_HICMA=ON"); +#endif + } + throw runtime_error("You need to enable whether HiCMA or Chameleon"); +} diff --git a/src/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.cpp b/src/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.cpp new file mode 100644 index 00000000..7d122d8c --- /dev/null +++ b/src/runtime/starpu/helpers/concrete/ChameleonStarPuHelpers.cpp @@ -0,0 +1,61 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file ChameleonStarPuHelpers.cpp + * @brief A class for Chameleon implementation of StarPu helpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#include +#include + +using namespace exageostat::runtime; + +void +ChameleonStarPuHelpers::ExaGeoStatOptionsInit(void *apOptions, void *apSequence, void *apRequest) { + + RUNTIME_options_init((RUNTIME_option_t *) apOptions, (CHAM_context_t *) ExaGeoStatHardware::GetChameleonContext(), + (RUNTIME_sequence_t *) apSequence, (RUNTIME_request_t *) apRequest); +} + +void ChameleonStarPuHelpers::ExaGeoStatOptionsFree(void *apOptions) { + RUNTIME_options_ws_free((RUNTIME_option_t *) apOptions); +} + + +void ChameleonStarPuHelpers::ExaGeoStatOptionsFinalize(void *apOptions) { + auto *options = (RUNTIME_option_t *) apOptions; + RUNTIME_options_finalize(options, (CHAM_context_t *) ExaGeoStatHardware::GetChameleonContext()); +} + +void *ChameleonStarPuHelpers::ExaGeoStatDataGetAddr(void *apDescriptor, const int &aDescRow, const int &aDescCol) { + return RUNTIME_data_getaddr((CHAM_desc_t *) apDescriptor, aDescRow, aDescCol); +} + +int ChameleonStarPuHelpers::GetMT(void *apDescriptor) { + auto descriptor = (CHAM_desc_t *) apDescriptor; + return descriptor->mt; +} + +int ChameleonStarPuHelpers::GetM(void *apDescriptor) { + auto descriptor = (CHAM_desc_t *) apDescriptor; + return descriptor->m; +} + +int ChameleonStarPuHelpers::GetMB(void *apDescriptor) { + auto descriptor = (CHAM_desc_t *) apDescriptor; + return descriptor->mb; +} + +void *ChameleonStarPuHelpers::GetOptions() { + return new RUNTIME_option_t; +} + +void ChameleonStarPuHelpers::DeleteOptions(void *apOptions) { + delete (RUNTIME_option_t *) apOptions; +} diff --git a/src/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.cpp b/src/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.cpp new file mode 100644 index 00000000..5b82c4fb --- /dev/null +++ b/src/runtime/starpu/helpers/concrete/HicmaStarPuHelpers.cpp @@ -0,0 +1,58 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file HicmaStarPuHelpers.cpp + * @brief A class for Hicma implementation of StarPu helpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-25 +**/ + +#include +#include + +using namespace exageostat::runtime; + +void HicmaStarPuHelpers::ExaGeoStatOptionsInit(void *apOptions, void *apSequence, void *apRequest) { + HICMA_RUNTIME_options_init((HICMA_option_t *) apOptions, (HICMA_context_t *) ExaGeoStatHardware::GetHicmaContext(), + (HICMA_sequence_t *) apSequence, (HICMA_request_t *) apRequest); +} + +void HicmaStarPuHelpers::ExaGeoStatOptionsFree(void *apOptions) { + HICMA_RUNTIME_options_ws_free((HICMA_option_t *) apOptions); +} + +void HicmaStarPuHelpers::ExaGeoStatOptionsFinalize(void *apOptions) { + auto *options = (HICMA_option_t *) apOptions; + HICMA_RUNTIME_options_finalize(options, (HICMA_context_t *) ExaGeoStatHardware::GetHicmaContext()); +} + +void *HicmaStarPuHelpers::ExaGeoStatDataGetAddr(void *apDescriptor, const int &aDescRow, const int &aDescCol) { + return HICMA_RUNTIME_data_getaddr((HICMA_desc_t *) apDescriptor, aDescRow, aDescCol); +} + +int HicmaStarPuHelpers::GetMT(void *apDescriptor) { + auto descriptor = (HICMA_desc_t *) apDescriptor; + return descriptor->mt; +} + +int HicmaStarPuHelpers::GetM(void *apDescriptor) { + auto descriptor = (HICMA_desc_t *) apDescriptor; + return descriptor->m; +} + +int HicmaStarPuHelpers::GetMB(void *apDescriptor) { + auto descriptor = (HICMA_desc_t *) apDescriptor; + return descriptor->mb; +} + +void *HicmaStarPuHelpers::GetOptions() { + return new HICMA_option_t; +} + +void HicmaStarPuHelpers::DeleteOptions(void *apOptions) { + delete (HICMA_option_t *) apOptions; +} diff --git a/tests/R-tests/TestDataGeneration.R b/tests/R-tests/TestDataGeneration.R new file mode 100644 index 00000000..50955842 --- /dev/null +++ b/tests/R-tests/TestDataGeneration.R @@ -0,0 +1,57 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST)# + +# @file TestDataGeneration.R +# @brief +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-09 + +library("ExaGeoStatCPP") + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with Data Generation only - saving data with default path") + +# Variables +dimension = "3D" +ncores <- 4 +ngpus <- 0 +problem_size <- 16 +dts <- 8 +lts <- 0 +computation <- "exact" +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) + +# You need to provide a log_path to save the data. +log_path <- getwd() +# data path is where to read data from +data_path <- "" +# observations file path is where to read observation file +observations_file <- "" +# recovery file path is where to read recovery file +recovery_file <- "" +p <- 1 +q <- 1 + +hardware <- new(Hardware, computation, ncores, ngpus, p, q) +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension, log_path=log_path) + +# Print the data.. +paste("** Locations X - Y - Z") +locations <- get_locations(data=exageostat_data) +paste(locations) + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with Data Generation - Reading Data") + +# data path is where to read data from +data_path <- "./synthetic_ds/SYN_16_1" + +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension, data_path=data_path) + +paste("** Locations X - Y - Z - after reading") +locations <- get_locations(data=exageostat_data) +paste(locations) \ No newline at end of file diff --git a/tests/R-tests/TestDataModeling.R b/tests/R-tests/TestDataModeling.R new file mode 100644 index 00000000..f0b1567d --- /dev/null +++ b/tests/R-tests/TestDataModeling.R @@ -0,0 +1,76 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST)# + +# @file TestDataGeneration.R +# @brief +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-09 + +library("ExaGeoStatCPP") + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with data Modeling only - dst") + +dimension = "2D" +ncores <- 2 +ngpus <- 0 +problem_size <- 16 +dts <- 8 +lts <- 0 +computation <- "diag_approx" +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) +lower_bound <- c(0.1,0.1,0.1) +upper_bound <- c(5,5,5) +p <- 1 +q <- 1 + +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +z_value <- c( -1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, + 0.161705025505231914, 0.623389205185149065, -1.341858445399783495, + -1.054282062428600009, -1.669383221392507943, 0.219170645803740793, + 0.971213790000161170, 0.538973474182433021, -0.752828466476077041, + 0.290822066007430102) + +locations_x <- c(0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440, 0.652140077821011688, 0.806332494087129037, + 0.553322652018005678, 0.800961318379491916, 0.207324330510414295, + 0.347951476310368490, 0.092042420080872822, 0.465445944914930965, + 0.528267338063630132, 0.974792095826657490, 0.552452887769893985, + 0.877592126344701295) + +locations_y <- c(0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537, 0.168459601739528508, 0.105195696955825133, + 0.396398870832379624, 0.296757457846952011, 0.564507515068284116, + 0.627679865720607300, 0.928648813611047563, 0.958236057068741931, + 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, + 0.942824444953078489) + +theta <- model_data(matrix=z_value, x=locations_x, y=locations_y, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10, computation=computation, band=1) +hardware$finalize_hardware() + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with data Modeling only - tlr") + +lts <- 8 +computation <- "tlr" + +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) +empty_data <- new(Data, problem_size, dimension) +theta <- model_data(matrix=z_value, x=locations_x, y=locations_y, kernel=kernel, dts=dts, lts=lts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10, computation=computation) +hardware$finalize_hardware() + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with data Modeling only - exact") + +lts <- 0 +computation <- "exact" + +empty_data <- new(Data, problem_size, dimension) +hardware <- new(Hardware, computation, ncores, ngpus, 1, 1) +theta <- model_data(matrix=z_value, x=locations_x, y=locations_y, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10, computation=computation) diff --git a/tests/R-tests/TestDataPrediction.R b/tests/R-tests/TestDataPrediction.R new file mode 100644 index 00000000..2afeb679 --- /dev/null +++ b/tests/R-tests/TestDataPrediction.R @@ -0,0 +1,74 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST)# + +# @file TestDataPrediction.R +# @brief +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-09 + +library("ExaGeoStatCPP") + +paste("---------------------------------------------------------------") +paste("ExaGeoStat with data Prediction only - mspe") + +dimension = "2D" +ncores <- 2 +ngpus <- 0 +problem_size <- 16 +dts <- 8 +lts <- 0 +computation <- "exact" +kernel <- "univariate_matern_stationary" +estimated_theta <- c(1,0.1,0.5) +p <- 1 +q <- 1 + +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +z_value <- c(-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, + 0.161705025505231914, 0.623389205185149065, -1.341858445399783495, + -1.054282062428600009, -1.669383221392507943, 0.219170645803740793, + 0.971213790000161170, 0.538973474182433021) + +locations_x <- c(0.092042420080872822, 0.193041886015106440, 0.330556191348134576, + 0.181612878614480805, 0.370473792629892440, 0.652140077821011688, + 0.553322652018005678, 0.800961318379491916, 0.207324330510414295, + 0.465445944914930965, 0.528267338063630132, 0.974792095826657490, + 0.552452887769893985, 0.877592126344701295) + +locations_y <- c(0.928648813611047563, 0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537, 0.168459601739528508, 0.105195696955825133, + 0.396398870832379624, 0.296757457846952011, 0.564507515068284116, + 0.627679865720607300, 0.958236057068741931, + 0.573571374074921758, 0.568657969024185528) + +test_x <- c(0.347951, 0.62768) +test_y <- c(0.806332, 0.105196) +predict_data(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) + +paste("---------------------------------------------------------------") +paste("ExaGeoStat with data Prediction only - idw") + +test_measurements = c(-1.05428, -1.47441) +idw_error = idw(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta, test_measurements=test_measurements) +paste("idw error values:") +paste(idw_error) + +paste("---------------------------------------------------------------") +paste("ExaGeoStat with data Prediction only - fisher") + +fisher_matrix <- fisher(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) +paste("fisher matrix values:") +paste(fisher_matrix) + +paste("---------------------------------------------------------------") +paste("ExaGeoStat with data Prediction only - MLOE-MMOM") +true_theta <- c(1.1,0.2,0.5) + +result_mloe_mmom = mloe_mmom(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta, true_theta=true_theta) +cat(sprintf("MLOE = %.6f", result_mloe_mmom[1]), "\n") +cat(sprintf("MMOM = %.6f", result_mloe_mmom[2]), "\n") diff --git a/tests/R-tests/TestExaGeoStatAPI.R b/tests/R-tests/TestExaGeoStatAPI.R new file mode 100644 index 00000000..618c2c2c --- /dev/null +++ b/tests/R-tests/TestExaGeoStatAPI.R @@ -0,0 +1,78 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST)# + +# @file TestExaGeoStatAPI.R +# @brief +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-09 + +library("ExaGeoStatCPP") + +paste("---------------------------------------------------------------") +paste("ExaGeoStat with all Modules - Dense") + +ncores <- 1 +ngpus <- 0 +problem_size <- 16 +dts <- 8 +lts <- 0 +computation <- "exact" +dimension = "2D" +kernel <- "univariate_matern_stationary" +initial_theta <- c(1,0.1,0.5) +lower_bound <- c(0.1,0.1,0.1) +upper_bound <- c(5,5,5) +p <- 1 +q <- 1 + +hardware <- new(Hardware, computation, ncores, ngpus, p, q) + +exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension) +estimated_theta <- model_data(data=exageostat_data, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10) + +test_x <- c(0.2, 0.330) +test_y <- c(0.104, 0.14) +locations = get_locations(data=exageostat_data) +predict_data(train_data=list(sapply(locations, function(v) v[1]), sapply(locations, function(v) v[2]), get_Z_measurement_vector(data=exageostat_data, type="chameleon")), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with Data Generation only") +new_exageostat_data <- simulate_data(kernel=kernel, initial_theta=initial_theta, problem_size=problem_size, dts=dts, dimension=dimension) + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with data Modeling only") + +z_value <- c( -1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, + 0.161705025505231914, 0.623389205185149065, -1.341858445399783495, + -1.054282062428600009, -1.669383221392507943, 0.219170645803740793, + 0.971213790000161170, 0.538973474182433021, -0.752828466476077041, + 0.290822066007430102) + +locations_x <- c(0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440, 0.652140077821011688, 0.806332494087129037, + 0.553322652018005678, 0.800961318379491916, 0.207324330510414295, + 0.347951476310368490, 0.092042420080872822, 0.465445944914930965, + 0.528267338063630132, 0.974792095826657490, 0.552452887769893985, + 0.877592126344701295) + +locations_y <- c(0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537, 0.168459601739528508, 0.105195696955825133, + 0.396398870832379624, 0.296757457846952011, 0.564507515068284116, + 0.627679865720607300, 0.928648813611047563, 0.958236057068741931, + 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, + 0.942824444953078489) + +empty_data <- new(Data, problem_size, "2D") +estimated_theta <- model_data(data=empty_data, matrix=z_value, x=locations_x, y=locations_y, kernel=kernel, dts=dts, dimension=dimension,lb=lower_bound, ub=upper_bound, mle_itr=10) + +paste("---------------------------------------------------------------------------------------------") +paste("ExaGeoStat with data Prediction only") + +test_x <- c(0.2, 0.330) +test_y <- c(0.104, 0.14) + +predict_data(train_data=list(locations_x, locations_y, z_value), test_data=list(test_x, test_y), kernel=kernel, dts=dts, estimated_theta=estimated_theta) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 6d9a940d..75c33860 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -1,21 +1,32 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy -# @date 2023-01-31 +# @date 2024-01-24 add_subdirectory(api) -add_subdirectory(linear-algebra-solvers) +add_subdirectory(configurations) add_subdirectory(data-generators) -add_subdirectory(configurations/data-generation) -add_subdirectory(kernels) +add_subdirectory(hardware) add_subdirectory(helpers) +add_subdirectory(kernels) +add_subdirectory(linear-algebra-solvers) +add_subdirectory(prediction) +add_subdirectory(results) + +if (USE_HICMA) + add_subdirectory(data-units) +endif () + +if (USE_R) + add_subdirectory(Rcpp-adapters) +endif () enable_testing() -add_executable(exageostat-tests ${EXAGEOSTAT_TESTFILES}) -target_link_libraries(exageostat-tests Catch2::Catch2WithMain ${PROJECT_NAME}_INTERFACE) -catch_discover_tests(exageostat-tests) \ No newline at end of file +add_executable(exageostat-tests main.cpp ${EXAGEOSTAT_TESTFILES}) +target_link_libraries(exageostat-tests Catch2::Catch2 ${PROJECT_NAME}_INTERFACE) +catch_discover_tests(exageostat-tests) diff --git a/tests/cpp-tests/Rcpp-adapters/CMakeLists.txt b/tests/cpp-tests/Rcpp-adapters/CMakeLists.txt new file mode 100644 index 00000000..9a4a59a5 --- /dev/null +++ b/tests/cpp-tests/Rcpp-adapters/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-02-09 + +set(EXAGEOSTAT_TESTFILES + + ${CMAKE_CURRENT_SOURCE_DIR}/TestAllRFunctions.cpp + ${EXAGEOSTAT_TESTFILES} + PARENT_SCOPE + ) + diff --git a/tests/cpp-tests/Rcpp-adapters/TestAllRFunctions.cpp b/tests/cpp-tests/Rcpp-adapters/TestAllRFunctions.cpp new file mode 100644 index 00000000..38f193e3 --- /dev/null +++ b/tests/cpp-tests/Rcpp-adapters/TestAllRFunctions.cpp @@ -0,0 +1,169 @@ +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestAllRFunctions.cpp + * @brief Test suite for R/Rcpp adapters in C++. + * @details This file contains tests for R methods adapted for use in C++ within the ExaGeoStat software package. + * It includes tests for initializing arguments, loading data, modeling data, and predicting data using Rcpp adapters. + * The test suite specifically verifies the integration and functionality of R methods through the Rcpp interface + * within a C++ environment, ensuring that statistical models and algorithms are correctly initialized, + * data is accurately loaded and processed, and predictions are properly executed. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-09 +**/ + +#include + +#include + +using namespace std; + +using namespace exageostat::adapters; +using namespace exageostat::common; + +void TEST_DATA_GENERATION() { + + const string computation = "exact"; + const string dimension = "2D"; + const string kernel = "univariate_matern_stationary"; + const string distance_matrix = "eg"; + const int cores_number = 1; + const int gpus_number = 0; + const int problem_size = 9; + const int dts = 3; + const int lts = 0; + const vector initial_theta = {1, 0.1, 0.5}; + const vector lower_bound = {0.1, 0.1, 0.1}; + const vector upper_bound = {5, 5, 5}; + const vector estimated_theta = {0.9, 0.2, 0.5}; + srand(0); + + auto hardware = ExaGeoStatHardware(computation, cores_number, gpus_number); + auto exageostat_data = R_ExaGeoStatLoadData(kernel, initial_theta, distance_matrix, problem_size, 0, dts, lts, + dimension, "", "", "", ""); + + vector x = {0.257389, 0.456062, 0.797269, 0.242161, 0.440742, 0.276432, 0.493965, 0.953933, 0.86952}; + vector y = {0.138506, 0.238193, 0.170245, 0.579583, 0.514397, 0.752682, 0.867704, 0.610986, 0.891279}; + vector z = {-1.27234, -2.47547, 0.54585, -0.120985, 0.242569, -1.54421, 0.0986468, 0.779835, -1.48139}; + + for (int i = 0; i < problem_size; i++) { + REQUIRE((exageostat_data->GetLocations()->GetLocationX()[i] - x[i]) == Catch::Approx(0.0).margin(1e-6)); + REQUIRE((exageostat_data->GetLocations()->GetLocationY()[i] - y[i]) == Catch::Approx(0.0).margin(1e-6)); + REQUIRE((exageostat_data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z)[i] - + z[i]) == Catch::Approx(0.0).margin(1e-5)); + } + delete exageostat_data; +} + +void TEST_ALL_R_METHODS() { + + const string computation = "exact"; + const int cores_number = 1; + const int gpus_number = 0; + const string dimension = "2D"; + const string kernel = "univariate_matern_stationary"; + const string distance_matrix = "eg"; + const int dts = 8; + const int lts = 0; + + const vector initial_theta = {1, 0.1, 0.5}; + const vector estimated_theta = {0.9, 0.2, 0.5}; + const vector lower_bound = {0.1, 0.1, 0.1}; + const vector upper_bound = {5, 5, 5}; + + vector> train_data = { + {0.193041886015106440, 0.330556191348134576, 0.181612878614480805, 0.370473792629892440, + 0.652140077821011688, 0.806332494087129037, 0.553322652018005678, 0.800961318379491916, + 0.207324330510414295, 0.347951476310368490, 0.092042420080872822, 0.465445944914930965, + 0.528267338063630132, 0.974792095826657490, 0.552452887769893985, 0.877592126344701295}, + {0.103883421072709245, 0.135790035858701447, 0.434683756771190977, 0.400778210116731537, + 0.168459601739528508, 0.105195696955825133, 0.396398870832379624, 0.296757457846952011, + 0.564507515068284116, 0.627679865720607300, 0.928648813611047563, 0.958236057068741931, + 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, 0.942824444953078489}, + {-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, -0.163880452049749520, + 0.313503633252489700, -1.474410682226017677, 0.161705025505231914, 0.623389205185149065, + -1.341858445399783495, -1.054282062428600009, -1.669383221392507943, 0.219170645803740793, + 0.971213790000161170, 0.538973474182433021, -0.752828466476077041, 0.290822066007430102} + }; + vector> test_data = { + {0.193041886015106440, 0.330556191348134576}, + {0.103883421072709245, 0.135790035858701447} + }; + + auto hardware = ExaGeoStatHardware(computation, cores_number, gpus_number); + + SECTION("Prediction Method") { + + // Since we're testing with the same x and y that we sent to the train data, then we expect the same output. + auto result = R_ExaGeoStatPredictData(kernel, distance_matrix, estimated_theta, dts, lts, dimension, train_data, + test_data); + for (int i = 0; i < result.size(); i++) { + REQUIRE((result[i] - train_data[2][i]) == Catch::Approx(0.0).margin(1e-6)); + } + + // Now let's test with new values + test_data = { + {0.2, 0.3}, + {0.2, 0.2} + }; + result = R_ExaGeoStatPredictData(kernel, distance_matrix, estimated_theta, dts, lts, dimension, train_data, + test_data); + vector expected_output = {-1.04437, -1.63133}; + for (int i = 0; i < result.size(); i++) { + REQUIRE((result[i] - expected_output[i]) == Catch::Approx(0.0).margin(1e-5)); + } + + }SECTION("PREDICTION - Fisher") { + + auto result = R_ExaGeoStatFisher(kernel, distance_matrix, estimated_theta, dts, lts, dimension, train_data, + test_data); + + vector expected_output = {0.143552740378975224, 0.022642203822768981, 0.013749788660229965, + 0.022642203822769023, 0.143052423579629107, -0.371722296732991009, + 0.013749788660229986, -0.371722296732990953, 1.101996735797240667}; + + for (int i = 0; i < result.size(); i++) { + REQUIRE((result[i] - expected_output[i]) == Catch::Approx(0.0).margin(1e-6)); + } + } + + SECTION("PREDICTION - MLOE-MMOM") { + test_data = { + {0.347951, 0.62768}, + {0.806332, 0.105196}, + }; + auto result = R_ExaGeoStatMLOE_MMOM(kernel, distance_matrix, estimated_theta, initial_theta, dts, lts, + dimension, train_data, test_data); + vector expected_output = {0.0529825, -0.408526}; + for (int i = 0; i < result.size(); i++) { + REQUIRE((result[i] - expected_output[i]) == Catch::Approx(0.0).margin(1e-6)); + } + + result = R_ExaGeoStatMLOE_MMOM("univariate_matern_stationary", "eg", initial_theta, initial_theta, 8, 0, "2D", + train_data, test_data); + for (double i: result) { + REQUIRE((i - 0) == Catch::Approx(0.0).margin(1e-6)); + } + } + + SECTION("PREDICTION - IDW") { + + vector test_measurements = { + -1.05428, -1.47441 + }; + auto result = R_ExaGeoStatIDW(kernel, distance_matrix, estimated_theta, dts, lts, dimension, train_data, + test_data, test_measurements); + vector expected_output = {0.447903, 0.100866, 0.79494}; + for (int i = 0; i < result.size(); i++) { + REQUIRE((result[i] - expected_output[i]) == Catch::Approx(0.0).margin(1e-6)); + } + } +} + +TEST_CASE("Test R/Rcpp adapters in C++") { + TEST_DATA_GENERATION(); + TEST_ALL_R_METHODS(); +} \ No newline at end of file diff --git a/tests/cpp-tests/api/CMakeLists.txt b/tests/cpp-tests/api/CMakeLists.txt index 9748ef3d..4c8b2eeb 100644 --- a/tests/cpp-tests/api/CMakeLists.txt +++ b/tests/cpp-tests/api/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @author Sameh Abdulah # @date 2023-08-08 diff --git a/tests/cpp-tests/api/TestExaGeoStatApi.cpp b/tests/cpp-tests/api/TestExaGeoStatApi.cpp index 1241baa5..5edcf550 100644 --- a/tests/cpp-tests/api/TestExaGeoStatApi.cpp +++ b/tests/cpp-tests/api/TestExaGeoStatApi.cpp @@ -1,15 +1,15 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TestExaGeoStatApi.cpp * @brief Test suite for the ExaGeoStat APIs data generation functionality. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah - * @date 2023-08-07 + * @date 2024-02-04 **/ #include @@ -18,8 +18,8 @@ using namespace std; using namespace exageostat::common; +using namespace exageostat::dataunits; using namespace exageostat::configurations; -using namespace exageostat::hardware; void TEST_GENERATE_DATA() { SECTION("Data generation - Observations") @@ -47,16 +47,15 @@ void TEST_GENERATE_DATA() { // initialize ExaGeoStat Hardware. auto hardware = ExaGeoStatHardware(EXACT_DENSE, 4, 0); // Or you could use configurations.GetComputation(). - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); // Define the expected output for desk Z double expected_output_data[] = {-1.272336, -2.590700, 0.512143, -0.163880, 0.313504, -1.474411, 0.161705, 0.623389, -1.341858, -1.054282, -1.669383, 0.219171, 0.971214, 0.538973, -0.752828, 0.290822}; - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc; + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(CHAMELEON_DESCRIPTOR, + DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; double diff; @@ -80,7 +79,7 @@ void TEST_MODEL_DATA(Computation aComputation) { configurations.SetDenseTileSize(dts); configurations.SetComputation(aComputation); configurations.SetMaxMleIterations(3); - configurations.SetTolerance(pow(10, -4)); + configurations.SetTolerance(4); vector lb{0.1, 0.1, 0.1}; configurations.SetLowerBounds(lb); @@ -108,8 +107,9 @@ void TEST_MODEL_DATA(Computation aComputation) { { // initialize ExaGeoStat Hardware. auto hardware = ExaGeoStatHardware(aComputation, 4, 0); // Or you could use configurations.GetComputation(). - exageostat::dataunits::ExaGeoStatData data(configurations.GetProblemSize(), - configurations.GetDimension()); + std::unique_ptr> data = std::make_unique>( + configurations.GetProblemSize(), configurations.GetDimension()); + //initiating the matrix of the CHAMELEON Descriptor Z. auto *z_matrix = new double[N]{-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, @@ -133,11 +133,11 @@ void TEST_MODEL_DATA(Computation aComputation) { 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, 0.942824444953078489}; - data.GetLocations()->SetLocationX(*location_x, N); - data.GetLocations()->SetLocationY(*location_y, N); + data->GetLocations()->SetLocationX(*location_x, N); + data->GetLocations()->SetLocationY(*location_y, N); - double log_likelihood = exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, - data, z_matrix); + double log_likelihood = exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(configurations, data, + z_matrix); REQUIRE((log_likelihood - expected) == Catch::Approx(0.0).margin(1e-6)); delete[] location_x; @@ -147,11 +147,9 @@ void TEST_MODEL_DATA(Computation aComputation) { { // initialize ExaGeoStat Hardware. auto hardware = ExaGeoStatHardware(aComputation, 4, 0); // Or you could use configurations.GetComputation(). - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, - data); - double log_likelihood = exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, - data); + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(configurations, data); + double log_likelihood = exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(configurations, data); REQUIRE((log_likelihood - expected) == Catch::Approx(0.0).margin(1e-6)); } } @@ -167,7 +165,7 @@ void TEST_PREDICTION() { configurations.SetDenseTileSize(dts); configurations.SetComputation(EXACT_DENSE); configurations.SetMaxMleIterations(3); - configurations.SetTolerance(pow(10, -4)); + configurations.SetTolerance(4); vector lb{0.1, 0.1, 0.1}; configurations.SetLowerBounds(lb); @@ -181,7 +179,8 @@ void TEST_PREDICTION() { Configurations::SetVerbosity(QUIET_MODE); auto hardware = ExaGeoStatHardware(EXACT_DENSE, configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); - exageostat::dataunits::ExaGeoStatData data(configurations.GetProblemSize(), configurations.GetDimension()); + std::unique_ptr> data = std::make_unique>( + configurations.GetProblemSize(), configurations.GetDimension()); auto *z_matrix = new double[N]{-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, @@ -203,33 +202,33 @@ void TEST_PREDICTION() { 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, 0.942824444953078489}; - data.GetLocations()->SetLocationX(*location_x, N); - data.GetLocations()->SetLocationY(*location_y, N); + data->GetLocations()->SetLocationX(*location_x, N); + data->GetLocations()->SetLocationY(*location_y, N); SECTION("Test Prediction - MSPE ONLY") { vector new_estimated_theta{0.9, 0.09, 0.4}; configurations.SetEstimatedTheta(new_estimated_theta); configurations.SetIsMSPE(true); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); }SECTION("Test Prediction - IDW ONLY") { configurations.SetIsMSPE(false); configurations.SetIsIDW(true); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); }SECTION("Test Prediction - MLOE_MMOM ONLY") { configurations.SetIsMSPE(false); configurations.SetIsIDW(false); vector new_estimated_theta{0.9, 0.09, 0.4}; configurations.SetEstimatedTheta(new_estimated_theta); configurations.SetIsMLOEMMOM(true); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); }SECTION("Test Prediction - FISHER\n") { configurations.SetIsMLOEMMOM(false); configurations.SetIsFisher(true); vector new_estimated_theta{0.9, 0.09, 0.4}; configurations.SetEstimatedTheta(new_estimated_theta); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); }SECTION("Test Prediction - ALL OPERATIONS") { vector new_estimated_theta{0.9, 0.09, 0.4}; configurations.SetEstimatedTheta(new_estimated_theta); @@ -239,16 +238,15 @@ void TEST_PREDICTION() { configurations.SetIsFisher(true); // Setting Estimated with initial theta will require mloe_mmom to be zero configurations.SetEstimatedTheta(initial_theta); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); }SECTION("Test Prediction - ALL MODULES") { configurations.SetIsMSPE(true); configurations.SetIsIDW(true); configurations.SetIsFisher(true); configurations.SetIsMLOEMMOM(true); - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, configurations, - data); - exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(hardware, configurations, data); - exageostat::api::ExaGeoStat::ExaGeoStatPrediction(hardware, configurations, data, z_matrix); + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(configurations, data); + exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(configurations, data); + exageostat::api::ExaGeoStat::ExaGeoStatPrediction(configurations, data, z_matrix); } delete[] location_x; delete[] location_y; @@ -259,6 +257,8 @@ TEST_CASE("ExaGeoStat API tests") { TEST_GENERATE_DATA(); TEST_MODEL_DATA(EXACT_DENSE); TEST_MODEL_DATA(DIAGONAL_APPROX); +#ifdef USE_HICMA TEST_MODEL_DATA(TILE_LOW_RANK); +#endif TEST_PREDICTION(); } \ No newline at end of file diff --git a/tests/cpp-tests/configurations/data-generation/CMakeLists.txt b/tests/cpp-tests/configurations/CMakeLists.txt similarity index 65% rename from tests/cpp-tests/configurations/data-generation/CMakeLists.txt rename to tests/cpp-tests/configurations/CMakeLists.txt index bdcadc45..9b9999e2 100644 --- a/tests/cpp-tests/configurations/data-generation/CMakeLists.txt +++ b/tests/cpp-tests/configurations/CMakeLists.txt @@ -1,16 +1,16 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-01-31 set(EXAGEOSTAT_TESTFILES - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestSyntheticDataConfigurations.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TestConfigurations.cpp ${EXAGEOSTAT_TESTFILES} PARENT_SCOPE diff --git a/tests/cpp-tests/configurations/data-generation/concrete/TestSyntheticDataConfigurations.cpp b/tests/cpp-tests/configurations/TestConfigurations.cpp similarity index 58% rename from tests/cpp-tests/configurations/data-generation/concrete/TestSyntheticDataConfigurations.cpp rename to tests/cpp-tests/configurations/TestConfigurations.cpp index 0aa00c4e..6ea294f6 100644 --- a/tests/cpp-tests/configurations/data-generation/concrete/TestSyntheticDataConfigurations.cpp +++ b/tests/cpp-tests/configurations/TestConfigurations.cpp @@ -1,18 +1,18 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** -* @file synthetic_data.cpp -* @brief Unit tests for the Configurations class in the ExaGeoStat software package. -* @details This file contains Catch2 unit tests that validate the functionality of the Configurations class -* in the ExaGeoStat software package. The tests cover various setters, getters, and value checks -* for configuration parameters such as dimensions, P-GRID, kernel name, problem size, precision, and more. -* Additionally, the tests include a copy-constructor test for the Configurations class. -* @version 1.0.0 -* @author Mahmoud ElKarargy -* @date 2023-01-31 + * @file synthetic_data.cpp + * @brief Unit tests for the Configurations class in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the Configurations class + * in the ExaGeoStat software package. The tests cover various setters, getters, and value checks + * for configuration parameters such as dimensions, P-GRID, kernel name, problem size, precision, and more. + * Additionally, the tests include a copy-constructor test for the Configurations class. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2023-01-31 **/ #include @@ -25,6 +25,75 @@ using namespace std; using namespace exageostat::common; using namespace exageostat::configurations; +void TEST_ARGUMENT_INITIALIZATION() { + + const int argc = 17; + char *argv[] = { + const_cast("program_name"), + const_cast("--N=16"), + const_cast("--dts=8"), + const_cast("--kernel=univariate_matern_stationary"), + const_cast("--computation=exact"), + const_cast("--precision=double"), + const_cast("--initial_theta=1:0.1:0.5"), + const_cast("--ub=5:5:5"), + const_cast("--lb=0.1:0.1:0.1"), + const_cast("--max_mle_iterations=5"), + const_cast("--tolerance=4"), + const_cast("--ZMiss=6"), + const_cast("--mspe"), + const_cast("--idw"), + const_cast("--mloe-mmom"), + const_cast("--fisher"), + const_cast("--data_path=./dummy-path") + }; + + Configurations configurations; + + // Initialize configuration dictionary with only common arguments + configurations.InitializeArguments(argc, argv); + + REQUIRE(configurations.GetProblemSize() == 16); + REQUIRE(configurations.GetKernelName() == "UnivariateMaternStationary"); + REQUIRE(configurations.GetDenseTileSize() == 8); + REQUIRE(configurations.GetPrecision() == DOUBLE); + + // No data generation arguments initialized + REQUIRE(configurations.GetDataPath() == string("")); + + // No data modeling arguments initialized + REQUIRE_THROWS(configurations.GetMaxMleIterations()); + REQUIRE_THROWS(configurations.GetTolerance()); + + // No data prediction arguments initialized + REQUIRE(configurations.GetIsMSPE() == false); + REQUIRE(configurations.GetIsIDW() == false); + REQUIRE(configurations.GetIsFisher() == false); + REQUIRE(configurations.GetIsMLOEMMOM() == false); + REQUIRE(configurations.GetUnknownObservationsNb() == 0); + + // Data generation arguments initialized + configurations.InitializeDataGenerationArguments(); + + REQUIRE(configurations.GetDataPath() == string("./dummy-path")); + + // Data modelling arguments initialized + configurations.InitializeDataModelingArguments(); + + REQUIRE(configurations.GetMaxMleIterations() == 5); + REQUIRE(configurations.GetTolerance() == pow(10, -4)); + + // Data prediction arguments initialized + configurations.InitializeDataPredictionArguments(); + + REQUIRE(configurations.GetIsMSPE() == true); + REQUIRE(configurations.GetIsIDW() == true); + REQUIRE(configurations.GetIsFisher() == true); + REQUIRE(configurations.GetIsMLOEMMOM() == true); + REQUIRE(configurations.GetUnknownObservationsNb() == 6); + +} + void TEST_SYNTHETIC_CONFIGURATIONS() { Configurations synthetic_data_configurations; @@ -113,7 +182,8 @@ void TEST_COPY_CONSTRUCTOR() { } } -TEST_CASE("Synthetic Data Configurations") { +TEST_CASE("Configurations Tests") { TEST_SYNTHETIC_CONFIGURATIONS(); TEST_COPY_CONSTRUCTOR(); + TEST_ARGUMENT_INITIALIZATION(); } diff --git a/tests/cpp-tests/data-generators/CMakeLists.txt b/tests/cpp-tests/data-generators/CMakeLists.txt index c3e1f4de..c84e7cfd 100644 --- a/tests/cpp-tests/data-generators/CMakeLists.txt +++ b/tests/cpp-tests/data-generators/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-03-08 diff --git a/tests/cpp-tests/data-generators/concrete/TestCSVDataGenerator.cpp b/tests/cpp-tests/data-generators/concrete/TestCSVDataGenerator.cpp index a26be8d0..8585b837 100644 --- a/tests/cpp-tests/data-generators/concrete/TestCSVDataGenerator.cpp +++ b/tests/cpp-tests/data-generators/concrete/TestCSVDataGenerator.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -9,7 +9,7 @@ * @details This file contains Catch2 unit tests that validate the functionality of the CSVDataGenerator class * in the ExaGeoStat software package. The tests cover various aspects of data generation, including spreading * and reversing bits, generating locations for different dimensions, and testing helper functions. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-03-08 **/ @@ -19,14 +19,16 @@ #include #include #include +#include using namespace std; using namespace exageostat::generators; using namespace exageostat::dataunits; using namespace exageostat::common; -using namespace exageostat::configurations; using namespace exageostat::kernels; +using namespace exageostat::configurations; +using namespace exageostat::dataLoader::csv; void TEST_CSV_P_1() { int N = 16; @@ -36,7 +38,6 @@ void TEST_CSV_P_1() { read_path = read_path + +"tests/cpp-tests/data-generators/concrete/synthetic_ds/SYN_16_1"; Configurations configurations; - configurations.SetIsCSV(true); configurations.SetIsSynthetic(false); configurations.SetProblemSize(16); configurations.SetDenseTileSize(8); @@ -47,11 +48,12 @@ void TEST_CSV_P_1() { vector initial_theta{1, 0.1, 0.5}; configurations.SetInitialTheta(initial_theta); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), configurations.GetTimeSlot()); - auto hardware = exageostat::hardware::ExaGeoStatHardware(configurations.GetComputation(), - configurations.GetCoresNumber(), - configurations.GetGPUsNumbers()); + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), + configurations.GetCoresNumber(), + configurations.GetGPUsNumbers()); //creating locations x and y. auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, @@ -87,15 +89,12 @@ void TEST_CSV_P_1() { locations.SetLocationX(*location_x, N); locations.SetLocationY(*location_y, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N, p, write_path, locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N, p, write_path, locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -120,16 +119,13 @@ void TEST_CSV_P_1() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_z, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N, p, write_path, locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N, p, write_path, locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_z = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_z = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -137,6 +133,7 @@ void TEST_CSV_P_1() { REQUIRE(data_loc_y[i] - location_y[i] == Catch::Approx(0.0).margin(1e-6)); REQUIRE(data_loc_z[i] - location_z[i] == Catch::Approx(0.0).margin(1e-6)); } + delete[] location_z; } SECTION("Test CSV ST Dimensions locations, p = 1.") { @@ -155,16 +152,13 @@ void TEST_CSV_P_1() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_time, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N, p, write_path, locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N, p, write_path, locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_time = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_time = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -172,7 +166,7 @@ void TEST_CSV_P_1() { REQUIRE(data_loc_y[i] - location_y[i] == Catch::Approx(0.0).margin(1e-6)); REQUIRE(data_loc_time[i] - location_time[i] == Catch::Approx(0.0).margin(1e-6)); } - + delete[] location_time; } delete[] location_x; @@ -189,21 +183,20 @@ void TEST_CSV_P_2() { read_path = read_path + +"tests/cpp-tests/data-generators/concrete/synthetic_ds/SYN_16_1"; Configurations configurations; - configurations.SetIsCSV(true); configurations.SetIsSynthetic(false); configurations.SetProblemSize(16); configurations.SetDenseTileSize(8); - int p = 2; - configurations.SetP(p); configurations.SetKernelName("BivariateMaternParsimonious"); configurations.SetComputation(exageostat::common::EXACT_DENSE); configurations.SetDataPath(read_path); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), configurations.GetTimeSlot()); + int p = pKernel->GetVariablesNumber(); - auto hardware = exageostat::hardware::ExaGeoStatHardware(configurations.GetComputation(), - configurations.GetCoresNumber(), - configurations.GetGPUsNumbers()); + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), + configurations.GetCoresNumber(), + configurations.GetGPUsNumbers()); //creating locations x and y. auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, @@ -250,16 +243,13 @@ void TEST_CSV_P_2() { locations.SetLocationX(*location_x, N); locations.SetLocationY(*location_y, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -287,17 +277,14 @@ void TEST_CSV_P_2() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_z, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_z = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_z = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -305,7 +292,7 @@ void TEST_CSV_P_2() { REQUIRE(data_loc_y[i] - location_y[i] == Catch::Approx(0.0).margin(1e-6)); REQUIRE(data_loc_z[i] - location_z[i] == Catch::Approx(0.0).margin(1e-6)); } - + delete[] location_z; } SECTION("Test CSV ST Dimensions locations, p = 2.") { @@ -327,17 +314,14 @@ void TEST_CSV_P_2() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_time, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_time = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_time = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -345,7 +329,7 @@ void TEST_CSV_P_2() { REQUIRE(data_loc_y[i] - location_y[i] == Catch::Approx(0.0).margin(1e-6)); REQUIRE(data_loc_time[i] - location_time[i] == Catch::Approx(0.0).margin(1e-6)); } - + delete[] location_time; } delete[] location_x; @@ -362,23 +346,22 @@ void TEST_CSV_P_3() { read_path = read_path + +"tests/cpp-tests/data-generators/concrete/synthetic_ds/SYN_16_1"; Configurations configurations; - configurations.SetIsCSV(true); configurations.SetIsSynthetic(false); configurations.SetProblemSize(16); configurations.SetDenseTileSize(3); - int p = 3; - configurations.SetP(p); configurations.SetKernelName("TrivariateMaternParsimonious"); configurations.SetComputation(exageostat::common::EXACT_DENSE); configurations.SetDataPath(read_path); vector initial_theta{1, 1, 1, 0.1, 0.5, 1, 1.5, 0.1, 0.1, 0}; configurations.SetInitialTheta(initial_theta); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), configurations.GetTimeSlot()); + int p = pKernel->GetVariablesNumber(); - auto hardware = exageostat::hardware::ExaGeoStatHardware(configurations.GetComputation(), - configurations.GetCoresNumber(), - configurations.GetGPUsNumbers()); + auto hardware = ExaGeoStatHardware(configurations.GetComputation(), + configurations.GetCoresNumber(), + configurations.GetGPUsNumbers()); //creating locations x and y. auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, @@ -422,16 +405,13 @@ void TEST_CSV_P_3() { locations.SetLocationX(*location_x, N); locations.SetLocationY(*location_y, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -457,17 +437,14 @@ void TEST_CSV_P_3() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_z, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_z = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_z = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -476,6 +453,7 @@ void TEST_CSV_P_3() { REQUIRE(data_loc_z[i] - location_z[i] == Catch::Approx(0.0).margin(1e-6)); } + delete[] location_z; } SECTION("Test CSV ST Dimensions locations, p = 3.") { @@ -494,17 +472,14 @@ void TEST_CSV_P_3() { locations.SetLocationY(*location_y, N); locations.SetLocationZ(*location_time, N); - exageostat::helpers::DiskWriter::WriteVectorsToDisk(*measurements_matrix, N * p, p, write_path, - locations); - auto data = *csv_reader->CreateData(configurations, hardware, *pKernel); + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N * p, p, write_path, + locations); + auto data = csv_reader->CreateData(configurations, *pKernel); - auto z_desc_mat = data.GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, - data.GetDescriptorData()->GetDescriptor( - CHAMELEON_DESCRIPTOR, - DESCRIPTOR_Z).chameleon_desc); - auto data_loc_x = data.GetLocations()->GetLocationX(); - auto data_loc_y = data.GetLocations()->GetLocationY(); - auto data_loc_time = data.GetLocations()->GetLocationZ(); + auto z_desc_mat = data->GetDescriptorData()->GetDescriptorMatrix(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z); + auto data_loc_x = data->GetLocations()->GetLocationX(); + auto data_loc_y = data->GetLocations()->GetLocationY(); + auto data_loc_time = data->GetLocations()->GetLocationZ(); for (int i = 0; i < N; i++) { REQUIRE(z_desc_mat[i] - measurements_matrix[i] == Catch::Approx(0.0).margin(1e-6)); @@ -512,7 +487,7 @@ void TEST_CSV_P_3() { REQUIRE(data_loc_y[i] - location_y[i] == Catch::Approx(0.0).margin(1e-6)); REQUIRE(data_loc_time[i] - location_time[i] == Catch::Approx(0.0).margin(1e-6)); } - + delete[] location_time; } delete[] location_x; diff --git a/tests/cpp-tests/data-generators/concrete/TestSyntheticGenerator.cpp b/tests/cpp-tests/data-generators/concrete/TestSyntheticGenerator.cpp index 2c418bc7..25e07650 100644 --- a/tests/cpp-tests/data-generators/concrete/TestSyntheticGenerator.cpp +++ b/tests/cpp-tests/data-generators/concrete/TestSyntheticGenerator.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -9,7 +9,7 @@ * @details This file contains Catch2 unit tests that validate the functionality of the SyntheticGenerator class * in the ExaGeoStat software package. The tests cover various aspects of data generation, including spreading * and reversing bits, generating locations for different dimensions, and testing helper functions. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-03-08 **/ @@ -20,6 +20,8 @@ #include #include #include +#include +#include using namespace std; @@ -27,8 +29,9 @@ using namespace exageostat::generators::synthetic; using namespace exageostat::generators; using namespace exageostat::dataunits; using namespace exageostat::common; -using namespace exageostat::configurations; using namespace exageostat::kernels; +using namespace exageostat::helpers; +using namespace exageostat::configurations; void TEST_SPREAD_REVERSED_BITS() { @@ -41,7 +44,7 @@ void TEST_SPREAD_REVERSED_BITS() { { uint16_t randomByte = INT16_MAX; REQUIRE(randomByte == 0x7FFF); - uint64_t returnedByte = SyntheticGenerator::SpreadBits(randomByte); + uint64_t returnedByte = SpreadBits(randomByte); // This because 7FFF will first be 16 hex = 64 bits // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 7FFF // 7FFF to bits is 0111111111111111 @@ -51,7 +54,7 @@ void TEST_SPREAD_REVERSED_BITS() { }SECTION("Reverse Spread Bytes") { uint64_t randomByte = 0x0111111111111111; - uint16_t returnedByte = SyntheticGenerator::ReverseSpreadBits(randomByte); + uint16_t returnedByte = ReverseSpreadBits(randomByte); REQUIRE(returnedByte == 0x7FFF); }SECTION("Spread & reverse 3D") { @@ -61,7 +64,7 @@ void TEST_SPREAD_REVERSED_BITS() { uint16_t z = INT16_MAX; uint64_t vectorZ; - vectorZ = (SyntheticGenerator::SpreadBits(z) << 2); + vectorZ = (SpreadBits(z) << 2); // vector Z will be // ---- ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 ---1 // After shifting by 2 @@ -70,7 +73,7 @@ void TEST_SPREAD_REVERSED_BITS() { REQUIRE(vectorZ == 0x0444444444444444); // Do the same for Y - vectorZ += (SyntheticGenerator::SpreadBits(y) << 1); + vectorZ += (SpreadBits(y) << 1); // If vector Z was empty it will be // ---- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- // But sine vectorZ is already contains Z. then by adding both we get @@ -79,16 +82,16 @@ void TEST_SPREAD_REVERSED_BITS() { REQUIRE(vectorZ == 0x0666666666666666); // Lastly, Adding X - vectorZ += SyntheticGenerator::SpreadBits(x); + vectorZ += SpreadBits(x); // Adding X without shifting will result in // ---- -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 -111 // Since 0111 is equal to 7 in hex then expected to be 0x0777777777777777 REQUIRE(vectorZ == 0x0777777777777777); // Spreading is Done, Now reversing. - uint16_t reversed_x = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 0); - uint16_t reversed_y = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 1); - uint16_t reversed_z = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 2); + uint16_t reversed_x = ReverseSpreadBits(vectorZ >> 0); + uint16_t reversed_y = ReverseSpreadBits(vectorZ >> 1); + uint16_t reversed_z = ReverseSpreadBits(vectorZ >> 2); // What we reversed is what we send. REQUIRE(reversed_x == INT16_MAX); @@ -107,13 +110,13 @@ void TEST_SPREAD_REVERSED_BITS() { uint16_t z_random = 22222; //Spreading - vectorZ = (SyntheticGenerator::SpreadBits(z_random) << 2) + - (SyntheticGenerator::SpreadBits(y_random) << 1) + - SyntheticGenerator::SpreadBits(x_random); + vectorZ = (SpreadBits(z_random) << 2) + + (SpreadBits(y_random) << 1) + + SpreadBits(x_random); // Spreading is Done, Now reversing. - uint16_t reversed_x_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 0); - uint16_t reversed_y_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 1); - uint16_t reversed_z_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 2); + uint16_t reversed_x_random = ReverseSpreadBits(vectorZ >> 0); + uint16_t reversed_y_random = ReverseSpreadBits(vectorZ >> 1); + uint16_t reversed_z_random = ReverseSpreadBits(vectorZ >> 2); REQUIRE(x_random == reversed_x_random); REQUIRE(y_random == reversed_y_random); @@ -128,28 +131,28 @@ void TEST_SPREAD_REVERSED_BITS() { uint16_t z = 0; uint64_t vectorZ; - vectorZ = (SyntheticGenerator::SpreadBits(z) << 2); + vectorZ = (SpreadBits(z) << 2); // vector Z will be zeros REQUIRE(vectorZ == 0x0000000000000000); // Do the same for Y - vectorZ += (SyntheticGenerator::SpreadBits(y) << 1); + vectorZ += (SpreadBits(y) << 1); // vector Z after shift by one will be // ---- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- --1- // Since 0010 is equal to 2 in hex then expected to be 0x022222222222222 REQUIRE(vectorZ == 0x0222222222222222); // Lastly, Adding X - vectorZ += SyntheticGenerator::SpreadBits(x); + vectorZ += SpreadBits(x); // Adding X without shifting will result in // ---- --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 --11 // Since 0011 is equal to 3 in hex then expected to be 0x0333333333333333 REQUIRE(vectorZ == 0x0333333333333333); // Spreading is Done, Now reversing. - uint16_t reversed_x = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 0); - uint16_t reversed_y = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 1); - uint16_t reversed_z = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 2); + uint16_t reversed_x = ReverseSpreadBits(vectorZ >> 0); + uint16_t reversed_y = ReverseSpreadBits(vectorZ >> 1); + uint16_t reversed_z = ReverseSpreadBits(vectorZ >> 2); // What we reversed is what we send. REQUIRE(reversed_x == INT16_MAX); @@ -168,13 +171,13 @@ void TEST_SPREAD_REVERSED_BITS() { uint16_t z_random = 0; //Spreading - vectorZ = (SyntheticGenerator::SpreadBits(z_random) << 2) + - (SyntheticGenerator::SpreadBits(y_random) << 1) + - SyntheticGenerator::SpreadBits(x_random); + vectorZ = (SpreadBits(z_random) << 2) + + (SpreadBits(y_random) << 1) + + SpreadBits(x_random); // Spreading is Done, Now reversing. - uint16_t reversed_x_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 0); - uint16_t reversed_y_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 1); - uint16_t reversed_z_random = SyntheticGenerator::ReverseSpreadBits(vectorZ >> 2); + uint16_t reversed_x_random = ReverseSpreadBits(vectorZ >> 0); + uint16_t reversed_y_random = ReverseSpreadBits(vectorZ >> 1); + uint16_t reversed_z_random = ReverseSpreadBits(vectorZ >> 2); REQUIRE(x_random == reversed_x_random); REQUIRE(y_random == reversed_y_random); @@ -191,19 +194,20 @@ void TEST_GENERATE_LOCATIONS() { synthetic_data_configurations.SetComputation(exageostat::common::EXACT_DENSE); vector initial_theta{1, 0.1, 0.5}; synthetic_data_configurations.SetInitialTheta(initial_theta); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(synthetic_data_configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + synthetic_data_configurations.GetKernelName(), synthetic_data_configurations.GetTimeSlot()); - auto hardware = exageostat::hardware::ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), - synthetic_data_configurations.GetCoresNumber(), - synthetic_data_configurations.GetGPUsNumbers()); + auto hardware = ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), + synthetic_data_configurations.GetCoresNumber(), + synthetic_data_configurations.GetGPUsNumbers()); SECTION("2D Generation") { unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( synthetic_data_configurations); synthetic_data_configurations.SetDimension(Dimension2D); - auto *data = synthetic_generator->CreateData(synthetic_data_configurations, hardware, *pKernel); + auto data = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); double *x = data->GetLocations()->GetLocationX(); double *y = data->GetLocations()->GetLocationY(); @@ -213,15 +217,12 @@ void TEST_GENERATE_LOCATIONS() { REQUIRE(x[i] != 0); REQUIRE(y[i] != 0); } - delete data; - } - SECTION("3D Generation") + }SECTION("3D Generation") { synthetic_data_configurations.SetDimension(Dimension3D); unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( synthetic_data_configurations); - auto *data = synthetic_generator->CreateData(synthetic_data_configurations, - hardware, *pKernel); + auto data = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); double *x = data->GetLocations()->GetLocationX(); double *y = data->GetLocations()->GetLocationY(); @@ -232,16 +233,14 @@ void TEST_GENERATE_LOCATIONS() { REQUIRE(y[i] != 0); REQUIRE(z[i] != 0); } - delete data; - } - SECTION("ST Generation") + + }SECTION("ST Generation") { synthetic_data_configurations.SetDimension(DimensionST); synthetic_data_configurations.SetTimeSlot(2); unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( synthetic_data_configurations); - auto *data = synthetic_generator->CreateData(synthetic_data_configurations, - hardware, *pKernel); + auto data = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); double *x = data->GetLocations()->GetLocationX(); double *y = data->GetLocations()->GetLocationY(); @@ -252,7 +251,7 @@ void TEST_GENERATE_LOCATIONS() { REQUIRE(y[i] != 0.0); REQUIRE(z[i] != 0.0); } - delete data; + } delete pKernel; @@ -269,7 +268,7 @@ void TEST_HELPERS_FUNCTIONS() { { double lowerRange = -0.4; double higherRange = 0.4; - double uniformed_num = SyntheticGenerator::UniformDistribution(lowerRange, higherRange); + double uniformed_num = LocationGenerator::UniformDistribution(lowerRange, higherRange); REQUIRE(uniformed_num > lowerRange); REQUIRE(uniformed_num < 1); } @@ -277,9 +276,9 @@ void TEST_HELPERS_FUNCTIONS() { SECTION("Compare Uint32") { uint32_t num1 = 16; - REQUIRE(SyntheticGenerator::CompareUint64(num1, num1) == false); - REQUIRE(SyntheticGenerator::CompareUint64(num1, num1 + num1) == true); - REQUIRE(SyntheticGenerator::CompareUint64(num1 + num1, num1) == false); + REQUIRE(CompareUint64(num1, num1) == false); + REQUIRE(CompareUint64(num1, num1 + num1) == true); + REQUIRE(CompareUint64(num1 + num1, num1) == false); SyntheticGenerator::ReleaseInstance(); } } @@ -298,18 +297,19 @@ void TEST_GENERATION() { synthetic_data_configurations.SetDenseTileSize(1); synthetic_data_configurations.SetKernelName("UnivariateMaternStationary"); synthetic_data_configurations.SetComputation(exageostat::common::EXACT_DENSE); - auto hardware = exageostat::hardware::ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), - synthetic_data_configurations.GetCoresNumber(), - synthetic_data_configurations.GetGPUsNumbers()); + auto hardware = ExaGeoStatHardware(synthetic_data_configurations.GetComputation(), + synthetic_data_configurations.GetCoresNumber(), + synthetic_data_configurations.GetGPUsNumbers()); - Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(synthetic_data_configurations.GetKernelName()); + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + synthetic_data_configurations.GetKernelName(), synthetic_data_configurations.GetTimeSlot()); unique_ptr> synthetic_generator = DataGenerator::CreateGenerator( synthetic_data_configurations); // Initialize the seed manually with zero, to get the first generated seeded numbers. int seed = 0; srand(seed); - auto *data = synthetic_generator->CreateData(synthetic_data_configurations, hardware, *pKernel); + auto data = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); // The expected output of the locations. vector x = {0.257389, 0.456062, 0.797269, 0.242161, 0.440742, 0.276432, 0.493965, 0.953933, 0.86952}; vector y = {0.138506, 0.238193, 0.170245, 0.579583, 0.514397, 0.752682, 0.867704, 0.610986, 0.891279}; @@ -320,7 +320,7 @@ void TEST_GENERATION() { } // Now test re-generating locations again, but without modifying seed manually which will results in completely new locations values - auto *data1 = synthetic_generator->CreateData(synthetic_data_configurations, hardware, *pKernel); + auto data1 = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); for (int i = 0; i < N; i++) { REQUIRE((data1->GetLocations()->GetLocationX()[i] - x[i]) != Catch::Approx(0.0).margin(1e-6)); REQUIRE((data1->GetLocations()->GetLocationY()[i] - y[i]) != Catch::Approx(0.0).margin(1e-6)); @@ -329,14 +329,11 @@ void TEST_GENERATION() { // Now if we modified seed again, we will get the first generated locations again. int seed_srand = 0; srand(seed_srand); - auto *data2 = synthetic_generator->CreateData(synthetic_data_configurations, hardware, *pKernel); + auto data2 = synthetic_generator->CreateData(synthetic_data_configurations, *pKernel); for (int i = 0; i < N; i++) { REQUIRE((data2->GetLocations()->GetLocationX()[i] - x[i]) == Catch::Approx(0.0).margin(1e-6)); REQUIRE((data2->GetLocations()->GetLocationY()[i] - y[i]) == Catch::Approx(0.0).margin(1e-6)); } - delete data; - delete data1; - delete data2; delete pKernel; } } diff --git a/tests/cpp-tests/data-units/CMakeLists.txt b/tests/cpp-tests/data-units/CMakeLists.txt new file mode 100644 index 00000000..1bbfb1df --- /dev/null +++ b/tests/cpp-tests/data-units/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-01-24 + +set(EXAGEOSTAT_TESTFILES + ${CMAKE_CURRENT_SOURCE_DIR}/TestDescriptorData.cpp + ${EXAGEOSTAT_TESTFILES} + PARENT_SCOPE + ) diff --git a/tests/cpp-tests/data-units/TestDescriptorData.cpp b/tests/cpp-tests/data-units/TestDescriptorData.cpp new file mode 100644 index 00000000..5f87d1a0 --- /dev/null +++ b/tests/cpp-tests/data-units/TestDescriptorData.cpp @@ -0,0 +1,64 @@ +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestDescriptorData.cpp + * @brief Tests for CHAMELEON to HICMA descriptor conversion in ExaGeoStat. + * @details This test case verifies the conversion of matrix descriptors from the CHAMELEON format to the HICMA format. + * It ensures that key properties of the matrix descriptor, such as dimensions, block sizes, and grid distribution parameters, are preserved during the conversion process. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-02-04 +**/ + +#include + +#include + +using namespace std; + +using namespace exageostat::linearAlgebra; +using namespace exageostat::common; +using namespace exageostat::dataunits; +using namespace exageostat::configurations; + +void TEST_CHAM_TO_HICMA_CONV() { + + // Initialize Configuration + Configurations synthetic_data_configurations; + synthetic_data_configurations.SetProblemSize(4); + synthetic_data_configurations.SetDenseTileSize(1); + + // Initialize linear algebra solver + int p = 1; + auto hardware = ExaGeoStatHardware(TILE_LOW_RANK, 1, 0); + auto linearAlgebraSolver = LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); + auto *data = new DescriptorData(); + linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, p); + + // Create CHAM descriptor and convert it to HICMA descriptor + auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; + auto *HICMA_descriptor = data->ConvertChameleonToHicma(CHAM_descriptorC,DESCRIPTOR_C); + + // Verify common attributes are of same value + REQUIRE(CHAM_descriptorC->m == HICMA_descriptor->m); + REQUIRE(CHAM_descriptorC->n == HICMA_descriptor->n); + REQUIRE(CHAM_descriptorC->mb == HICMA_descriptor->mb); + REQUIRE(CHAM_descriptorC->nb == HICMA_descriptor->nb); + REQUIRE(CHAM_descriptorC->bsiz == HICMA_descriptor->bsiz); + REQUIRE(CHAM_descriptorC->i == HICMA_descriptor->i); + REQUIRE(CHAM_descriptorC->j == HICMA_descriptor->j); + REQUIRE(CHAM_descriptorC->mt == HICMA_descriptor->mt); + REQUIRE(CHAM_descriptorC->nt == HICMA_descriptor->nt); + REQUIRE(CHAM_descriptorC->lm == HICMA_descriptor->lm); + REQUIRE(CHAM_descriptorC->ln == HICMA_descriptor->ln); + REQUIRE(CHAM_descriptorC->p == HICMA_descriptor->p); + REQUIRE(CHAM_descriptorC->q == HICMA_descriptor->q); + + delete data; +} + +TEST_CASE(" CHAMELEON To HICMA Converter") { + TEST_CHAM_TO_HICMA_CONV(); +} diff --git a/tests/cpp-tests/hardware/CMakeLists.txt b/tests/cpp-tests/hardware/CMakeLists.txt new file mode 100644 index 00000000..c60a7043 --- /dev/null +++ b/tests/cpp-tests/hardware/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-01-24 + +set(EXAGEOSTAT_TESTFILES + ${CMAKE_CURRENT_SOURCE_DIR}/TestExaGeoStatHardware.cpp + ${EXAGEOSTAT_TESTFILES} + PARENT_SCOPE + ) diff --git a/tests/cpp-tests/hardware/TestExaGeoStatHardware.cpp b/tests/cpp-tests/hardware/TestExaGeoStatHardware.cpp new file mode 100644 index 00000000..67e0e2a3 --- /dev/null +++ b/tests/cpp-tests/hardware/TestExaGeoStatHardware.cpp @@ -0,0 +1,111 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestExaGeoStatHardware.cpp + * @brief Unit tests for the ExaGeoStatHardware class in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the ExaGeoStatHardware class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-24 +**/ + +#include + +#include + +using namespace exageostat::common; + +void TEST_HARDWARE_CONSTRUCTION() { + + //Initialize multiple instances of the hardware, and verify chameleon context is not null. + auto hardware_1 = ExaGeoStatHardware(EXACT_DENSE, 4, 0); + REQUIRE(hardware_1.GetChameleonContext() != nullptr); + + auto hardware_2 = ExaGeoStatHardware(DIAGONAL_APPROX, 4, 0); + REQUIRE(hardware_2.GetChameleonContext() != nullptr); + REQUIRE(hardware_1.GetChameleonContext() == hardware_2.GetChameleonContext()); + + //In case of HICMA initialize a TLR hardware and verify non-null context, + // otherwise exception is raised in case of initialization. +#ifdef USE_HICMA + auto hardware_3 = ExaGeoStatHardware(TILE_LOW_RANK, 4, 0); + REQUIRE(hardware_3.GetHicmaContext() != nullptr); + + auto hardware_4 = ExaGeoStatHardware(TILE_LOW_RANK, 4, 0); + REQUIRE(hardware_4.GetHicmaContext() != nullptr); + REQUIRE(hardware_3.GetHicmaContext() == hardware_4.GetHicmaContext()); +#else + REQUIRE_THROWS(ExaGeoStatHardware(TILE_LOW_RANK, 4, 0)); +#endif + +} + +void TEST_STATIC_CONTEXT() { + + //Initialize multiple instances of the hardware: EXACT_DENSE,DIAGONAL_APPROX ,and verify they all have same static Chameleon context. + auto hardware_1 = ExaGeoStatHardware(EXACT_DENSE, 4, 0); + auto context_hardware_1 = ExaGeoStatHardware::GetContext(EXACT_DENSE); + + auto hardware_2 = ExaGeoStatHardware(EXACT_DENSE, 1, 0); + auto context_hardware_2 = ExaGeoStatHardware::GetContext(EXACT_DENSE); + REQUIRE(context_hardware_1 == context_hardware_2); + + auto hardware_3 = ExaGeoStatHardware(DIAGONAL_APPROX, 7, 0); + auto context_hardware_3 = ExaGeoStatHardware::GetContext(DIAGONAL_APPROX); + REQUIRE(context_hardware_2 == context_hardware_3); + + auto hardware_4 = ExaGeoStatHardware(DIAGONAL_APPROX, 3, 0); + auto context_hardware_4 = ExaGeoStatHardware::GetContext(DIAGONAL_APPROX); + REQUIRE(context_hardware_3 == context_hardware_4); + + //In case of HICMA initialize multiple instances of the TLR hardware. +#ifdef USE_HICMA + // Verify they have same static HICMA context + auto hardware_5 = ExaGeoStatHardware(TILE_LOW_RANK, 4, 0); + REQUIRE(hardware_5.GetContext(TILE_LOW_RANK) != nullptr); + + auto hardware_6 = ExaGeoStatHardware(TILE_LOW_RANK, 4, 0); + REQUIRE(hardware_6.GetContext(TILE_LOW_RANK) != nullptr); + REQUIRE(hardware_5.GetContext(TILE_LOW_RANK) == hardware_6.GetContext(TILE_LOW_RANK)); + + // Verify they have same Chameleon context as the EXACT_DENSE and DIAGONAL_APPROX hardware + REQUIRE(hardware_5.GetContext(EXACT_DENSE) == hardware_6.GetContext(EXACT_DENSE)); + REQUIRE(hardware_5.GetContext(EXACT_DENSE) == hardware_1.GetContext(EXACT_DENSE)); +#endif + +} + +void TEST_CONTEXT_GETTER() { + + // Initialize multiple instances of hardware, and verify context getter results. + auto hardware_1 = ExaGeoStatHardware(EXACT_DENSE, 1, 0); + auto hardware_2 = ExaGeoStatHardware(DIAGONAL_APPROX, 1, 0); + + // Chameleon context is always non-null + REQUIRE(hardware_1.GetContext(EXACT_DENSE) != nullptr); + REQUIRE(hardware_2.GetContext(DIAGONAL_APPROX) != nullptr); + + //In case of HICMA, initialize TLR hardware. +#ifdef USE_HICMA + auto hardware_3 = ExaGeoStatHardware(TILE_LOW_RANK, 4, 0); + + // Hicma context and Chameleon context are always non-null + REQUIRE(hardware_3.GetContext(TILE_LOW_RANK) != nullptr); + REQUIRE(hardware_3.GetContext(EXACT_DENSE) != nullptr); + REQUIRE(hardware_3.GetContext(DIAGONAL_APPROX) != nullptr); +#else + // Otherwise an exception is raised + REQUIRE_THROWS(hardware_1.GetContext(TILE_LOW_RANK)); + REQUIRE_THROWS(hardware_2.GetContext(TILE_LOW_RANK)); +#endif +} + +TEST_CASE("ExaGeoStat Hardware Tests") { + TEST_HARDWARE_CONSTRUCTION(); + TEST_CONTEXT_GETTER(); + TEST_STATIC_CONTEXT(); +} + diff --git a/tests/cpp-tests/helpers/CMakeLists.txt b/tests/cpp-tests/helpers/CMakeLists.txt index 4bae3c7a..c3f0158c 100644 --- a/tests/cpp-tests/helpers/CMakeLists.txt +++ b/tests/cpp-tests/helpers/CMakeLists.txt @@ -1,16 +1,16 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy -# @author Sameh Abdulah -# @date 2023-12-08 +# @date 2024-01-24 set(EXAGEOSTAT_TESTFILES - ${CMAKE_CURRENT_SOURCE_DIR}/TestPredictionHelpers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TestDiskWriter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TestDistanceCalculationHelpers.cpp ${EXAGEOSTAT_TESTFILES} PARENT_SCOPE diff --git a/tests/cpp-tests/helpers/TestDiskWriter.cpp b/tests/cpp-tests/helpers/TestDiskWriter.cpp new file mode 100644 index 00000000..2ffc65dc --- /dev/null +++ b/tests/cpp-tests/helpers/TestDiskWriter.cpp @@ -0,0 +1,83 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestDiskWriter.cpp + * @brief Unit tests for the DiskWriter in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the class DiskWriter. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-24 +**/ + +#include +#include + +#include +#include + +using namespace exageostat::dataunits; +using namespace exageostat::common; +using namespace exageostat::dataLoader::csv; + +void TEST_3D_VECTORS_WRITING() { + // Initialize data vectors + int N = 8; + auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440, 0.652140077821011688, 0.806332494087129037, + 0.553322652018005678, 0.800961318379491916}; + + auto *location_y = new double[N]{0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537, 0.168459601739528508, 0.105195696955825133, + 0.396398870832379624, 0.296757457846952011}; + + auto *location_z = new double[N]{1, 1, 1, 1, + 1, 1, 1, 1}; + + auto *measurements_matrix = new double[N]{-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, + 0.161705025505231914, 0.623389205185149065}; + + // Initialize Locations object, that will be written in file + Locations locations(N, Dimension3D); + locations.SetLocationX(*location_x, N); + locations.SetLocationY(*location_y, N); + locations.SetLocationZ(*location_z, N); + + const int p = 1; + + std::string write_path = PROJECT_SOURCE_DIR; + std::string expectedFilePath = write_path + "/synthetic_ds/SYN_" + std::to_string(N / p) + "_1"; + + // Write the data into file + CSVLoader::GetInstance()->WriteData(*measurements_matrix, N, p, write_path, locations); + REQUIRE(std::filesystem::exists(expectedFilePath)); + + std::ifstream file(expectedFilePath); + REQUIRE(file.is_open()); + + // Read the contents from the file + std::string line; + for (int i = 0; i < N / p; ++i) { + std::getline(file, line); + + std::ostringstream oss; + oss << std::setprecision(15) << locations.GetLocationX()[i] << ',' + << locations.GetLocationY()[i] << ',' << locations.GetLocationZ()[i] << "," << std::setprecision(15) + << measurements_matrix[i]; + std::string expectedLine = oss.str(); + + REQUIRE(line == expectedLine); + } + + delete[] location_x; + delete[] location_y; + delete[] location_z; + delete[] measurements_matrix; +} + +TEST_CASE("Disk Writer Tests") { + TEST_3D_VECTORS_WRITING(); +} diff --git a/tests/cpp-tests/helpers/TestDistanceCalculationHelpers.cpp b/tests/cpp-tests/helpers/TestDistanceCalculationHelpers.cpp new file mode 100644 index 00000000..aae67a88 --- /dev/null +++ b/tests/cpp-tests/helpers/TestDistanceCalculationHelpers.cpp @@ -0,0 +1,144 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestDistanceCalculationHelpers.cpp + * @brief Unit tests for the DistanceCalculationHelpers.cpp in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the class DistanceCalculationHelpers. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-24 +**/ + +#include +#include + +#include +#include + +using namespace exageostat::common; +using namespace exageostat::helpers; +using namespace exageostat::dataunits; + +void TEST_RADIAN_CONVERSION() { + exageostat::helpers::DistanceCalculationHelpers distance_helper; + REQUIRE(distance_helper.DegreeToRadian(0) == Catch::Approx(0.0)); + REQUIRE(distance_helper.DegreeToRadian(90) == Catch::Approx(PI / 2)); + REQUIRE(distance_helper.DegreeToRadian(180) == Catch::Approx(PI)); +} + +void TEST_CALCULATE_DISTANCE() { + + SECTION("2D - Euclidean & Haversine Distance") { + int size = 2; + + // 2D - Locations initializations + auto *location_x = new double[size]{10.0, 4.0}; + auto *location_y = new double[size]{12.0, 4.0}; + + Locations location1(size, Dimension2D); + Locations location2(size, Dimension2D); + + location1.SetLocationX(*location_x, size); + location1.SetLocationY(*location_y, size); + location2.SetLocationX(*location_x, size); + location2.SetLocationY(*location_y, size); + + int idx1 = 0; // index of x-coordinate + int idx2 = 1; // index of y-coordinate + int flagZ = 0; // 2D case + + int distanceMetric = 0; // Default - Use Euclidean distance + REQUIRE(DistanceCalculationHelpers::CalculateDistance(location1, location2, idx1, idx2, distanceMetric, + flagZ) == 10); + + distanceMetric = 1; // Use Haversine distance + auto distance_earth = DistanceCalculationHelpers::DistanceEarth(location_x[idx1], location_y[idx1], + location_x[idx2], location_y[idx2]); + REQUIRE(DistanceCalculationHelpers::CalculateDistance(location1, location2, idx1, idx2, distanceMetric, + flagZ) == distance_earth); + + delete[] location_x; + delete[] location_y; + }SECTION("3D - Euclidean & Haversine Distance") { + int size = 3; + + // 3D - Locations initializations + auto *location_x = new double[size]{10.0, 4.0}; + auto *location_y = new double[size]{12.0, 4.0}; + auto *location_z = new double[size]{1, 2}; + + Locations location1(size, Dimension3D); + Locations location2(size, Dimension3D); + + location1.SetLocationX(*location_x, size); + location1.SetLocationY(*location_y, size); + location1.SetLocationZ(*location_z, size); + + location2.SetLocationX(*location_x, size); + location2.SetLocationY(*location_y, size); + location2.SetLocationZ(*location_z, size); + + int idx1 = 0; // index of x-coordinate + int idx2 = 1; // index of y-coordinate + int flagZ = 1; // 2D case + + int distanceMetric = 0; // Use Euclidean distance + REQUIRE(DistanceCalculationHelpers::CalculateDistance(location1, location2, idx1, idx2, distanceMetric, + flagZ) == Catch::Approx(10.05).epsilon(0.01)); + + distanceMetric = 1; // Use Haversine distance + REQUIRE_THROWS( + DistanceCalculationHelpers::CalculateDistance(location1, location2, idx1, idx2, distanceMetric, + flagZ)); + + delete[] location_x; + delete[] location_y; + delete[] location_z; + } +} + +void TEST_DISTANCE_EARTH() { + SECTION("Distance between two identical points") { + + double lat = 0.1, lon = 0.2; + REQUIRE(DistanceCalculationHelpers::DistanceEarth(lat, lon, lat, lon) == Catch::Approx(0.0)); + + }SECTION("Distance between North Pole and South Pole") { + + double north_pole_Lat = 90.0, pole_Lon = 0.0; + double south_pole_Lat = -90.0; + REQUIRE(DistanceCalculationHelpers::DistanceEarth(north_pole_Lat, pole_Lon, south_pole_Lat, pole_Lon) == + Catch::Approx(EARTH_RADIUS * M_PI)); + + }SECTION("Distance between two points on the equator 90 degrees apart") { + + double equator_Lat = 0.0; + double lon1 = 0.0, lon2 = 90.0; + REQUIRE(DistanceCalculationHelpers::DistanceEarth(equator_Lat, lon1, equator_Lat, lon2) == + Catch::Approx(EARTH_RADIUS * M_PI / 2)); + + }SECTION("Distance between two arbitrary points") { + + // Arbitrary location coordinates + double location1_lat = 40.7128; + double location1_lon = -74.0060; + double location2_lat = 34.0522; + double location2_lon = -118.2437; + + // The expected distance is approximately 3940 kilometers + double expectedDistance = 3940.0; + double calculatedDistance = DistanceCalculationHelpers::DistanceEarth(location1_lat, location1_lon, + location2_lat, location2_lon); + REQUIRE(calculatedDistance == Catch::Approx(expectedDistance).epsilon(0.01)); + + } +} + +TEST_CASE("Degree to Radian Conversion") { + TEST_RADIAN_CONVERSION(); + TEST_CALCULATE_DISTANCE(); + TEST_DISTANCE_EARTH(); +} \ No newline at end of file diff --git a/tests/cpp-tests/kernels/CMakeLists.txt b/tests/cpp-tests/kernels/CMakeLists.txt index cc96f6b4..40ea4ea0 100644 --- a/tests/cpp-tests/kernels/CMakeLists.txt +++ b/tests/cpp-tests/kernels/CMakeLists.txt @@ -1,35 +1,18 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-04-29 -set(EXAGEOSTAT_TESTFILES +# Automatically add all kernels tests in the concrete directory. +file(GLOB ALL_KERNELS ${CMAKE_CURRENT_SOURCE_DIR}/concrete/*.cpp) - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNonStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateMaternFlexible.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDsigmaSquare.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateMaternParsimonious.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNuggetsStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateSpacetimeMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDnu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDbeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquare.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdbetaBeta.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdbetaNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternDdnuNu.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestBivariateSpacetimeMaternStationary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNonGaussian.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateExpNonGaussian.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestTrivariateMaternParsimonious.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestUnivariateMaternNonStat.cpp +set(EXAGEOSTAT_TESTFILES + ${ALL_KERNELS} ${EXAGEOSTAT_TESTFILES} PARENT_SCOPE - ) + ) \ No newline at end of file diff --git a/tests/cpp-tests/kernels/concrete/TestBivariateMaternFlexible.cpp b/tests/cpp-tests/kernels/concrete/TestBivariateMaternFlexible.cpp index 9ad99895..0189e7c5 100644 --- a/tests/cpp-tests/kernels/concrete/TestBivariateMaternFlexible.cpp +++ b/tests/cpp-tests/kernels/concrete/TestBivariateMaternFlexible.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -7,7 +7,7 @@ * @brief Unit tests for the BivariateMaternFlexible kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the BivariateMaternFlexible kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-09 @@ -19,10 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_BivariateMaternFlexible() { @@ -49,11 +48,10 @@ void TEST_KERNEL_GENERATION_BivariateMaternFlexible() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = {-0.696887, -2.069051, -0.417382, -1.001165, -0.235721, -1.726871, -0.285059, diff --git a/tests/cpp-tests/kernels/concrete/TestBivariateMaternParsimonious.cpp b/tests/cpp-tests/kernels/concrete/TestBivariateMaternParsimonious.cpp index 497a979b..fd951ab6 100644 --- a/tests/cpp-tests/kernels/concrete/TestBivariateMaternParsimonious.cpp +++ b/tests/cpp-tests/kernels/concrete/TestBivariateMaternParsimonious.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestBivariateMaternParsimonious kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestBivariateMaternParsimonious kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -20,10 +20,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_BivariateMaternParsimonious() { @@ -50,11 +49,10 @@ void TEST_KERNEL_GENERATION_BivariateMaternParsimonious() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = {-1.272336, -2.466950, 0.294719, -0.605327, 0.386028, -1.598090, 0.278897, diff --git a/tests/cpp-tests/kernels/concrete/TestBivariateSpacetimeMaternStationary.cpp b/tests/cpp-tests/kernels/concrete/TestBivariateSpacetimeMaternStationary.cpp index 81fde6bf..c03aa2ff 100644 --- a/tests/cpp-tests/kernels/concrete/TestBivariateSpacetimeMaternStationary.cpp +++ b/tests/cpp-tests/kernels/concrete/TestBivariateSpacetimeMaternStationary.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestBivariateSpacetimeMaternStationary kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestBivariateSpacetimeMaternStationary kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -20,10 +20,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_BivariateSpacetimeMaternStationary() { @@ -41,7 +40,7 @@ void TEST_KERNEL_GENERATION_BivariateSpacetimeMaternStationary() { synthetic_data_configurations.SetInitialTheta(initial_theta); synthetic_data_configurations.SetDimension(DimensionST); - synthetic_data_configurations.SetTimeSlot(5); + synthetic_data_configurations.SetTimeSlot(3); int dts = 4; synthetic_data_configurations.SetDenseTileSize(dts); synthetic_data_configurations.SetComputation(EXACT_DENSE); @@ -51,22 +50,18 @@ void TEST_KERNEL_GENERATION_BivariateSpacetimeMaternStationary() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output - double expected_output_data[] = { - -1.272336, -2.516013, -1.182511, -2.512958, -1.203093, -2.548053, -1.213645, -2.511269, -1.807922, - -2.992990, -2.072972, -3.001448, -1.525724, -3.004085, -1.997874, -2.993439, -1.256771, -2.832258, - -1.022281, -2.827732, -0.924332, -2.856855, -1.363071, -2.832165, -1.680104, -3.400946, -1.685995, - -3.414854, -1.318928, -3.440336, -1.944915, -3.428945, -1.300296, -3.367150, -1.572847, -3.392844, - -1.126261, -3.392112, -1.682665, -3.394862 - }; - - for (size_t i = 0; i < N; i++) { + double expected_output_data[] = {-1.272336, -2.516013, -1.171584, -2.513616, -1.168821, -2.531118, -1.200293, + -1.960279, -1.919141, -2.005663, -2.279083, -2.006927, -0.807580, -1.719351, + -1.532754, -1.733719, -0.935139, -1.752957, 0.125841, -1.722780, -0.162095, + -1.738346, -0.866950, -1.753649}; + + for (size_t i = 0; i < N * 3 * 2; i++) { double diff = A[i] - expected_output_data[i]; REQUIRE(diff == Catch::Approx(0.0).margin(1e-6)); } diff --git a/tests/cpp-tests/kernels/concrete/TestTrivariateMaternParsimonious.cpp b/tests/cpp-tests/kernels/concrete/TestTrivariateMaternParsimonious.cpp index 5c42c4c2..c412e4db 100644 --- a/tests/cpp-tests/kernels/concrete/TestTrivariateMaternParsimonious.cpp +++ b/tests/cpp-tests/kernels/concrete/TestTrivariateMaternParsimonious.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestTrivariateMaternParsimonious kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestTrivariateMaternParsimonious kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -20,10 +20,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_TrivariateMaternParsimonious() { @@ -48,11 +47,10 @@ void TEST_KERNEL_GENERATION_TrivariateMaternParsimonious() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateExpNonGaussian.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateExpNonGaussian.cpp index 18abd91e..984f33be 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateExpNonGaussian.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateExpNonGaussian.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TestUnivariateExpNonGaussian.cpp * @brief - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDbeta.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDbeta.cpp index 0ec31efd..43fba252 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDbeta.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDbeta.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDbeta kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDbeta kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -18,8 +18,9 @@ #include using namespace std; -using namespace exageostat::configurations; + using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDbeta() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaBeta.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaBeta.cpp index 9102f9b6..76e5cdea 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaBeta.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaBeta.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdbetaBeta kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdbetaBeta kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,9 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdbetaBeta() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaNu.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaNu.cpp index 903ef13a..3d7e03d4 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaNu.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdbetaNu.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdbetaNu kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdbetaNu kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,10 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdbetaNu() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdnuNu.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdnuNu.cpp index 4e0b3a74..762208e4 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdnuNu.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdnuNu.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdnuNu kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdnuNu kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,9 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdnuNu() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquare.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquare.cpp index f3e9d072..775847ad 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquare.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquare.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdsigmaSquare kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdsigmaSquare kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -17,11 +17,11 @@ #include #include -using namespace exageostat::configurations; +using namespace std; + using namespace exageostat::common; using namespace exageostat::api; - -using namespace std; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdsigmaSquare() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp index 9f277794..657e1357 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareBeta.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdsigmaSquareBetaBeta kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdsigmaSquareBetaBeta kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -18,9 +18,10 @@ #include using namespace std; -using namespace exageostat::configurations; + using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdsigmaSquareBeta() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp index 566786bc..785eb847 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDdsigmaSquareNu.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdsigmaSquareNu kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdsigmaSquareNu kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,9 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDdsigmaSquareNu() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDnu.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDnu.cpp index 5d212512..cdfbbf2c 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDnu.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDnu.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDnu kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDnu kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,9 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDnu() { SECTION("UnivariateMaternDnu") diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDsigmaSquare.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDsigmaSquare.cpp index dde48ff4..bb44c9bc 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDsigmaSquare.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternDsigmaSquare.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternDdsigmaSquare kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternDdsigmaSquare kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-29 @@ -19,9 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternDsigmaSquare() { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonGaussian.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonGaussian.cpp index daec5161..7252175e 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonGaussian.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonGaussian.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternNonGaussian kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternNonGaussian kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,10 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternNonGaussian() { @@ -36,6 +35,12 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNonGaussian() { synthetic_data_configurations.SetProblemSize(N); synthetic_data_configurations.SetKernelName("UnivariateMaternNonGaussian"); + vector lb{0.01, 0.01, -5, 0.1, -2}; + synthetic_data_configurations.SetLowerBounds(lb); + + vector ub{15, 5, 5, 5, 2, 2}; + synthetic_data_configurations.SetUpperBounds(ub); + vector initial_theta{7.0711, 1, 0, 2, 0, 0}; synthetic_data_configurations.SetInitialTheta(initial_theta); int dts = 3; @@ -46,11 +51,10 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNonGaussian() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = { @@ -60,7 +64,7 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNonGaussian() { }; for (size_t i = 0; i < N; i++) { - double diff = A[i] - expected_output_data[i]; + double diff = A[i] - expected_output_data[i] / 2; REQUIRE(diff == Catch::Approx(0.0).margin(1e-6)); } } diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStationary.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStationary.cpp deleted file mode 100644 index 35be6dc5..00000000 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStationary.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, -// All rights reserved. -// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). - -/** - * @file TestUnivariateMaternNonStationary.cpp - * @brief - * @version 1.0.0 - * @author Mahmoud ElKarargy - * @author Sameh Abdulah - * @date 2023-05-08 -**/ diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNuggetsStationary.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNuggetsStationary.cpp index da21bc33..28bc9221 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNuggetsStationary.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNuggetsStationary.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternNuggetsStationary kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternNuggetsStationary kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -20,10 +20,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternNuggetsStationary() { @@ -48,11 +47,10 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNuggetsStationary() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = { diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternStationary.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternStationary.cpp index 461c0a20..c74cc623 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternStationary.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateMaternStationary.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateMaternStationary kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternStationary kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-04-29 @@ -20,10 +20,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateMaternStationary() { @@ -49,12 +48,11 @@ void TEST_KERNEL_GENERATION_UnivariateMaternStationary() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output double expected_output_data[] = {-1.272336, -2.475473, 0.545850, -0.120985, 0.242569, -1.544215, 0.098647, diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStat.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariatePowExpStationary.cpp similarity index 55% rename from tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStat.cpp rename to tests/cpp-tests/kernels/concrete/TestUnivariatePowExpStationary.cpp index a7382c04..e6c65c16 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateMaternNonStat.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariatePowExpStationary.cpp @@ -1,17 +1,17 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** - * @file TestUnivariateMaternNonStat.cpp - * @brief Unit tests for the TestUnivariateMaternNonStat kernel in the ExaGeoStat software package. - * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateMaternNonStat kernel + * @file TestUnivariatePowExpStationary.cpp + * @brief Unit tests for the TestUnivariatePowExpStationary kernel in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariatePowExpStationary kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 - * @author Mahmoud ElKarargy + * @version 1.1.0 * @author Sameh Abdulah - * @date 2023-05-10 + * @author Mahmoud ElKarargy + * @date 2024-01-16 **/ #include @@ -20,28 +20,27 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; -void TEST_KERNEL_GENERATION_UnivariateMaternNonStat() { +void TEST_KERNEL_GENERATION_UnivariatePowExpStationary() { - SECTION("UnivariateMaternNonStat") + SECTION("UnivariatePowExpStationary") { // Create a new synthetic_data_configurations object with the provided command line arguments Configurations synthetic_data_configurations; - int N = 16; + int N = 9; synthetic_data_configurations.SetProblemSize(N); - synthetic_data_configurations.SetKernelName("UnivariateMaternNonStat"); + synthetic_data_configurations.SetKernelName("UnivariatePowExpStationary"); synthetic_data_configurations.SetDimension(Dimension2D); - vector initial_theta{0.04, 1.57, 0.33, -1, 0.8, 0.1, -0.5, 0.5}; + vector initial_theta{1, 0.1, 0.5}; synthetic_data_configurations.SetInitialTheta(initial_theta); - int dts = 3; + int dts = 5; synthetic_data_configurations.SetDenseTileSize(dts); synthetic_data_configurations.SetComputation(EXACT_DENSE); // initialize ExaGeoStat Hardware. @@ -49,18 +48,15 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNonStat() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output - double expected_output_data[] = { - -1.329875, -2.691617, 0.043584, -0.606902, -0.213657, -1.322967, - -0.281561, 0.084918, -1.152730, -1.209422, -1.776260, -0.410195, - 0.221300, 0.454534, -0.742289, 0.135949 - }; + double expected_output_data[] = {-1.272336, -2.362813, 0.616384, -0.072468, 0.401498, -1.559690, 0.211848, + 0.776627, -1.524810}; for (size_t i = 0; i < N; i++) { double diff = A[i] - expected_output_data[i]; @@ -69,7 +65,7 @@ void TEST_KERNEL_GENERATION_UnivariateMaternNonStat() { } } -TEST_CASE("UnivariateMaternNonStat kernel test") { - TEST_KERNEL_GENERATION_UnivariateMaternNonStat(); +TEST_CASE("Univariate Pow-Exp Stationary kernel test") { + TEST_KERNEL_GENERATION_UnivariatePowExpStationary(); -} \ No newline at end of file +} diff --git a/tests/cpp-tests/kernels/concrete/TestUnivariateSpacetimeMaternStationary.cpp b/tests/cpp-tests/kernels/concrete/TestUnivariateSpacetimeMaternStationary.cpp index 365bcf7d..132d726f 100644 --- a/tests/cpp-tests/kernels/concrete/TestUnivariateSpacetimeMaternStationary.cpp +++ b/tests/cpp-tests/kernels/concrete/TestUnivariateSpacetimeMaternStationary.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). @@ -8,7 +8,7 @@ * @brief Unit tests for the TestUnivariateSpacetimeMaternStationary kernel in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestUnivariateSpacetimeMaternStationary kernel * in the ExaGeoStat software package. The tests cover the generation of data using this kernel with various configurations. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @author Sameh Abdulah * @date 2023-05-10 @@ -19,10 +19,9 @@ using namespace std; -using namespace exageostat::configurations; using namespace exageostat::api; using namespace exageostat::common; -using namespace exageostat::hardware; +using namespace exageostat::configurations; void TEST_KERNEL_GENERATION_UnivariateSpacetimeMaternStationary() { @@ -50,22 +49,17 @@ void TEST_KERNEL_GENERATION_UnivariateSpacetimeMaternStationary() { int seed = 0; srand(seed); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - auto *CHAM_descriptorZ = data.GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, - exageostat::common::DESCRIPTOR_Z).chameleon_desc; + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + auto *CHAM_descriptorZ = data->GetDescriptorData()->GetDescriptor(exageostat::common::CHAMELEON_DESCRIPTOR, + exageostat::common::DESCRIPTOR_Z).chameleon_desc; auto *A = (double *) CHAM_descriptorZ->mat; // Define the expected output - double expected_output_data[] = { - -1.272336, -2.499643, 0.241533, -0.680865, - -0.966917, -2.919659, 0.289843, -0.387418, - -1.633527, -2.982286, -0.534392, -0.453970, - -0.907212, -2.455697, -0.617580, -0.289998, - -0.755687, -3.013465, 0.547427, -0.665510 - }; - - for (size_t i = 0; i < N; i++) { + double expected_output_data[] = {-1.272336, -2.600097, -0.482699, -0.533521, 0.008692, -1.750492, -0.453709, + 0.336176, -1.573801, -1.256633, -1.817694, -0.305688, 0.627641, 0.376389, + -0.939680, 0.167822, 0.514814, -1.315864, 1.884674, -0.234791}; + + for (size_t i = 0; i < N * 5; i++) { double diff = A[i] - expected_output_data[i]; REQUIRE(diff == Catch::Approx(0.0).margin(1e-6)); } diff --git a/tests/cpp-tests/linear-algebra-solvers/CMakeLists.txt b/tests/cpp-tests/linear-algebra-solvers/CMakeLists.txt index 555e0cb7..a50eb717 100644 --- a/tests/cpp-tests/linear-algebra-solvers/CMakeLists.txt +++ b/tests/cpp-tests/linear-algebra-solvers/CMakeLists.txt @@ -1,10 +1,10 @@ -# Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, # All rights reserved. # ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). # @file CMakeLists.txt -# @version 1.0.0 +# @version 1.1.0 # @author Mahmoud ElKarargy # @date 2023-04-06 @@ -14,7 +14,7 @@ set(EXAGEOSTAT_TESTFILES ${EXAGEOSTAT_TESTFILES} ) -if (EXAGEOSTAT_USE_HICMA) +if (USE_HICMA) list(APPEND EXAGEOSTAT_TESTFILES ${CMAKE_CURRENT_SOURCE_DIR}/concrete/TestHiCMAImplementationTLR.cpp ) diff --git a/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDST.cpp b/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDST.cpp index 4d889111..9b31bbfb 100644 --- a/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDST.cpp +++ b/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDST.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TestChameleonImplementationDST.cpp * @brief Unit tests for the Diagonal Super Tile computation in the ExaGeoStat software package. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-04-09 **/ @@ -25,29 +25,26 @@ using namespace std; using namespace exageostat::linearAlgebra; using namespace exageostat::common; -using namespace exageostat::configurations; using namespace exageostat::dataunits; -using namespace exageostat::hardware; +using namespace exageostat::configurations; //Test that the function initializes the CHAM_descriptorC descriptor correctly. void TEST_CHAMELEON_DESCRIPTORS_VALUES_DST() { Configurations synthetic_data_configurations; - + int p = 1; SECTION("SINGLE") { // initialize Hardware. auto hardware = ExaGeoStatHardware(DIAGONAL_APPROX, 1, 0); auto linearAlgebraSolver = LinearAlgebraFactory::CreateLinearAlgebraSolver(DIAGONAL_APPROX); - linearAlgebraSolver->SetContext(hardware.GetChameleonContext()); - synthetic_data_configurations.SetProblemSize(64); synthetic_data_configurations.SetDenseTileSize(16); auto *data = new DescriptorData(); - linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, nullptr); + linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, p, nullptr); auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; auto *CHAM_descriptorZ = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; @@ -55,7 +52,7 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES_DST() { auto *CHAM_descriptorDeterminant = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_DETERMINANT).chameleon_desc; auto *CHAM_descriptorProduct = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT).chameleon_desc; - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); + int N = synthetic_data_configurations.GetProblemSize(); int dts = synthetic_data_configurations.GetDenseTileSize(); int pGrid = synthetic_data_configurations.GetPGrid(); int qGrid = synthetic_data_configurations.GetQGrid(); @@ -165,13 +162,11 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES_DST() { auto hardware = ExaGeoStatHardware(DIAGONAL_APPROX, 2, 0); auto linearAlgebraSolver = LinearAlgebraFactory::CreateLinearAlgebraSolver(DIAGONAL_APPROX); - linearAlgebraSolver->SetContext(hardware.GetChameleonContext()); - synthetic_data_configurations.SetProblemSize(32); synthetic_data_configurations.SetDenseTileSize(16); auto *data = new DescriptorData(); - linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, nullptr); + linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, p, nullptr); auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; auto *CHAM_descriptorZ = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; @@ -181,7 +176,7 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES_DST() { auto *CHAM_descriptorProduct = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT).chameleon_desc; auto *CHAM_descriptorProduct_1 = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_1).chameleon_desc; auto *CHAM_descriptorProduct_2 = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_2).chameleon_desc; - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); + int N = synthetic_data_configurations.GetProblemSize(); int dts = synthetic_data_configurations.GetDenseTileSize(); int pGrid = synthetic_data_configurations.GetPGrid(); int qGrid = synthetic_data_configurations.GetQGrid(); diff --git a/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDense.cpp b/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDense.cpp index c96b7417..d0d978a2 100644 --- a/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDense.cpp +++ b/tests/cpp-tests/linear-algebra-solvers/concrete/TestChameleonImplementationDense.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TestChameleonImplmentationDense.cpp * @brief Unit tests for the Dense computation in the ExaGeoStat software package. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-04-06 **/ @@ -25,15 +25,14 @@ using namespace std; using namespace exageostat::linearAlgebra; using namespace exageostat::common; -using namespace exageostat::configurations; using namespace exageostat::dataunits; -using namespace exageostat::hardware; +using namespace exageostat::configurations; //Test that the function initializes the CHAM_descriptorC descriptor correctly. void TEST_CHAMELEON_DESCRIPTORS_VALUES() { Configurations synthetic_data_configurations; - + int p = 1; SECTION("SINGLE") { @@ -41,13 +40,11 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES() { auto hardware = ExaGeoStatHardware(EXACT_DENSE, 1, 0); auto linearAlgebraSolver = LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); - linearAlgebraSolver->SetContext(hardware.GetChameleonContext()); - synthetic_data_configurations.SetProblemSize(4); synthetic_data_configurations.SetDenseTileSize(1); auto *data = new DescriptorData(); - linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, nullptr); + linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, p, nullptr); auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; auto *CHAM_descriptorZ = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_Z).chameleon_desc; @@ -55,7 +52,7 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES() { auto *CHAM_descriptorDeterminant = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_DETERMINANT).chameleon_desc; auto *CHAM_descriptorProduct = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT).chameleon_desc; - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); + int N = synthetic_data_configurations.GetProblemSize(); int dts = synthetic_data_configurations.GetDenseTileSize(); int pGrid = synthetic_data_configurations.GetPGrid(); int qGrid = synthetic_data_configurations.GetQGrid(); @@ -165,13 +162,11 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES() { auto hardware = ExaGeoStatHardware(EXACT_DENSE, 4, 0); auto linearAlgebraSolver = LinearAlgebraFactory::CreateLinearAlgebraSolver(EXACT_DENSE); - linearAlgebraSolver->SetContext(hardware.GetChameleonContext()); - synthetic_data_configurations.SetProblemSize(64); synthetic_data_configurations.SetDenseTileSize(8); auto *data = new DescriptorData(); - linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, nullptr); + linearAlgebraSolver->InitiateDescriptors(synthetic_data_configurations, *data, p, nullptr); auto *CHAM_descriptorC = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C).chameleon_desc; auto *CHAM_descsubC11 = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_C11).chameleon_desc; @@ -187,7 +182,7 @@ void TEST_CHAMELEON_DESCRIPTORS_VALUES() { auto *CHAM_descriptorProduct_1 = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_1).chameleon_desc; auto *CHAM_descriptorProduct_2 = data->GetDescriptor(CHAMELEON_DESCRIPTOR, DESCRIPTOR_PRODUCT_2).chameleon_desc; - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); + int N = synthetic_data_configurations.GetProblemSize(); int dts = synthetic_data_configurations.GetDenseTileSize(); int pGrid = synthetic_data_configurations.GetPGrid(); int qGrid = synthetic_data_configurations.GetQGrid(); diff --git a/tests/cpp-tests/linear-algebra-solvers/concrete/TestHiCMAImplementationTLR.cpp b/tests/cpp-tests/linear-algebra-solvers/concrete/TestHiCMAImplementationTLR.cpp index 00f1f51d..db014810 100644 --- a/tests/cpp-tests/linear-algebra-solvers/concrete/TestHiCMAImplementationTLR.cpp +++ b/tests/cpp-tests/linear-algebra-solvers/concrete/TestHiCMAImplementationTLR.cpp @@ -1,12 +1,12 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** * @file TestHiCMAImplementationTLR.cpp * @brief Unit tests for the Tile Low Rank computation in the ExaGeoStat software package. - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-04-09 **/ @@ -18,99 +18,77 @@ using namespace std; using namespace exageostat::common; -using namespace exageostat::configurations; using namespace exageostat::dataunits; -using namespace exageostat::hardware; +using namespace exageostat::configurations; //Test that the function initializes the HICMA_descriptorC descriptor correctly. void TEST_HICMA_DESCRIPTORS_VALUES_TLR() { - Configurations synthetic_data_configurations; - synthetic_data_configurations.SetComputation(exageostat::common::TILE_LOW_RANK); - synthetic_data_configurations.SetMaxMleIterations(1); - synthetic_data_configurations.SetTolerance(pow(10, -4)); - - vector lb{0.1, 0.1, 0.1}; - synthetic_data_configurations.SetLowerBounds(lb); - synthetic_data_configurations.SetStartingTheta(lb); - vector ub{5, 5, 5}; - synthetic_data_configurations.SetUpperBounds(ub); - vector initial_theta{1, 0.1, 0.5}; - synthetic_data_configurations.SetInitialTheta(initial_theta); - vector estimated_theta{-1, -1, -1}; - synthetic_data_configurations.SetEstimatedTheta(estimated_theta); - synthetic_data_configurations.SetKernelName("UnivariateMaternStationary"); - synthetic_data_configurations.SetMaxRank(500); - synthetic_data_configurations.SetProblemSize(16); - synthetic_data_configurations.SetLowTileSize(8); - synthetic_data_configurations.SetDenseTileSize(8); - - SECTION("With Approximation mode ON") - { + SECTION("descriptors values") { + + Configurations synthetic_data_configurations; + synthetic_data_configurations.SetComputation(exageostat::common::TILE_LOW_RANK); + synthetic_data_configurations.SetMaxMleIterations(1); + synthetic_data_configurations.SetTolerance(4); + + vector lb{0.1, 0.1, 0.1}; + synthetic_data_configurations.SetLowerBounds(lb); + synthetic_data_configurations.SetStartingTheta(lb); + vector ub{5, 5, 5}; + synthetic_data_configurations.SetUpperBounds(ub); + vector initial_theta{1, 0.1, 0.5}; + synthetic_data_configurations.SetInitialTheta(initial_theta); + vector estimated_theta{-1, -1, -1}; + synthetic_data_configurations.SetEstimatedTheta(estimated_theta); + synthetic_data_configurations.SetKernelName("UnivariateMaternStationary"); + synthetic_data_configurations.SetMaxRank(500); + synthetic_data_configurations.SetProblemSize(16); + synthetic_data_configurations.SetLowTileSize(8); + synthetic_data_configurations.SetDenseTileSize(8); // initialize Hardware. auto hardware = ExaGeoStatHardware(TILE_LOW_RANK, 1, 0); synthetic_data_configurations.SetApproximationMode(1); - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(hardware, synthetic_data_configurations, data); + std::unique_ptr> data; + exageostat::api::ExaGeoStat::ExaGeoStatLoadData(synthetic_data_configurations, data); + exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(synthetic_data_configurations, data); - auto *HICMA_descriptorC = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_C).hicma_desc; + auto *HICMA_descriptorC = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_C).hicma_desc; int approximationMode = synthetic_data_configurations.GetApproximationMode(); - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); - int lts = synthetic_data_configurations.GetLowTileSize(); - int pGrid = synthetic_data_configurations.GetPGrid(); - int qGrid = synthetic_data_configurations.GetQGrid(); - - if (approximationMode == 1) { - // Descriptor C. - REQUIRE(HICMA_descriptorC->m == N); - REQUIRE(HICMA_descriptorC->n == N); - REQUIRE(HICMA_descriptorC->mb == lts); - REQUIRE(HICMA_descriptorC->nb == lts); - REQUIRE(HICMA_descriptorC->bsiz == lts * lts); - REQUIRE(HICMA_descriptorC->i == 0); - REQUIRE(HICMA_descriptorC->j == 0); - REQUIRE(HICMA_descriptorC->mt == ceil((N * 1.0) / (lts * 1.0))); - REQUIRE(HICMA_descriptorC->nt == ceil((N * 1.0) / (lts * 1.0))); - REQUIRE(HICMA_descriptorC->lm == N); - REQUIRE(HICMA_descriptorC->ln == N); - REQUIRE(HICMA_descriptorC->p == pGrid); - REQUIRE(HICMA_descriptorC->q == qGrid); - } - }SECTION("With Approximation mode OFF") { - synthetic_data_configurations.SetApproximationMode(0); - - // initialize Hardware. - auto hardware = ExaGeoStatHardware(TILE_LOW_RANK, 1, 0); - - exageostat::dataunits::ExaGeoStatData data; - exageostat::api::ExaGeoStat::ExaGeoStatLoadData(hardware, synthetic_data_configurations, - data); - exageostat::api::ExaGeoStat::ExaGeoStatDataModeling(hardware, synthetic_data_configurations, data); - - int N = synthetic_data_configurations.GetProblemSize() * synthetic_data_configurations.GetP(); + int N = synthetic_data_configurations.GetProblemSize(); int lts = synthetic_data_configurations.GetLowTileSize(); int pGrid = synthetic_data_configurations.GetPGrid(); int qGrid = synthetic_data_configurations.GetQGrid(); - // Re-Run again but with approx mode OFF + // Descriptor C. + REQUIRE(HICMA_descriptorC->m == N); + REQUIRE(HICMA_descriptorC->n == N); + REQUIRE(HICMA_descriptorC->mb == lts); + REQUIRE(HICMA_descriptorC->nb == lts); + REQUIRE(HICMA_descriptorC->bsiz == lts * lts); + REQUIRE(HICMA_descriptorC->i == 0); + REQUIRE(HICMA_descriptorC->j == 0); + REQUIRE(HICMA_descriptorC->mt == ceil((N * 1.0) / (lts * 1.0))); + REQUIRE(HICMA_descriptorC->nt == ceil((N * 1.0) / (lts * 1.0))); + REQUIRE(HICMA_descriptorC->lm == N); + REQUIRE(HICMA_descriptorC->ln == N); + REQUIRE(HICMA_descriptorC->p == pGrid); + REQUIRE(HICMA_descriptorC->q == qGrid); int maxRank = synthetic_data_configurations.GetMaxRank(); string actualObservationsFilePath = synthetic_data_configurations.GetActualObservationsFilePath(); - auto *HICMA_descriptorZ = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_Z).hicma_desc; - auto *HICMA_descriptorZcpy = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, - DESCRIPTOR_Z_COPY).hicma_desc; - auto *HICMA_descriptorDeterminant = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, - DESCRIPTOR_DETERMINANT).hicma_desc; - auto *HICMA_descriptorCD = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_CD).hicma_desc; - auto *HICMA_descriptorCUV = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, - DESCRIPTOR_CUV).hicma_desc; - auto *HICMA_descriptorCrk = data.GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, - DESCRIPTOR_CRK).hicma_desc; + auto *HICMA_descriptorZ = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_Z).hicma_desc; + auto *HICMA_descriptorZcpy = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, + DESCRIPTOR_Z_COPY).hicma_desc; + auto *HICMA_descriptorDeterminant = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, + DESCRIPTOR_DETERMINANT).hicma_desc; + auto *HICMA_descriptorCD = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, DESCRIPTOR_CD).hicma_desc; + auto *HICMA_descriptorCUV = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, + DESCRIPTOR_CUV).hicma_desc; + auto *HICMA_descriptorCrk = data->GetDescriptorData()->GetDescriptor(HICMA_DESCRIPTOR, + DESCRIPTOR_CRK).hicma_desc; // Descriptor CD. REQUIRE(HICMA_descriptorCD->m == N); @@ -211,10 +189,9 @@ void TEST_HICMA_DESCRIPTORS_VALUES_TLR() { REQUIRE(HICMA_descriptorDeterminant->ln == 1); REQUIRE(HICMA_descriptorDeterminant->p == pGrid); REQUIRE(HICMA_descriptorDeterminant->q == qGrid); - } } TEST_CASE("HiCMA Implementation TLR") { TEST_HICMA_DESCRIPTORS_VALUES_TLR(); -} \ No newline at end of file +} diff --git a/tests/cpp-tests/main.cpp b/tests/cpp-tests/main.cpp new file mode 100644 index 00000000..615c8555 --- /dev/null +++ b/tests/cpp-tests/main.cpp @@ -0,0 +1,23 @@ +#include + +#ifdef USE_MPI +#include +#endif + +int main(int argc, char* argv[]) { + +#ifdef USE_MPI + int provided = 0; + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); +#endif + + int result = Catch::Session().run( argc, argv ); + +#ifdef USE_MPI + MPI_Finalize(); +#endif + + return result; +} + + diff --git a/tests/cpp-tests/prediction/CMakeLists.txt b/tests/cpp-tests/prediction/CMakeLists.txt new file mode 100644 index 00000000..f2d68617 --- /dev/null +++ b/tests/cpp-tests/prediction/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-01-24 + +set(EXAGEOSTAT_TESTFILES + + ${CMAKE_CURRENT_SOURCE_DIR}/TestPrediction.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TestPredictionHelpers.cpp + + ${EXAGEOSTAT_TESTFILES} + PARENT_SCOPE + ) + diff --git a/tests/cpp-tests/prediction/TestPrediction.cpp b/tests/cpp-tests/prediction/TestPrediction.cpp new file mode 100644 index 00000000..49605ed7 --- /dev/null +++ b/tests/cpp-tests/prediction/TestPrediction.cpp @@ -0,0 +1,202 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestPrediction.cpp + * @brief Unit tests for the TestPrediction class in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the TestPrediction class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-1-18 +**/ + +#include + +#include + +using namespace std; + +using namespace exageostat::common; +using namespace exageostat::prediction; +using namespace exageostat::results; +using namespace exageostat::configurations; + +void TEST_PREDICTION_MISSING_DATA() { + + //Init configuration + Configurations configurations; + configurations.SetUnknownObservationsNb(4); + int N = 16; + configurations.SetProblemSize(N); + configurations.SetKernelName("UnivariateMaternStationary"); + int dts = 8; + + configurations.SetDenseTileSize(dts); + configurations.SetComputation(EXACT_DENSE); + configurations.SetMaxMleIterations(3); + configurations.SetTolerance(4); + + vector lb{0.1, 0.1, 0.1}; + configurations.SetLowerBounds(lb); + configurations.SetStartingTheta(lb); + vector ub{5, 5, 5}; + configurations.SetUpperBounds(ub); + vector initial_theta{1, 0.1, 0.5}; + configurations.SetInitialTheta(initial_theta); + + + auto hardware = ExaGeoStatHardware(EXACT_DENSE, configurations.GetCoresNumber(), configurations.GetGPUsNumbers()); + std::unique_ptr> data = std::make_unique>( + configurations.GetProblemSize(), configurations.GetDimension()); + + auto *z_matrix = new double[N]{-1.272336140360187606, -2.590699695867695773, 0.512142584178685967, + -0.163880452049749520, 0.313503633252489700, -1.474410682226017677, + 0.161705025505231914, 0.623389205185149065, -1.341858445399783495, + -1.054282062428600009, -1.669383221392507943, 0.219170645803740793, + 0.971213790000161170, 0.538973474182433021, -0.752828466476077041, + 0.290822066007430102}; + //creating locations x and y. + auto *location_x = new double[N]{0.193041886015106440, 0.330556191348134576, 0.181612878614480805, + 0.370473792629892440, 0.652140077821011688, 0.806332494087129037, + 0.553322652018005678, 0.800961318379491916, 0.207324330510414295, + 0.347951476310368490, 0.092042420080872822, 0.465445944914930965, + 0.528267338063630132, 0.974792095826657490, 0.552452887769893985, + 0.877592126344701295}; + auto *location_y = new double[N]{0.103883421072709245, 0.135790035858701447, 0.434683756771190977, + 0.400778210116731537, 0.168459601739528508, 0.105195696955825133, + 0.396398870832379624, 0.296757457846952011, 0.564507515068284116, + 0.627679865720607300, 0.928648813611047563, 0.958236057068741931, + 0.573571374074921758, 0.568657969024185528, 0.935835812924391552, + 0.942824444953078489}; + + data->GetLocations()->SetLocationX(*location_x, N); + data->GetLocations()->SetLocationY(*location_y, N); + + SECTION("Test Prediction - MSPE ") + { + configurations.SetIsIDW(false); + configurations.SetIsMLOEMMOM(false); + configurations.SetIsFisher(false); + configurations.SetIsMSPE(true); + + vector estimated_theta{0.9, 0.09, 0.4}; + configurations.SetEstimatedTheta(estimated_theta); + + // Register and create a kernel object + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + + // Add the data prediction arguments. + configurations.InitializeDataPredictionArguments(); + Prediction::PredictMissingData(data, configurations, z_matrix, *pKernel); + + REQUIRE(Results::GetInstance()->GetMSPEError() == Catch::Approx(0.552448)); + delete pKernel; + }SECTION("Test Prediction - IDW ") { + configurations.SetIsMLOEMMOM(false); + configurations.SetIsFisher(false); + configurations.SetIsMSPE(false); + configurations.SetIsIDW(true); + + vector estimated_theta{0.9, 0.09, 0.4}; + configurations.SetEstimatedTheta(estimated_theta); + std::vector idw_error = {1.18856255, 1.25725881, 1.11986628}; + + // Register and create a kernel object + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + // Add the data prediction arguments. + configurations.InitializeDataPredictionArguments(); + Prediction::PredictMissingData(data, configurations, z_matrix, *pKernel); + for (int i = 0; i < 3; i++) { + REQUIRE(Results::GetInstance()->GetIDWError()[i] == Catch::Approx(idw_error[i])); + } + delete pKernel; + }SECTION("Test Prediction - MLOE_MMOM ") { + configurations.SetIsMSPE(false); + configurations.SetIsIDW(false); + configurations.SetIsMLOEMMOM(true); + configurations.SetIsFisher(false); + + vector estimated_theta{0.9, 0.09, 0.4}; + configurations.SetEstimatedTheta(estimated_theta); + + // Register and create a kernel object + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + // Add the data prediction arguments. + configurations.InitializeDataPredictionArguments(); + Prediction::PredictMissingData(data, configurations, z_matrix, *pKernel); + REQUIRE(Results::GetInstance()->GetMLOE() == Catch::Approx(0.004467).margin(0.001)); + REQUIRE(Results::GetInstance()->GetMMOM() == Catch::Approx(-0.0812376).margin(0.001)); + delete pKernel; + }SECTION("Test Prediction - MLOE_MMOM with equal estimated theta") { + configurations.SetIsMSPE(false); + configurations.SetIsIDW(false); + configurations.SetIsMLOEMMOM(true); + configurations.SetIsFisher(false); + + vector new_estimated_theta{1, 0.1, 0.5}; + configurations.SetEstimatedTheta(new_estimated_theta); + + // Register and create a kernel object + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + + // Add the data prediction arguments. + configurations.InitializeDataPredictionArguments(); + Prediction::PredictMissingData(data, configurations, z_matrix, *pKernel); + REQUIRE(Results::GetInstance()->GetMLOE() == Catch::Approx(0).margin(0.001)); + REQUIRE(Results::GetInstance()->GetMMOM() == Catch::Approx(0).margin(0.001)); + delete pKernel; + } + + SECTION("Test Prediction - FISHER") { + configurations.SetIsMSPE(false); + configurations.SetIsIDW(false); + configurations.SetIsMLOEMMOM(false); + configurations.SetIsFisher(true); + + vector new_estimated_theta{0.9, 0.09, 0.4}; + configurations.SetEstimatedTheta(new_estimated_theta); + // Register and create a kernel object + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + // Add the data prediction arguments. + configurations.InitializeDataPredictionArguments(); + Prediction::PredictMissingData(data, configurations, z_matrix, *pKernel); + + vector required_fisher = {0.1045891821, 0.0005116817, 0.0409307011, 0.0005116817, 0.1873553354, + -1.3659618079, 0.0409307011, -1.3659618079, 10.5564826575}; + for (int i = 0; i < Results::GetInstance()->GetFisherMatrix().size(); i++) { + double diff = required_fisher[i] - Results::GetInstance()->GetFisherMatrix()[i]; + REQUIRE(diff == Catch::Approx(0.0).margin(1e-6)); + } + delete pKernel; + }SECTION("Test Prediction - Exception") { + vector new_estimated_theta{-1, -1, -1}; + configurations.SetEstimatedTheta(new_estimated_theta); + Prediction predictor; + // Register and create a kernel object + configurations.SetIsMLOEMMOM(true); + exageostat::kernels::Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create( + configurations.GetKernelName(), + configurations.GetTimeSlot()); + REQUIRE_THROWS(predictor.PredictMissingData(data, configurations, z_matrix, *pKernel)); + delete pKernel; + } + delete[] location_x; + delete[] location_y; + delete[] z_matrix; +} + +TEST_CASE("Test Predictions") { + TEST_PREDICTION_MISSING_DATA(); +} \ No newline at end of file diff --git a/tests/cpp-tests/helpers/TestPredictionHelpers.cpp b/tests/cpp-tests/prediction/TestPredictionHelpers.cpp similarity index 98% rename from tests/cpp-tests/helpers/TestPredictionHelpers.cpp rename to tests/cpp-tests/prediction/TestPredictionHelpers.cpp index b69b45fe..b16c9f6d 100644 --- a/tests/cpp-tests/helpers/TestPredictionHelpers.cpp +++ b/tests/cpp-tests/prediction/TestPredictionHelpers.cpp @@ -1,13 +1,13 @@ -// Copyright (c) 2017-2023 King Abdullah University of Science and Technology, +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, // All rights reserved. // ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). /** - * @file TestPrediction.cpp + * @file TestPredictionHelpers.cpp * @brief Unit tests for the TestPrediction class in the ExaGeoStat software package. * @details This file contains Catch2 unit tests that validate the functionality of the TestPrediction class - * @version 1.0.0 + * @version 1.1.0 * @author Mahmoud ElKarargy * @date 2023-12-08 **/ @@ -243,7 +243,7 @@ void TEST_SORT_HELPER_FUNCTION() { } } -TEST_CASE("Prediction tests") { +TEST_CASE("Test Prediction Helpers") { TEST_SHUFFLE_HELPER_FUNCTIONS(); TEST_SORT_HELPER_FUNCTION(); diff --git a/tests/cpp-tests/results/CMakeLists.txt b/tests/cpp-tests/results/CMakeLists.txt new file mode 100644 index 00000000..03659365 --- /dev/null +++ b/tests/cpp-tests/results/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2024-01-24 + +set(EXAGEOSTAT_TESTFILES + ${CMAKE_CURRENT_SOURCE_DIR}/TestResults.cpp + ${EXAGEOSTAT_TESTFILES} + PARENT_SCOPE + ) diff --git a/tests/cpp-tests/results/TestResults.cpp b/tests/cpp-tests/results/TestResults.cpp new file mode 100644 index 00000000..a5693222 --- /dev/null +++ b/tests/cpp-tests/results/TestResults.cpp @@ -0,0 +1,60 @@ +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestResults.cpp + * @brief Unit tests for the Results class in the ExaGeoStat software package. + * @details This file contains Catch2 unit tests that validate the functionality of the Results class + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2024-01-24 +**/ + +#include + +#include + +using namespace exageostat::results; + +void TEST_SINGLETON_RESULTS() { + //Test singleton instance of results + auto results1 = Results::GetInstance(); + auto results2 = Results::GetInstance(); + REQUIRE(results1 == results2); +} + +void TEST_SETTERS_AND_GETTERS() { + + auto results_instacne = Results::GetInstance(); + + SECTION("Total Modeling Execution Time Setter/Getter") { + results_instacne->SetTotalModelingExecutionTime(1.0); + REQUIRE(results_instacne->GetTotalModelingExecutionTime() == 1.0); + + }SECTION("Total Modeling Flops Setter/Getter") { + results_instacne->SetTotalModelingFlops(1.0); + REQUIRE(results_instacne->GetTotalModelingFlops() == 1.0); + + }SECTION("Avg Modeling Execution Time Setter/Getter") { + results_instacne->SetMLEIterations(0); + REQUIRE_THROWS(results_instacne->GetAverageModelingExecutionTime()); + + results_instacne->SetMLEIterations(2); + results_instacne->SetTotalModelingExecutionTime(4.0); + REQUIRE(results_instacne->GetAverageModelingExecutionTime() == 2.0); + + }SECTION("Avg Modeling Flops Setter/Getter") { + results_instacne->SetMLEIterations(0); + REQUIRE_THROWS(results_instacne->GetAverageModelingFlops()); + + results_instacne->SetMLEIterations(2); + results_instacne->SetTotalModelingFlops(4.0); + REQUIRE(results_instacne->GetAverageModelingFlops() == 2.0); + } +} + +TEST_CASE("Test Results") { + TEST_SINGLETON_RESULTS(); + TEST_SETTERS_AND_GETTERS(); +} diff --git a/tests/heavy-tests/CMakeLists.txt b/tests/heavy-tests/CMakeLists.txt new file mode 100644 index 00000000..2764f22b --- /dev/null +++ b/tests/heavy-tests/CMakeLists.txt @@ -0,0 +1,14 @@ + +# Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +# All rights reserved. +# ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +# @file CMakeLists.txt +# @version 1.1.0 +# @author Mahmoud ElKarargy +# @date 2023-12-20 + +enable_testing() +add_executable(exageostat-heavy-tests ${CMAKE_CURRENT_SOURCE_DIR}/HeavyTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ExamplesTests.cpp) +target_link_libraries(exageostat-heavy-tests Catch2::Catch2WithMain ${PROJECT_NAME}_INTERFACE) +catch_discover_tests(exageostat-heavy-tests) \ No newline at end of file diff --git a/tests/heavy-tests/ExamplesTests.cpp b/tests/heavy-tests/ExamplesTests.cpp new file mode 100644 index 00000000..1cb91890 --- /dev/null +++ b/tests/heavy-tests/ExamplesTests.cpp @@ -0,0 +1,138 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestExaGeoStatApi.cpp + * @brief Test suite for the ExaGeoStat APIs data generation functionality. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2023-12-26 +**/ + +#include +#include + +#include + +using namespace std; +using namespace std::filesystem; + +using namespace exageostat::dataunits; +using namespace exageostat::api; + +TEST_CASE("EXAMPLES") { + +// Specify the examples path +path currentPath = current_path().parent_path().parent_path() / "examples"; + +SECTION("Configuration"){ +path configurations_example = currentPath / "configurations/Example_Configurations_Setup "; +string arguments_string = "--N=10 --dts=8 --kernel=univariate_matern_stationary"; +cout << "Running Configurations example with arguments: " + arguments_string << endl << +flush; + +std::string fullCommand = std::string(configurations_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +SECTION("Synthetic Data Generation"){ +path synthetic_data_example = currentPath / "data-generators/Example_Synthetic_Data_Generation"; +string arguments_string = "--N=16 --dts=8 --kernel=univariate_matern_stationary --dimension=2d --computation=exact --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1"; +cout << "Running synthetic locations example with arguments: " + arguments_string << endl << +flush; + +std::string fullCommand = std::string(synthetic_data_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +currentPath = currentPath / "end-to-end"; +SECTION("Data Generation Module"){ +path data_generation_example = currentPath / "Example_Data_Generation"; +string arguments_string = "--N=32 --dts=8 --kernel=univariate_matern_stationary --dimension=3D --computation=diagonal_approx --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1"; +cout << "Running Data Generation Module example with arguments: " + arguments_string << endl << +flush; + +std::string fullCommand = std::string(data_generation_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +SECTION("Data Modeling Module"){ +path data_modeling_example = currentPath / "Example_Data_Modeling"; +#ifdef USE_HICMA +string arguments_string = "--N=16 --dts=8 --lts=8 --kernel=univariate_matern_stationary --dimension=2D --computation=tlr --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1 --max_mle_iterations=3 --tolerance=10 --max_rank=500"; +#else +string arguments_string = "--N=16 --dts=8 --kernel=univariate_matern_stationary --computation=exact --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1 --max_mle_iterations=3 --tolerance=10"; +#endif +cout << "Running Data Modeling example with arguments: " + arguments_string << endl << +flush; +std::string fullCommand = std::string(data_modeling_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +SECTION("Data Prediction Module"){ +path data_prediction_example = currentPath / "Example_Data_Prediction"; + +string arguments_string = "--N=16 --dts=8 --kernel=univariate_matern_stationary --computation=exact --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1 --Zmiss=10 --mspe --fisher --mloe_mmom --etheta=1.1:0.1:0.5"; +cout << "Running Data Prediction example with arguments: " + arguments_string << endl << +flush; + +std::string fullCommand = std::string(data_prediction_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +SECTION("Data Generation and Modeling"){ +path data_generation_modeling_example = currentPath / "Example_Data_Generation_and_Modeling"; + +string arguments_string = "--N=16 --dts=8 --kernel=univariate_matern_stationary --computation=exact --itheta=1:0.1:0.5 --ub=5:5:5 --lb=0.1:0.1:0.1 --max_mle_iterations=2 --tolerance=4 --etheta=1.1:?:0.5"; +cout << "Running Data data generation and modeling example with arguments: " + arguments_string << endl << +flush; + +std::string fullCommand = std::string(data_generation_modeling_example) + " " + arguments_string; +if ( +std::system(fullCommand +. + +c_str() + +)) { +throw runtime_error("This test failed " + fullCommand); +} +} +} diff --git a/tests/heavy-tests/HeavyTests.cpp b/tests/heavy-tests/HeavyTests.cpp new file mode 100644 index 00000000..61316f7a --- /dev/null +++ b/tests/heavy-tests/HeavyTests.cpp @@ -0,0 +1,254 @@ + +// Copyright (c) 2017-2024 King Abdullah University of Science and Technology, +// All rights reserved. +// ExaGeoStat is a software package, provided by King Abdullah University of Science and Technology (KAUST). + +/** + * @file TestExaGeoStatApi.cpp + * @brief Test suite for the ExaGeoStat APIs data generation functionality. + * @version 1.1.0 + * @author Mahmoud ElKarargy + * @date 2023-12-20 +**/ + +#include +#include + +#ifdef USE_CUDA +#include +#endif + +#include + +#include + +using namespace std; + +using namespace exageostat::kernels; + +void GenerateCommandLineArguments(const string &aKernelName, const string &aComputation, vector &aDimensions, + const string &aPrecision, vector &arguments_vector, + const string &aDistanceType) { + + // Search for the substring "TimeSpace" in the kernel name, As ST dimension only works with kernels having Spacetime in their name. + // This is a required convention described in the user manual + size_t found = aKernelName.find("Spacetime"); + // Check if the substring was found + if (found != std::string::npos) { + aDimensions = {"ST"}; + } else { + aDimensions = {"2D", "3D"}; + } + + // Set up a random number generator + random_device rd; + mt19937 gen(rd()); + int LOWER_SIZE = 6; + int MAX_SIZE = 25; + int MAX_LTS = 18; + int lts = INT16_MAX; + uniform_int_distribution problem_size_distribution(LOWER_SIZE, MAX_SIZE); + int max_threads_size = static_cast(std::thread::hardware_concurrency()); + uniform_int_distribution cpu_size_distribution(1, max_threads_size - 5); + uniform_int_distribution max_iteration_distribution(1, 4); + uniform_int_distribution band_distribution(1, 6); + uniform_int_distribution tolerance_distribution(1, 5); + uniform_int_distribution max_rank_distribution(200, 600); + uniform_int_distribution seed_distribution(0, 3); + + int N_value = problem_size_distribution(gen); + + if (aComputation == "tlr") { + uniform_int_distribution lts_distribution(LOWER_SIZE, MAX_LTS); + lts = lts_distribution(gen); + N_value = lts * lts; + if (aKernelName.find("Bivariate") != string::npos || aKernelName.find("Trivariate") != string::npos) { + lts = 18; + } + arguments_vector.push_back("--lts=" + to_string(lts)); + } + + // tile size need to be smaller than N or lts in case of HiCMA. + uniform_int_distribution dts_distribution(LOWER_SIZE, min(N_value, lts)); + int dts = dts_distribution(gen); + + // Since both Bivariate and Trivariate requires specific values. + if (aKernelName.find("Bivariate") != string::npos || aKernelName.find("Trivariate") != string::npos) { + dts = 18; + N_value = 162; + } + if (aKernelName.find("Trivariate") != string::npos) { + N_value = 108; + } + arguments_vector.push_back("--dts=" + to_string(dts)); + arguments_vector.push_back("--N=" + to_string(N_value)); + + uniform_int_distribution zMiss_distribution(2, min(N_value / 2, 100)); + // Create a kernel object to get the number of parameters for each kernel. + Kernel *pKernel = exageostat::plugins::PluginRegistry>::Create(aKernelName, 1); + int param_number = pKernel->GetParametersNumbers(); + delete pKernel; + + string initial_theta_arguments, lb_arguments, ub_arguments; + int zmiss; + zmiss = zMiss_distribution(gen); + if (aKernelName.find("Bivariate") != string::npos) { + do { + zmiss = zMiss_distribution(gen); + } while (zmiss % 2 != 0); + } + + if (aKernelName == "BivariateMaternFlexible") { + initial_theta_arguments = "0.3:0.6:0.01:0.3:0.9:0.9:0.05:0.3:1.5:0.9:0.99"; + lb_arguments = "0.01:0.01:0.01:0.01:0.01:0.01:0.01:0.01:0.01:0.01:0.01"; + ub_arguments = "50:50:50:50:50:50:50:50:50:50:50"; + } else if (aKernelName == "BivariateMaternParsimonious") { + initial_theta_arguments = "1:1:0.1:0.5:0.5:0.1"; + lb_arguments = "0.1:0.1:0.1:0.1:0.1:0.1"; + ub_arguments = "5:5:5:5:5:5"; + } else if (aKernelName == "BivariateSpacetimeMaternStationary" || aKernelName == "TrivariateMaternParsimonious") { + initial_theta_arguments = "1:1:0.1:0.5:0.5:0.1:0:0:0:0"; + lb_arguments = "0.1:0.1:0.1:0.1:0.1:0.1:0.1:0.1:0.1:0.1"; + ub_arguments = "5:5:5:5:5:5:5:5:5:5"; + } else { + uniform_real_distribution initial_theta_distribution(0.01, 2); + // Upper bond need to be larger than the initial theta + uniform_real_distribution ub_distribution(2, 5); + + for (int n = 0; n < param_number; n++) { + double initial_theta_value = initial_theta_distribution(gen); + initial_theta_arguments += to_string(initial_theta_value); + double lb_temp; + do { + lb_temp = initial_theta_distribution(gen); + } while (lb_temp >= initial_theta_value); + lb_arguments += to_string(lb_temp); + ub_arguments += to_string(ub_distribution(gen)); + if (n < param_number - 1) { + initial_theta_arguments += ":"; + ub_arguments += ":"; + lb_arguments += ":"; + } + } + } + + arguments_vector.push_back("--cores=" + to_string(cpu_size_distribution(gen))); +#ifdef USE_CUDA + int nDevices; + cudaGetDeviceCount(&nDevices); + uniform_int_distribution gpu_size_distribution(0, nDevices - 1); + arguments_vector.push_back("--gpus=" + to_string(gpu_size_distribution(gen))); +#endif + + arguments_vector.push_back("--kernel=" + aKernelName); + arguments_vector.push_back("--computation=" + aComputation); + arguments_vector.push_back("--precision=" + aPrecision); + arguments_vector.push_back("--initial_theta=" + initial_theta_arguments); + arguments_vector.push_back("--ub=" + ub_arguments); + arguments_vector.push_back("--lb=" + lb_arguments); + arguments_vector.push_back("--max_mle_iterations=" + to_string(max_iteration_distribution(gen))); + arguments_vector.push_back("--tolerance=" + to_string(tolerance_distribution(gen))); + arguments_vector.push_back("--max_rank=" + to_string(max_rank_distribution(gen))); + arguments_vector.push_back("--band=" + to_string(band_distribution(gen))); + arguments_vector.push_back("--ZMiss=" + to_string(zmiss)); + arguments_vector.push_back("--seed=" + to_string(seed_distribution(gen))); + arguments_vector.emplace_back("--idw"); + arguments_vector.emplace_back("--distance_metric=" + aDistanceType); + if (aKernelName.find("Bivariate") == string::npos && aKernelName.find("Trivariate") == string::npos) { + arguments_vector.emplace_back("--fisher"); + } + if (aKernelName.find("Trivariate") == string::npos) { + arguments_vector.emplace_back("--mspe"); + arguments_vector.emplace_back("--mloe-mmom"); + } +} + +TEST_CASE("END-TO-END") { + + // Add all the possible combination of code. + vector kernels_vector = { + "BivariateMaternFlexible", + "UnivariateMaternStationary", + "BivariateMaternParsimonious", + "BivariateSpacetimeMaternStationary", + "TrivariateMaternParsimonious", + "UnivariateExpNonGaussian", + "UnivariateMaternNonGaussian", + "UnivariateMaternNuggetsStationary", + "UnivariateSpacetimeMaternStationary" + }; + + vector computation_vector = {"exact", "diag_approx"}; +#ifdef USE_HICMA + computation_vector.emplace_back("tlr"); +#endif + vector dimensions_vector; + vector precision_vector = {"single", "double"}; + vector distance_vector = {"eg", "gcd"}; + + size_t combination_number = 1; + size_t number_of_iterations = 1; + for (int i = 0; i < number_of_iterations; i++) { + cout << "**** END-TO_END TESTS -- ITERATION NUMBER (" << i + 1 << ") ****" << endl; + + // Generate combinations. + for (const auto ¤t_kernel: kernels_vector) { + for (const auto &computation: computation_vector) { + for (const auto &precision: precision_vector) { + for (const auto &distance_type: distance_vector) { + + vector arguments_vector; + // This helper function will fill the arguments vector with the software arguments commands + GenerateCommandLineArguments(current_kernel, computation, dimensions_vector, precision, + arguments_vector, distance_type); + // Generate combination of dimensions. + for (const auto &dimension: dimensions_vector) { + // Add the dimension into the arguments vector + arguments_vector.push_back("--dimension=" + dimension); + + // Great Circle (GC) distance is only valid for 2D! + if (distance_type == "gcd" && (dimension == "3D" || dimension == "ST")) { + continue; + } + if (dimension == "ST" && computation == "tlr") { + continue; + } + if (dimension == "ST") { + random_device rd; + mt19937 gen(rd()); + uniform_int_distribution time_slot_distribution(1, 5); + arguments_vector.push_back("--time_slot=" + to_string(time_slot_distribution(gen))); + } + + string arguments_string; + for (const auto &j: arguments_vector) { + arguments_string += " " + j; + } + + cout << "(" << combination_number + << ") Testing the software with arguments: " + arguments_string << endl << flush; + + // Specify the executable path as the first argument + std::filesystem::path currentPath = + std::filesystem::current_path().parent_path().parent_path() / + "examples/end-to-end/Example_Data_Generation_Modeling_and_Prediction"; + std::string fullCommand = std::string(currentPath) + arguments_string; + if (std::system(fullCommand.c_str())) { + throw runtime_error("This test failed " + fullCommand); + } + // To remove the previous dimension. + arguments_vector.pop_back(); + + if (dimension == "ST") { + // To remove the time slot. + arguments_vector.pop_back(); + } + combination_number += 1; + } + } + } + } + } + } +} + diff --git a/tests/heavy-tests/README.md b/tests/heavy-tests/README.md new file mode 100644 index 00000000..aca3623a --- /dev/null +++ b/tests/heavy-tests/README.md @@ -0,0 +1,3 @@ +# Heavy Tests Subdirectory + +This directory includes all the heavy tests for the project. It executes all project testing examples using a different set of configurations to guarantee the seamless functionality of every test. \ No newline at end of file