Ejemplo n.º 1
0
/*
 * Use atomic compare-and-swap to update val to
 * val + inc.  Update occurs in a loop in case other
 * threads update in the meantime.
 */
inline void incLoop(tbb::atomic<double>& val, double inc) {
        double oldMass = val.load();
        double returnedMass = oldMass;
        double newMass{oldMass + inc};
        do {
            oldMass = returnedMass;
            newMass = oldMass + inc;
            returnedMass = val.compare_and_swap(newMass, oldMass);
        } while (returnedMass != oldMass);
}
Ejemplo n.º 2
0
/*
 * Use atomic compare-and-swap to update val to
 * val + inc (*in log-space*).  Update occurs in a loop in case other
 * threads update in the meantime.
 */
inline void incLoopLog(tbb::atomic<double>& val, double inc) {
	double oldMass = val.load();
	double returnedMass = oldMass;
	double newMass{salmon::math::LOG_0};
	do {
	  oldMass = returnedMass;
 	  newMass = salmon::math::logAdd(oldMass, inc);
	  returnedMass = val.compare_and_swap(newMass, oldMass);
	} while (returnedMass != oldMass);
}
inline void logAddMass(tbb::atomic<double>& bin,
                       double newMass) {
      double oldVal = bin;
      double retVal = oldVal;
      double newVal = 0.0;
      do {
          oldVal = retVal;
          newVal = salmon::math::logAdd(oldVal, newMass);
          retVal = bin.compare_and_swap(newVal, oldVal);
      } while (retVal != oldVal);
}
Ejemplo n.º 4
0
        simplest_scheduler::simplest_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_status(),
              m_rootTask(),
              m_initTBB( std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) ) ),
              m_taskGroupContext( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::concurrent_wait )
        {
            //            {Speaker oss; oss << std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) );}
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_rootTask = new( tbb::task::allocate_root( m_taskGroupContext ) ) tbb::empty_task;
            m_rootTask->set_ref_count( 1 );
        }
        simplest_prioritized_scheduler::simplest_prioritized_scheduler( context_base &context, int numThreads, int htstride ) 
            : scheduler_i( context ),
              m_runQueue(),
              m_status(),
              m_allocated(),
              m_initTBB( numThreads  + ( distributor::myPid() == 0 ? 0 : 1 ) ),
              m_applyStepInstance( NULL )
        {
			if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
				s_po = new pinning_observer( htstride );
			}
            m_status = COMPLETED;
            m_allocated = false;
            if( m_allocated.compare_and_swap( true, false ) == false ) {
                m_applyStepInstance = new apply_step_instance();
            }

        }