Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable parallel STL with a macro #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# SPDX-License-Identifier: MIT

# Works with 3.11 and tested through 3.15 (not tested yet)
cmake_minimum_required(VERSION 3.11...3.15)
cmake_minimum_required(VERSION 3.14)


project(CLIPPy
Expand Down Expand Up @@ -39,41 +38,57 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
endif()
endif()


#
# Nlohmann JSON
# Threads
find_package(Threads REQUIRED)

#
include(ExternalProject)
ExternalProject_Add(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.9.1/json.hpp
DOWNLOAD_NO_EXTRACT 1
LOG_DOWNLOAD 1
DOWNLOAD_DIR nlohmann_json/include/nlohmann/
BUILD_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
)
set(NLOHMANN_JSON_INCLUDE_DIR ${PROJECT_BINARY_DIR}/nlohmann_json/include)
# Boost
find_package(Boost 1.75 REQUIRED)

#
# Metall
#set(METALL_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-work)
set(METALL_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-src)
set(METALL_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-build)
set(METALL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/metall-install)
ExternalProject_Add(metall
find_package(Metall QUIET)
if (Metall_FOUND)
message(STATUS "Found Metall")
else ()
message(STATUS "Could NOT find Metall locally. Download Metall.")
include(FetchContent)
FetchContent_Declare(
Metall
GIT_REPOSITORY https://github.com/LLNL/metall.git
GIT_TAG master
SOURCE_DIR ${METALL_SOURCE_DIR}
BINARY_DIR ${METALL_BUILD_DIR}
CMAKE_ARGS -DINSTALL_HEADER_ONLY=ON -DCMAKE_INSTALL_PREFIX=${METALL_INSTALL_DIR}
GIT_TAG develop
)
set(METALL_INCLUDE_DIR ${METALL_INSTALL_DIR}/include)
find_package(Threads REQUIRED)
FetchContent_MakeAvailable(Metall)
endif ()

#
# Boost
find_package(Boost 1.75 REQUIRED COMPONENTS)
# cereal
FetchContent_Declare(cereal
URL https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.0.zip
)
FetchContent_GetProperties(cereal)
if (NOT cereal_POPULATED)
FetchContent_Populate(cereal)
endif ()
set(cereal_INCLUDE_DIR "${cereal_SOURCE_DIR}/include")

#
# MPI
find_package(MPI)

#
# YGM
if (MPI_CXX_FOUND)
FetchContent_Declare(YGM
URL https://github.com/LLNL/ygm/archive/refs/heads/master.zip
)
FetchContent_GetProperties(YGM)
if (NOT ygm_POPULATED)
FetchContent_Populate(YGM)
endif ()
set(YGM_INCLUDE_DIR "${ygm_SOURCE_DIR}/include")
endif ()

### Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
Expand Down
6 changes: 3 additions & 3 deletions examples/dataframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ function ( add_df_example example_name )
target_link_libraries(${example_name} PRIVATE libcliprt)
endfunction()

include_directories(${Boost_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})

add_library(libcliprt STATIC clip)
target_link_libraries(libcliprt PUBLIC ${Boost_LIBRARIES})

add_df_example(columninfo)
add_df_example(metadataquery)
add_df_example(columnquery)
add_df_example(create)
add_df_example(datafind)
add_df_example(extreme)
add_df_example(importCSV)
add_df_example(rowquery)

62 changes: 38 additions & 24 deletions examples/dataframe/clip.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

#include <iostream>
#include <fstream>
#include <sstream>

#include "clip.hpp"

#include <boost/json/src.hpp>

namespace boostjsn = boost::json;


void resultOK(std::ostream& os, const std::string& msg)
{
os << "{\n \"text\": \"OK\"";
Expand Down Expand Up @@ -52,7 +53,7 @@ pretty_print(std::ostream& os, boostjsn::value const& jv, std::string& indent)
os << indent << "}";
break;
}

case boostjsn::kind::array:
{
os << "[\n";
Expand All @@ -75,37 +76,37 @@ pretty_print(std::ostream& os, boostjsn::value const& jv, std::string& indent)
os << indent << "]";
break;
}

case boostjsn::kind::string:
{
os << boostjsn::serialize(jv.get_string());
break;
}

case boostjsn::kind::uint64:
os << jv.get_uint64();
break;

case boostjsn::kind::int64:
os << jv.get_int64();
break;

case boostjsn::kind::double_:
os << jv.get_double();
break;

case boostjsn::kind::bool_:
if(jv.get_bool())
os << "true";
else
os << "false";
break;

case boostjsn::kind::null:
os << "null";
break;
}

if(indent.empty())
os << "\n";
}
Expand All @@ -117,44 +118,44 @@ parseFile(std::istream& inps)
{
boostjsn::stream_parser p;
std::string line;

while (inps >> line)
{
boostjsn::error_code ec;

p.write(line.c_str(), line.size(), ec);

if (ec) return nullptr;
}
}

boostjsn::error_code ec;
p.finish(ec);
if (ec) return nullptr;

return p.release();
}

boostjsn::value
parseFile(const std::string& filename)
{
std::ifstream is{filename};

return parseFile(is);
}

void
prettyPrint(std::ostream& os, const boostjsn::value& jv)
{
std::string indent;

pretty_print(os, jv, indent);
}

void
prettyPrint(const boostjsn::value& jv)
{
std::ofstream os{"jsonin.log"};

prettyPrint(os, jv);
}

Expand All @@ -164,7 +165,7 @@ try
const boostjsn::object& argsobj = args.as_object();
boostjsn::object::const_iterator pos = argsobj.find(key);
if (pos == argsobj.end()) return;

name = pos->value().as_string().c_str();
}
catch (const std::invalid_argument&) {}
Expand All @@ -175,7 +176,7 @@ try
const boostjsn::object& argsobj = args.as_object();
boostjsn::object::const_iterator pos = argsobj.find(key);
if (pos == argsobj.end()) return;

val = pos->value().as_int64();
}
catch (const std::invalid_argument&) {}
Expand All @@ -186,12 +187,25 @@ int columnIndex(const std::vector<std::string>& all, const std::string& colname)
std::vector<std::string>::const_iterator aa = all.begin();
std::vector<std::string>::const_iterator zz = all.end();
std::vector<std::string>::const_iterator pos = std::find(aa, all.end(), colname);
clippy_assert<std::runtime_error>(pos != zz, "Column name not found: " + colname);

clippy_assert(pos != zz, "Column name not found: " + colname);
return std::distance(aa, pos);
}

bool fail(const std::string& msg)
bool fail( const std::string& msg
#if __cpp_lib_source_location
, std::source_location pos = std::source_location::current()
#endif /* __cpp_lib_source_location */
)
{
clippy_assert(false, msg);
std::stringstream errmsg;

errmsg << msg
#if __cpp_lib_source_location
<< " @ " << pos.file_name
<< " : " << pos.line
#endif /* __cpp_lib_source_location */
;

throw std::logic_error{errmsg.str()};
}
26 changes: 13 additions & 13 deletions examples/dataframe/clip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
#include <string>
#include <iosfwd>
#include <memory>
#include <sstream>

#if defined __has_include
#if __has_include (<source_location>)
#include <source_location>
#include <source_location>
#endif
#endif /* defined __has_include */

#include <boost/json.hpp>

#include "experimental/cxx-compat.hpp"

constexpr const bool firstMatch = false;

void resultOK(std::ostream& os, const std::string& msg = {});
Expand All @@ -30,11 +31,15 @@ void setValueIfAvail(const boost::json::value& args, const char* key, int& val);

int columnIndex(const std::vector<std::string>& all, const std::string& colname);

bool fail(const std::string& msg);
CXX_NORETURN
bool fail( const std::string& msg
#if __cpp_lib_source_location
, std::source_location pos = std::source_location::current()
#endif /* __cpp_lib_source_location */
);

namespace
{
template <class EX = std::logic_error>
inline
void clippy_assert( bool cond
, const std::string& msg
Expand All @@ -43,17 +48,12 @@ namespace
#endif /* __cpp_lib_source_location */
)
{
if (cond) return;
if (cond) { CXX_LIKELY; return; }

std::stringstream errmsg;

errmsg << msg
fail( msg
#if __cpp_lib_source_location
<< " @ " << pos.file_name
<< " : " << pos.line
, pos
#endif /* __cpp_lib_source_location */
;

throw EX{errmsg.str()};
);
}
}
Loading