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

Remove dependency on parallel stl algorithms #10

Open
wants to merge 1 commit 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
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ set_property(GLOBAL PROPERTY USE_FOLDERS on)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (UNIX)
find_package(OpenMP)
find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
if (CMAKE_VERSION VERSION_GREATER "3.8")
link_libraries(OpenMP::OpenMP_CXX)
else()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
endif(OPENMP_FOUND)
endif (UNIX)

OPTION(BUILD_AS_SHARED_LIBS "Build all the libraries as shared" OFF)
if (BUILD_AS_SHARED_LIBS)
Expand Down Expand Up @@ -49,11 +47,6 @@ endif ()

target_include_directories(CompactNSearch PUBLIC include)

if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
find_package(oneDPL REQUIRED)
target_link_libraries(CompactNSearch PUBLIC oneDPL)
endif()

install(FILES "include/CompactNSearch" ${HEADER_FILES}
DESTINATION include/)

Expand Down
13 changes: 4 additions & 9 deletions demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <limits>
#include <chrono>
#include <random>
#include <algorithm>

#include <omp.h>

Expand Down Expand Up @@ -151,21 +152,15 @@ enright_velocity_field(std::array<Real, 3> const& x)
void
advect()
{
#ifdef _MSC_VER
concurrency::parallel_for_each(
#elif defined(__APPLE__) && defined(__clang__)
std::for_each(oneapi::dpl::execution::par,
#else
__gnu_parallel::for_each(
#endif
positions.begin(), positions.end(), [&](std::array<Real, 3>& x)
#pragma omp parallel for
for (int _i = 0; _i < positions.size(); _i++)
{
std::array<Real, 3>& x = positions[_i];
std::array<Real, 3> v = enright_velocity_field(x);
x[0] += static_cast<Real>(0.005) * v[0];
x[1] += static_cast<Real>(0.005) * v[1];
x[2] += static_cast<Real>(0.005) * v[1];
}
);
}

int main(int argc, char* argv[])
Expand Down
9 changes: 0 additions & 9 deletions include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ namespace CompactNSearch

#define INITIAL_NUMBER_OF_INDICES 50
#define INITIAL_NUMBER_OF_NEIGHBORS 50

#ifdef _MSC_VER
#include <ppl.h>
#elif defined(__APPLE__) && defined(__clang__)
#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#else
#include <parallel/algorithm>
#endif
61 changes: 18 additions & 43 deletions src/CompactNSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,9 @@ NeighborhoodSearch::update_point_sets()
}

// Precompute cell indices.
#ifdef _MSC_VER
concurrency::parallel_for_each(
#elif defined(__APPLE__) && defined(__clang__)
std::for_each(oneapi::dpl::execution::par,
#else
__gnu_parallel::for_each(
#endif
m_point_sets.begin(), m_point_sets.end(), [&](PointSet& d)
{
#pragma omp parallel for
for (int j = 0; j < m_point_sets.size(); j++){
PointSet& d = m_point_sets[j];
if (d.is_dynamic())
{
d.m_keys.swap(d.m_old_keys);
Expand All @@ -251,7 +245,7 @@ NeighborhoodSearch::update_point_sets()
d.m_keys[i] = cell_index(d.point(i));
}
}
});
}

std::vector<unsigned int> to_delete;
if (m_erase_empty_cells)
Expand Down Expand Up @@ -315,15 +309,9 @@ NeighborhoodSearch::erase_empty_entries(std::vector<unsigned int> const& to_dele
});

// Perform neighborhood search.
#ifdef _MSC_VER
concurrency::parallel_for_each(
#elif defined(__APPLE__) && defined(__clang__)
std::for_each(oneapi::dpl::execution::par,
#else
__gnu_parallel::for_each(
#endif
kvps.begin(), kvps.end(), [&](std::pair<HashKey const, unsigned int>* kvp_)
{
#pragma omp parallel for
for (int j =0; j < kvps.size(); j++){
std::pair<HashKey const, unsigned int>* kvp_ = kvps[j];
auto& kvp = *kvp_;

for (unsigned int i = 0; i < to_delete.size(); ++i)
Expand All @@ -334,7 +322,7 @@ NeighborhoodSearch::erase_empty_entries(std::vector<unsigned int> const& to_dele
break;
}
}
});
}
}

void
Expand Down Expand Up @@ -415,22 +403,16 @@ NeighborhoodSearch::query()
});

// Perform neighborhood search.
#ifdef _MSC_VER
concurrency::parallel_for_each(
#elif defined(__APPLE__) && defined(__clang__)
std::for_each(oneapi::dpl::execution::par,
#else
__gnu_parallel::for_each(
#endif
kvps.begin(), kvps.end(), [&](std::pair<HashKey const, unsigned int> const* kvp_)
{
#pragma omp parallel for
for (int _i = 0; _i < kvps.size(); _i++){
std::pair<HashKey const, unsigned int> const* kvp_ = kvps[_i];
auto const& kvp = *kvp_;
HashEntry const& entry = m_entries[kvp.second];
HashKey const& key = kvp.first;

if (entry.n_searching_points == 0u)
{
return;
continue;
}

for (unsigned int a = 0; a < entry.n_indices(); ++a)
Expand Down Expand Up @@ -471,26 +453,20 @@ NeighborhoodSearch::query()
}
}
}
);


std::vector<std::array<bool, 27>> visited(m_entries.size(), {false});
std::vector<Spinlock> entry_locks(m_entries.size());

#ifdef _MSC_VER
concurrency::parallel_for_each(
#elif defined(__APPLE__) && defined(__clang__)
std::for_each(oneapi::dpl::execution::par,
#else
__gnu_parallel::for_each(
#endif
kvps.begin(), kvps.end(), [&](std::pair<HashKey const, unsigned int> const* kvp_)
{
#pragma omp parallel for
for (int _i = 0; _i < kvps.size(); _i++){
std::pair<HashKey const, unsigned int> const* kvp_ = kvps[_i];

auto const& kvp = *kvp_;
HashEntry const& entry = m_entries[kvp.second];

if (entry.n_searching_points == 0u)
return;
continue;
HashKey const& key = kvp.first;

for (int dj = -1; dj <= 1; dj++)
Expand Down Expand Up @@ -579,8 +555,7 @@ NeighborhoodSearch::query()
}
}
}
});

}
}


Expand Down