Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/pstl/internal/parallel_impl.h
// -*- C++ -*- | // -*- C++ -*- | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef _PSTL_PARALLEL_IMPL_H | #ifndef _PSTL_PARALLEL_IMPL_H | ||||
#define _PSTL_PARALLEL_IMPL_H | #define _PSTL_PARALLEL_IMPL_H | ||||
#include "pstl_config.h" | #include "pstl_config.h" | ||||
#include <atomic> | #include <atomic> | ||||
#include <pstl/internal/parallel_backend.h> | |||||
// This header defines the minimum set of parallel routines required to support Parallel STL, | // This header defines the minimum set of parallel routines required to support Parallel STL, | ||||
// implemented on top of Intel(R) Threading Building Blocks (Intel(R) TBB) library | // implemented on top of Intel(R) Threading Building Blocks (Intel(R) TBB) library | ||||
_PSTL_HIDE_FROM_ABI_PUSH | _PSTL_HIDE_FROM_ABI_PUSH | ||||
namespace __pstl | namespace __pstl | ||||
{ | { | ||||
namespace __internal | namespace __internal | ||||
Show All 36 Lines | __par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, | ||||
}); | }); | ||||
return __extremum != __initial_dist ? __first + __extremum : __last; | return __extremum != __initial_dist ? __first + __extremum : __last; | ||||
} | } | ||||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | ||||
// parallel_or | // parallel_or | ||||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | ||||
//! Return true if brick f[i,j) returns true for some subrange [i,j) of [first,last) | //! Return true if brick f[i,j) returns true for some subrange [i,j) of [first,last) | ||||
template <class _BackendTag, class _ExecutionPolicy, class _Index, class _Brick> | template <class _BackendTag = __par_backend_tag, class _ExecutionPolicy, class _Index, class _Brick> | ||||
bool | bool __parallel_or(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f) { | ||||
__parallel_or(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f) | |||||
{ | |||||
std::atomic<bool> __found(false); | std::atomic<bool> __found(false); | ||||
__par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, | __par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, | ||||
[__f, &__found](_Index __i, _Index __j) | [__f, &__found](_Index __i, _Index __j) | ||||
{ | { | ||||
if (!__found.load(std::memory_order_relaxed) && __f(__i, __j)) | if (!__found.load(std::memory_order_relaxed) && __f(__i, __j)) | ||||
{ | { | ||||
__found.store(true, std::memory_order_relaxed); | __found.store(true, std::memory_order_relaxed); | ||||
__par_backend::__cancel_execution(); | __par_backend::__cancel_execution(); | ||||
Show All 11 Lines |