本文整理汇总了C++中policy_type类的典型用法代码示例。如果您正苦于以下问题:C++ policy_type类的具体用法?C++ policy_type怎么用?C++ policy_type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了policy_type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
KOKKOS_INLINE_FUNCTION
void operator()( typename policy_type::member_type & )
{
enum { CHUNK = 8 };
const int n = CHUNK < m_count ? CHUNK : m_count ;
if ( 1 < m_count ) {
future_type f[ CHUNK ] ;
const int inc = ( m_count + n - 1 ) / n ;
for ( int i = 0 ; i < n ; ++i ) {
long begin = i * inc ;
long count = begin + inc < m_count ? inc : m_count - begin ;
f[i] = m_policy.task_spawn( TestTaskDependence(count,m_policy,m_accum) , Kokkos::TaskSingle );
}
m_count = 0 ;
m_policy.respawn( this , m_policy.when_all( n , f ) );
}
else if ( 1 == m_count ) {
Kokkos::atomic_increment( & m_accum() );
}
}
示例2: create
static KOKKOS_INLINE_FUNCTION
future_type create(policy_type &policy, const TaskFunctorType &func) {
future_type f ;
// while ( f.is_null() ) {
f = policy.task_create_team(func, _max_task_dependence);
// }
if ( f.is_null() ) Kokkos::abort("task_create_team FAILED, out of memory");
return f ;
}
示例3: runtime_error
typename std::enable_if< ! std::is_same<policy_type,PRIORITY_POLICY>::value, std::future<typename std::result_of<F(Args...)>::type> >::type
enqueue(F&& f, Args&&... args){
typedef typename std::result_of<F(Args...)>::type return_type;
// Don't allow enqueueing after stopping the pool
if ( ! isActive.load() )
throw std::runtime_error("enqueue on stopped ThreadPool");
auto task = std::make_shared<std::packaged_task<return_type()>>(
std::bind(std::forward<F>(f), std::forward<Args>(args)...) );
std::future<return_type> result = task->get_future();
{
std::unique_lock<std::mutex> lock(queue_mutex);
mTasks.push([task](){ (*task)(); });
}
condition.notify_one();
return result;
}
示例4: addDependence
static
void addDependence(policy_type &policy,
TaskFunctorType *after, const future_type &before) {
policy.add_dependence(after, before);
}
示例5: clearDependence
static KOKKOS_INLINE_FUNCTION
void clearDependence(policy_type &policy, TaskFunctorType *func) {
policy.clear_dependence(func);
}
示例6: respawn
static
void respawn(policy_type &policy, TaskFunctorType *func) {
policy.respawn(func);
}
示例7: clearDependence
static
void clearDependence(policy_type &policy, TaskFunctorType *func) {
policy.clear_dependence(func);
}
示例8: spawn
static
void spawn(policy_type &policy, const future_type &obj) {
policy.spawn(obj);
}
示例9: create
static
future_type create(policy_type &policy, const TaskFunctorType &func) {
return (_use_team_interface ?
policy.create_team(func, _max_task_dependence) :
policy.create (func, _max_task_dependence));
}
示例10: addDependence
static
void addDependence(policy_type &policy,
const future_type &after, const future_type &before) {
policy.add_dependence(after, before);
}
示例11: respawn
static KOKKOS_INLINE_FUNCTION
void respawn(policy_type &policy, TaskFunctorType *func) {
policy.respawn(func);
}
示例12: exception_invalid_key
/*!
* \brief Access cache data
*
* Accessor to the data (values) stored in cache. If the specified key exists in the cache, it's usage count will be touched and reference to the element is returned.
* The data object itself is kept in the cache, so the reference will be valid until it is removed (either manually or due to cache overflow) or cache object destroyed.
*
* \param <_k> key to the data
*
* \throw <exception_invalid_key> Thrown when non-existent key is supplied. You could use \link cache::check check member \endlink or \link cache::count count member \endlink to check cache existence prior to fetching the data
*
* \return constand reference to the data, mapped by the key. of type Data of course.
*
* \see check
*/
const Data& fetch(const Key& _k) {
if (!this->_check(_k)) {
throw exception_invalid_key("Key is not in cache",_k);
}
_policy->touch(_k);
return (*(_storage.find(_k))).second;
}
示例13: get
/*!
* \brief Safe cache data access
*
* Accessor to the data (values) stored in cache. If the specified key exists in the cache, it's usage count will be touched
* and reference to the element, wrapped to boost::optional is returned. For non-exsitent key empty boost::optional container is returned
* The data object itself is kept in the cache, so the reference will be valid until it is removed (either manually or due to cache overflow) or cache object destroyed.
*
* This function is only available if USE_BOOST_OPTIONAL macro is defined
*
* \param <_k> key to the data
*
* \return constant boost::optional wrapper, holding constant reference to the data, in case when key were in the cache,
* or empty constant boost::optional wrapper for non-existent key.
*
* \see check, fetch
*/
const boost::optional<const Data&> get(const Key& _k) throw() {
write_lock_type l = lock.lockWrite();
if (!this->_check(_k)) {
return boost::optional<const Data&>();
}
_policy->touch(_k);
return boost::optional<const Data&>((*(_storage.find(_k))).second);
}
示例14: _erase
size_type _erase ( const key_type& x ) throw() {
size_type ret=_storage.erase(x);
_policy->remove(x);
_currEntries-=ret;
return ret;
}
示例15: insert
/*!
* \brief Insert element to the cache
*
* The cache is extended by inserting a single new element. This effectively increases the cache size. Because cache do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way.
* Extension of cache could result in removal of some elements, depending of the cache fullness and used policy. It is also possible, that removal of excessive entries
* will fail, therefore insert operation will fail too.
*
* \throw <exception_cache_full> Thrown when there are no available space in the cache and policy doesn't allows removal of elements.
* \throw <exception_invalid_key> Thrown when the policy doesn't accepts the key
*
* \return true if the new elemented was inserted or false if an element with the same key existed.
*/
bool insert(Key _k, Data _d) {
write_lock_type l = lock.lockWrite();
while (this->_currEntries >= this->_maxEntries) {
_victim<Key> victim=_policy->victim();
if (!victim) {
throw exception_cache_full("The cache is full and no element can be expired at the moment. Remove some elements manually");
}
this->_erase(*victim);
}
_policy->insert(_k);
bool result=_storage.insert(value_type(_k,_d)).second;
if (result) {
_currEntries++;
}
return result;
}