Skip to content

Commit

Permalink
Optional TBB linking (#101)
Browse files Browse the repository at this point in the history
* Changed the TBB linking for GCC STL to be optional with installed system library.
* Added multiple retries when creating the output folder to handle concurrent batches race condition.
  • Loading branch information
israel-vieira authored Jan 27, 2023
1 parent 86398ff commit ab79a1d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
steps:
- name: Tarball url
run: echo "${{ github.server_url }}/${{ github.repository }}/archive/refs/tags/${{ github.ref_name }}.tar.gz"
- name: Create tarball sha256
run: curl -sL "${{ github.server_url }}/${{ github.repository }}/archive/refs/tags/${{ github.ref_name }}.tar.gz" | shasum -a 256 > sha256sum.txt
- name: Create tarball sha256
run: |
curl -O -sL "${{ github.server_url }}/${{ github.repository }}/archive/refs/tags/${{ github.ref_name }}.tar.gz" | sha256sum > sha256sum.txt
sha256sum ${{ github.ref_name }}.tar.gz > sha256sum.txt
- name: Upload sha256sum file
uses: softprops/action-gh-release@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(HealthGPS
VERSION 1.2.1.0
VERSION 1.2.2.0
DESCRIPTION "Global Health Policy Simulation model (Health-GPS)"
HOMEPAGE_URL "/~https://github.com/imperialCHEPI/healthgps"
LANGUAGES CXX)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ To start working on the *Health GPS* code base, the suggested development machin
5. [Microsoft Visual Studio](https://visualstudio.microsoft.com) 2022 or newer with CMake presets integration.
6. [GCC](https://gcc.gnu.org/) 11.1 or newer installed on *Linux* environment, plus.
* [Intel TBB](/~https://github.com/oneapi-src/oneTBB) library version 2018 or later installed (e.g. `sudo apt update && sudo apt install libtbb-dev`)
7. The latest [vcpkg](/~https://github.com/microsoft/vcpkg) installed globally for Visual Studio projects, and the VCPKG_ROOT environment variable set to the installation directory.
7. The latest [vcpkg](/~https://github.com/microsoft/vcpkg) installed globally for Visual Studio projects, and the `VCPKG_ROOT` *environment variable* set to the installation directory.
8. Internet connection.

Download the *Health GPS* source code to the local machine, we recommend somewhere like root `/src` or `/source`, since otherwise you may run into path issues with the build systems.
```cmd
> git clone /~https://github.com/imperialCHEPI/healthgps
```
Finally, open the `.../healthgps` folder in Visual Studio and hit build. The first build takes considerably longer than normal due to the initial work required by CMake and the package manager.
Finally, open the `healthgps` folder in Visual Studio and build. The first build takes considerably longer than normal due to the initial work required by CMake and the package manager.

>**NOTE:** *This is the current toolset being used for developing the HealthGPS model, however CMake is supported by VS Code and many other IDE of choice, e.g. the model is current being compiled and built on Ubuntu Linux 22.04 LTS using only the CMake command line.*
Expand Down
3 changes: 2 additions & 1 deletion src/HealthGPS.Benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ find_package(fmt CONFIG REQUIRED)
find_package(cxxopts CONFIG REQUIRED)
find_package(benchmark CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(TBB QUIET)

add_executable(HealthGPS.Benchmarks "")
target_compile_features(HealthGPS.Tests PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
Expand All @@ -12,7 +13,7 @@ target_sources(HealthGPS.Benchmarks
"string_benchs.h"
"identifier_benchs.h")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(TBB_FOUND AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
target_link_libraries(HealthGPS.Benchmarks
PRIVATE
HealthGPS.Core
Expand Down
4 changes: 3 additions & 1 deletion src/HealthGPS.Console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ find_package(indicators CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_path(RAPIDCSV_INCLUDE_DIRS "rapidcsv.h")
find_package(Threads REQUIRED)
find_package(TBB QUIET)

add_executable(HealthGPS.Console "")
target_compile_features(HealthGPS.Console PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
Expand Down Expand Up @@ -39,7 +40,8 @@ if(WIN32)
target_sources(HealthGPS.Console PRIVATE versioninfo.rc)
endif(WIN32)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "TBB found: ${TBB_FOUND}")
if(TBB_FOUND AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
target_link_libraries(HealthGPS.Console
PRIVATE
HealthGPS.Core
Expand Down
24 changes: 22 additions & 2 deletions src/HealthGPS.Console/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "HealthGPS.Core/scoped_timer.h"

#include <chrono>
#include <thread>
#include <iostream>
#include <optional>
#include <fstream>
Expand Down Expand Up @@ -274,8 +275,8 @@ Configuration load_configuration(CommandOptions& options)
config.output = opt["output"].get<OutputInfo>();
config.output.folder = expand_environment_variables(config.output.folder);
if (!fs::exists(config.output.folder)) {
fmt::print(fg(fmt::color::dark_salmon), "Creating output folder: {}\n", config.output.folder);
if (!fs::create_directories(config.output.folder)) {
fmt::print(fg(fmt::color::dark_salmon), "\nCreating output folder: {} ...\n", config.output.folder);
if (!create_output_folder(config.output.folder)) {
throw std::runtime_error(fmt::format("Failed to create output folder: {}", config.output.folder));
}
}
Expand All @@ -297,6 +298,25 @@ Configuration load_configuration(CommandOptions& options)
return config;
}

bool create_output_folder(std::filesystem::path folder_path, unsigned int num_retries)
{
using namespace std::chrono_literals;
for (unsigned int i = 1; i <= num_retries; i++) {
try {
if (std::filesystem::create_directories(folder_path)) {
return true;
}
}
catch (const std::exception& ex) {
fmt::print(fg(fmt::color::red), "Failed to create output folder, attempt #{} - {}.\n", i, ex.what());
}

std::this_thread::sleep_for(1000ms);
}

return false;
}

std::vector<core::DiseaseInfo> get_diseases(core::Datastore& data_api, Configuration& config)
{
std::vector<core::DiseaseInfo> result;
Expand Down
2 changes: 2 additions & 0 deletions src/HealthGPS.Console/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CommandOptions parse_arguments(cxxopts::Options& options, int& argc, char* argv[

Configuration load_configuration(CommandOptions& options);

bool create_output_folder(std::filesystem::path folder_path, unsigned int num_retries = 3);

std::vector<hgps::core::DiseaseInfo> get_diseases(hgps::core::Datastore& data_api, Configuration& config);

hgps::ModelInput create_model_input(hgps::core::DataTable& input_table, hgps::core::Country country,
Expand Down
3 changes: 2 additions & 1 deletion src/HealthGPS.Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ find_package(fmt CONFIG REQUIRED)
find_package(cxxopts CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(TBB QUIET)

include(CTest)
include(GoogleTest)
Expand Down Expand Up @@ -40,7 +41,7 @@ target_sources(HealthGPS.Tests
"CountryModule.h"
"RiskFactorData.h")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(TBB_FOUND AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
target_link_libraries(HealthGPS.Tests
PRIVATE
HealthGPS.Core
Expand Down

0 comments on commit ab79a1d

Please sign in to comment.