コード例 #1
0
ファイル: Tick.cpp プロジェクト: praveenv253/moose
/**
 * This function is called to advance this one tick through one 'process'
 * cycle. It is called in parallel on multiple threads, and the thread
 * info is in the ProcInfo. It is the job of the target Elements to
 * examine the ProcInfo and assign subsets of the object array to do
 * the process operation.
 */
void Tick::advance( ProcInfo* info ) const
{
    // March through Process calls for each scheduled Element.
    // Note that there is a unique BindIndex for each tick.
    // We preallocate 0 through 10 for this.
    assert( index_ < processVec().size() );
    BindIndex b = processVec()[ index_ ]->getBindIndex();
    const vector< MsgFuncBinding >* m = ticke_->getMsgAndFunc( b );
    for ( vector< MsgFuncBinding >::const_iterator i = m->begin();
            i != m->end(); ++i ) {
        Msg::getMsg( i->mid )->process( info, i->fid );
    }
}
コード例 #2
0
ファイル: Clock.cpp プロジェクト: csiki/moose-csiki
void Clock::handleStep( const Eref& e, unsigned int numSteps )
{
	if ( isRunning_ || doingReinit_ ) {
		cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
		return;
	}
	buildTicks( e );
	assert( currentStep_ == nSteps_ );
	assert( activeTicks_.size() == activeTicksMap_.size() );
	nSteps_ += numSteps;
	runTime_ = nSteps_ * dt_;
	for ( isRunning_ = true;
		isRunning_ && currentStep_ < nSteps_; ++currentStep_ )
	{
		// Curr time is end of current step.
		unsigned int endStep = currentStep_ + 1;
		currentTime_ = info_.currTime = dt_ * endStep;
		vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
		for ( vector< unsigned int>::iterator j = 
			activeTicks_.begin(); j != activeTicks_.end(); ++j ) {
			if ( endStep % *j == 0 ) {
				info_.dt = *j * dt_;
				processVec()[*k]->send( e, &info_ );
			}
			++k;
		}
	}
	info_.dt = dt_;
	isRunning_ = false;
	finished()->send( e );
}
コード例 #3
0
ファイル: Clock.cpp プロジェクト: asiaszmek/moose
void Clock::handleStep( const Eref& e, unsigned long numSteps )
{
    numSteps *= stride_;
    if ( isRunning_ || doingReinit_ )
    {
        cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
        return;
    }

    time_t rawtime;
    struct tm * timeinfo;
    char now[80];

    buildTicks( e );
    assert( currentStep_ == nSteps_ );
    assert( activeTicks_.size() == activeTicksMap_.size() );
    nSteps_ += numSteps;
    runTime_ = nSteps_ * dt_;
    for ( isRunning_ = (activeTicks_.size() > 0 );
            isRunning_ && currentStep_ < nSteps_; currentStep_ += stride_ )
    {
        // Curr time is end of current step.
        unsigned long endStep = currentStep_ + stride_;
        currentTime_ = info_.currTime = dt_ * endStep;
        vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
        for ( vector< unsigned int>::iterator j =
                    activeTicks_.begin(); j != activeTicks_.end(); ++j )
        {
            if ( endStep % *j == 0 )
            {
                info_.dt = *j * dt_;
                processVec()[*k]->send( e, &info_ );
            }
            ++k;
        }

        // When 10% of simulation is over, notify user when notify_ is set to
        // true.
        if( notify_ )
        {
            if( fmod(100 * currentTime_ / runTime_ , 10.0) == 0.0 )
            {
                time( &rawtime );
                timeinfo = localtime( &rawtime );
                strftime(now, 80, "%c", timeinfo);
                cout << "@ " << now << ": " << 100 * currentTime_ / runTime_ 
                    << "% of total " << runTime_ << " seconds is over." << endl;
            }
        }
    }
	if ( activeTicks_.size() == 0 )
		currentTime_ = runTime_;

    info_.dt = dt_;
    isRunning_ = false;
    finished()->send( e );
}
コード例 #4
0
ファイル: Clock.cpp プロジェクト: asiaszmek/moose-core
Clock::~Clock()
{
	if ( Msg::isLastTrump() ) { // Clean up, end of the simulation.
		for ( unsigned int i = 0; i < Clock::numTicks; ++i ) {
			delete processVec()[i];
			delete reinitVec()[i];
			delete sharedProcVec()[i];
		}
	}
}
コード例 #5
0
ファイル: Clock.cpp プロジェクト: csiki/moose-csiki
void Clock::buildTicks( const Eref& e )
{
	activeTicks_.resize(0);
	activeTicksMap_.resize(0);
	for ( unsigned int i = 0; i < ticks_.size(); ++i ) {
		if ( ticks_[i] > 0 && 
				e.element()->hasMsgs( processVec()[i]->getBindIndex() ) ) {
			activeTicks_.push_back( ticks_[i] );
			activeTicksMap_.push_back( i );
		}
	}
}
コード例 #6
0
ファイル: Clock.cpp プロジェクト: asiaszmek/moose-core
void Clock::buildTicks( const Eref& e )
{
	activeTicks_.resize(0);
	activeTicksMap_.resize(0);
	stride_ = ~0U;
	for ( unsigned int i = 0; i < ticks_.size(); ++i ) {
		if ( ticks_[i] > 0 && 
				e.element()->hasMsgs( processVec()[i]->getBindIndex() ) ) {
			activeTicks_.push_back( ticks_[i] );
			activeTicksMap_.push_back( i );
			if ( ticks_[i] > 0 && stride_ > ticks_[i] )
				stride_ = ticks_[i];
		}
	}
	// Should really do the HCF of N numbers here to get the stride.
}
コード例 #7
0
ファイル: Clock.cpp プロジェクト: asiaszmek/moose-core
static vector< SharedFinfo *>& sharedProcVec() {
	static vector< SharedFinfo* > vec;
	if ( vec.size() == 0 ) {
		vec.resize( Clock::numTicks );
		for ( unsigned int i = 0; i < Clock::numTicks; ++i ) {
			stringstream ss;
			Finfo* temp[2];
			temp[0] = processVec()[i];
			temp[1] = reinitVec()[i];
			ss << "proc" << i;
			vec[i] = new SharedFinfo( ss.str(), 
						"Shared process/reinit message",
						temp, 2 );
		}
	}
	return vec;
}
コード例 #8
0
ファイル: Clock.cpp プロジェクト: hrani/moose-core
void Clock::handleStep( const Eref& e, unsigned long numSteps )
{
    numSteps *= stride_;
    if ( isRunning_ || doingReinit_ )
    {
        cout << "Clock::handleStart: Warning: simulation already in progress.\n Command ignored\n";
        return;
    }

    time_t rawtime;
    struct tm * timeinfo;
    char now[80];

    buildTicks( e );
    assert( currentStep_ == nSteps_ );
    assert( activeTicks_.size() == activeTicksMap_.size() );
    nSteps_ += numSteps;
    runTime_ = nSteps_ * dt_;
    for ( isRunning_ = (activeTicks_.size() > 0 );
            isRunning_ && currentStep_ < nSteps_; currentStep_ += stride_ )
    {
        // Curr time is end of current step.
        unsigned long endStep = currentStep_ + stride_;
        currentTime_ = info_.currTime = dt_ * endStep;

#if PARALLELIZE_CLOCK_USING_CPP11_ASYNC

        // NOTE: It does not produce very promising results. The challenge here
        // is doing load-balancing.
        // TODO: To start with, we can put one solver on one thread and everything
        // else onto 1 thread. Each Hsove, Ksolve, and Gsolve can take its own
        // thread and rest are on different threads.

        unsigned int nTasks = activeTicks_.size( );
        unsigned int numThreads_ = 3;
        unsigned int blockSize = 1 + (nTasks / numThreads_);

        for( unsigned int i = 0; i < numThreads_; ++i  )
        {
            std::async( std::launch::async
                        , [this,blockSize,i,nTasks,endStep,e]
            {
                unsigned int mapI = i * blockSize;
                // Get the block we want to run in paralle.
                for( unsigned int ii = i * blockSize; ii < min((i+1) * blockSize, nTasks); ii++ )
                {
                    unsigned int j = activeTicks_[ ii ];
                    if( endStep % j == 0  )
                    {
                        info_.dt = j * dt_;
                        processVec( )[ activeTicksMap_[mapI] ]->send( e, &info_ );
                    }
                    mapI++;
                }
            }
                      );
        }
#else
        vector< unsigned int >::const_iterator k = activeTicksMap_.begin();
        for ( vector< unsigned int>::iterator j =
                    activeTicks_.begin(); j != activeTicks_.end(); ++j )
        {
            if ( endStep % *j == 0 )
            {
                info_.dt = *j * dt_;
                processVec()[*k]->send( e, &info_ );
            }
            ++k;
        }
#endif

        // When 10% of simulation is over, notify user when notify_ is set to
        // true.
        if( notify_ )
        {
            if( fmod(100 * currentTime_ / runTime_, 10.0) == 0.0 )
            {
                time( &rawtime );
                timeinfo = localtime( &rawtime );
                strftime(now, 80, "%c", timeinfo);
                cout << "@ " << now << ": " << 100 * currentTime_ / runTime_
                     << "% of total " << runTime_ << " seconds is over." << endl;
            }
        }

        if ( activeTicks_.size() == 0 )
            currentTime_ = runTime_;
    }

    info_.dt = dt_;
    isRunning_ = false;
    finished()->send( e );
}
コード例 #9
0
ファイル: Tick.cpp プロジェクト: praveenv253/moose
const Cinfo* Tick::initCinfo()
{
    ///////////////////////////////////////////////////////
    // Field definitions
    ///////////////////////////////////////////////////////
    // Refers it to the parent Clock.
    static UpValueFinfo< Clock, double > dt(
        "dt",
        "Timestep for this tick",
        &Clock::setTickDt,
        &Clock::getTickDt
    );
    static ValueFinfo< Tick, double > localdt(
        "localdt",
        "Timestep for this tick",
        &Tick::setDt,
        &Tick::getDt
    );
    /*
    static ValueFinfo< Tick, string> path(
    	"path",
    	"Wildcard path of objects managed by this tick",
    	&Tick::setPath,
    	&Tick::getPath
    );
    */
    ///////////////////////////////////////////////////////
    // MsgSrc definitions
    ///////////////////////////////////////////////////////
    // These are defined outside this function.

    ///////////////////////////////////////////////////////
    // MsgDest definitions
    ///////////////////////////////////////////////////////
    /*
    static DestFinfo parent( "parent",
    	"Message from Parent Element(s)",
    	new EpFunc0< Tick >( &Tick::destroy ) );
    	*/

    static Finfo* procShared0[] = { processVec()[0], reinitVec()[0] };
    static Finfo* procShared1[] = { processVec()[1], reinitVec()[1] };
    static Finfo* procShared2[] = { processVec()[2], reinitVec()[2] };
    static Finfo* procShared3[] = { processVec()[3], reinitVec()[3] };
    static Finfo* procShared4[] = { processVec()[4], reinitVec()[4] };
    static Finfo* procShared5[] = { processVec()[5], reinitVec()[5] };
    static Finfo* procShared6[] = { processVec()[6], reinitVec()[6] };
    static Finfo* procShared7[] = { processVec()[7], reinitVec()[7] };
    static Finfo* procShared8[] = { processVec()[8], reinitVec()[8] };
    static Finfo* procShared9[] = { processVec()[9], reinitVec()[9] };

    static SharedFinfo proc0( "proc0", "Shared proc/reinit message", procShared0, sizeof( procShared0 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc1( "proc1", "Shared proc/reinit message", procShared1, sizeof( procShared1 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc2( "proc2", "Shared proc/reinit message", procShared2, sizeof( procShared2 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc3( "proc3", "Shared proc/reinit message", procShared3, sizeof( procShared3 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc4( "proc4", "Shared proc/reinit message", procShared4, sizeof( procShared4 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc5( "proc5", "Shared proc/reinit message", procShared5, sizeof( procShared5 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc6( "proc6", "Shared proc/reinit message", procShared6, sizeof( procShared6 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc7( "proc7", "Shared proc/reinit message", procShared7, sizeof( procShared7 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc8( "proc8", "Shared proc/reinit message", procShared8, sizeof( procShared8 ) / sizeof( const Finfo* ) );
    static SharedFinfo proc9( "proc9", "Shared proc/reinit message", procShared9, sizeof( procShared9 ) / sizeof( const Finfo* ) );

    static Finfo* tickFinfos[] =
    {
        // Fields
        &dt,
        &localdt,
        // &path,
        // Shared SrcFinfos for process
        &proc0,
        &proc1,
        &proc2,
        &proc3,
        &proc4,
        &proc5,
        &proc6,
        &proc7,
        &proc8,
        &proc9,
        // MsgDest definitions
        // &parent, // I thought this was to be inherited?
    };

    static Cinfo tickCinfo(
        "Tick",
        // 0,
        Neutral::initCinfo(),
        tickFinfos,
        sizeof(tickFinfos) / sizeof(Finfo *),
        new Dinfo< Tick >()
    );

    return &tickCinfo;
}
コード例 #10
0
ファイル: Tick.cpp プロジェクト: praveenv253/moose
/**
 * Checks if we have any tick targets.
 */
bool Tick::hasTickTargets() const
{
    assert( ticke_ );
    BindIndex b = processVec()[ index_ ]->getBindIndex();
    return ticke_->hasMsgs( b );
}
コード例 #11
0
ファイル: Clock.cpp プロジェクト: csiki/moose-csiki
const Cinfo* Clock::initCinfo()
{
	///////////////////////////////////////////////////////
	// Field definitions
	///////////////////////////////////////////////////////
		static ValueFinfo< Clock, double > dt( 
			"dt",
			"Base timestep for simulation",
			&Clock::setDt,
			&Clock::getDt
		);
		static ReadOnlyValueFinfo< Clock, double > runTime( 
			"runTime",
			"Duration to run the simulation",
			&Clock::getRunTime
		);
		static ReadOnlyValueFinfo< Clock, double > currentTime(
			"currentTime",
			"Current simulation time",
			&Clock::getCurrentTime
		);
		static ReadOnlyValueFinfo< Clock, unsigned int > nsteps( 
			"nsteps",
			"Number of steps to advance the simulation, in units of the smallest timestep on the clock ticks",
			&Clock::getNsteps
		);
		static ReadOnlyValueFinfo< Clock, unsigned int > numTicks( 
			"numTicks",
			"Number of clock ticks",
			&Clock::getNumTicks
		);
		static ReadOnlyValueFinfo< Clock, unsigned int > currentStep( 
			"currentStep",
			"Current simulation step",
			&Clock::getCurrentStep
		);

		static ReadOnlyValueFinfo< Clock, vector< double > > dts( 
			"dts",
			"Utility function returning the dt (timestep) of all ticks.",
			&Clock::getDts
		);

		static ReadOnlyValueFinfo< Clock, bool > isRunning( 
			"isRunning",
			"Utility function to report if simulation is in progress.",
			&Clock::isRunning
		);

		static LookupValueFinfo< Clock, unsigned int, unsigned int > 
			tickStep(
			"tickStep",
			"Step size of specified Tick, as integral multiple of dt_"
			" A zero step size means that the Tick is inactive",
			&Clock::setTickStep,
			&Clock::getTickStep
		);

		static LookupValueFinfo< Clock, unsigned int, double > tickDt(
			"tickDt",
			"Timestep dt of specified Tick. Always integral multiple of "
			"dt_. If you assign a non-integer multiple it will round off. "
			" A zero timestep means that the Tick is inactive",
			&Clock::setTickDt,
			&Clock::getTickDt
		);
	///////////////////////////////////////////////////////
	// Shared definitions
	///////////////////////////////////////////////////////
	static Finfo* procShared0[] = { processVec()[0], reinitVec()[0] };
	static Finfo* procShared1[] = { processVec()[1], reinitVec()[1] };
	static Finfo* procShared2[] = { processVec()[2], reinitVec()[2] };
	static Finfo* procShared3[] = { processVec()[3], reinitVec()[3] };
	static Finfo* procShared4[] = { processVec()[4], reinitVec()[4] };
	static Finfo* procShared5[] = { processVec()[5], reinitVec()[5] };
	static Finfo* procShared6[] = { processVec()[6], reinitVec()[6] };
	static Finfo* procShared7[] = { processVec()[7], reinitVec()[7] };
	static Finfo* procShared8[] = { processVec()[8], reinitVec()[8] };
	static Finfo* procShared9[] = { processVec()[9], reinitVec()[9] };
	static Finfo* procShared10[] = { processVec()[10], reinitVec()[10] };
	static Finfo* procShared11[] = { processVec()[11], reinitVec()[11] };
	static Finfo* procShared12[] = { processVec()[12], reinitVec()[12] };
	static Finfo* procShared13[] = { processVec()[13], reinitVec()[13] };
	static Finfo* procShared14[] = { processVec()[14], reinitVec()[14] };
	static Finfo* procShared15[] = { processVec()[15], reinitVec()[15] };
	static Finfo* procShared16[] = { processVec()[16], reinitVec()[16] };
	static Finfo* procShared17[] = { processVec()[17], reinitVec()[17] };
	static Finfo* procShared18[] = { processVec()[18], reinitVec()[18] };
	static Finfo* procShared19[] = { processVec()[19], reinitVec()[19] };

	static string s = "Shared process/reinit message";
	unsigned int sz = sizeof( procShared0 ) / sizeof( const Finfo* );
	static SharedFinfo proc0( "proc0", s, procShared0, sz );
	static SharedFinfo proc1( "proc1", s, procShared1, sz );
	static SharedFinfo proc2( "proc2", s, procShared2, sz );
	static SharedFinfo proc3( "proc3", s, procShared3, sz );
	static SharedFinfo proc4( "proc4", s, procShared4, sz );
	static SharedFinfo proc5( "proc5", s, procShared5, sz );
	static SharedFinfo proc6( "proc6", s, procShared6, sz );
	static SharedFinfo proc7( "proc7", s, procShared7, sz );
	static SharedFinfo proc8( "proc8", s, procShared8, sz );
	static SharedFinfo proc9( "proc9", s, procShared9, sz );
	static SharedFinfo proc10( "proc10", s, procShared10, sz );
	static SharedFinfo proc11( "proc11", s, procShared11, sz );
	static SharedFinfo proc12( "proc12", s, procShared12, sz );
	static SharedFinfo proc13( "proc13", s, procShared13, sz );
	static SharedFinfo proc14( "proc14", s, procShared14, sz );
	static SharedFinfo proc15( "proc15", s, procShared15, sz );
	static SharedFinfo proc16( "proc16", s, procShared16, sz );
	static SharedFinfo proc17( "proc17", s, procShared17, sz );
	static SharedFinfo proc18( "proc18", s, procShared18, sz );
	static SharedFinfo proc19( "proc19", s, procShared19, sz );

	///////////////////////////////////////////////////////
	// MsgDest definitions
	///////////////////////////////////////////////////////
		static DestFinfo start( "start", 
			"Sets off the simulation for the specified duration",
			new EpFunc1< Clock, double >(&Clock::handleStart )
		);

		static DestFinfo step( "step", 
			"Sets off the simulation for the specified # of steps",
			new EpFunc1< Clock, unsigned int >(&Clock::handleStep )
		);

		static DestFinfo stop( "stop", 
			"Halts the simulation, with option to restart seamlessly",
			new OpFunc0< Clock >(&Clock::stop )
		);

		static DestFinfo reinit( "reinit", 
			"Zeroes out all ticks, starts at t = 0",
	 		new EpFunc0< Clock >(&Clock::handleReinit )
		);

		static Finfo* clockControlFinfos[] = {
			&start, &step, &stop, &reinit,
		};
	///////////////////////////////////////////////////////
	// SharedFinfo for Shell to control Clock
	///////////////////////////////////////////////////////
		static SharedFinfo clockControl( "clockControl",
			"Controls all scheduling aspects of Clock, usually from Shell",
			clockControlFinfos, 
			sizeof( clockControlFinfos ) / sizeof( Finfo* )
		);

	static Finfo* clockFinfos[] =
	{
		// Fields
		&dt,				// Value
		&runTime,			// ReadOnlyValue
		&currentTime,		// ReadOnlyValue
		&nsteps,			// ReadOnlyValue
		&numTicks,			// ReadOnlyValue
		&currentStep,		// ReadOnlyValue
		&dts,				// ReadOnlyValue
		&isRunning,			// ReadOnlyValue
		&tickStep,			// LookupValue
		&tickDt,			// LookupValue
		&clockControl,		// Shared
		finished(),			// Src
		&proc0,				// Src
		&proc1,				// Src
		&proc2,				// Src
		&proc3,				// Src
		&proc4,				// Src
		&proc5,				// Src
		&proc6,				// Src
		&proc7,				// Src
		&proc8,				// Src
		&proc9,				// Src
		&proc10,				// Src
		&proc11,				// Src
		&proc12,				// Src
		&proc13,				// Src
		&proc14,				// Src
		&proc15,				// Src
		&proc16,				// Src
		&proc17,				// Src
		&proc18,				// Src
		&proc19,				// Src
	};
	
	static string doc[] =
	{
		"Name", "Clock",
		"Author", "Upinder S. Bhalla, Nov 2013, NCBS",
		"Description", "Clock: Clock class. Handles sequencing of operations in simulations."
		"Every object scheduled for operations in MOOSE is connected to one"
		"of the 'Tick' entries on the Clock."
		"The Clock manages ten 'Ticks', each of which has its own dt,"
		"which is an integral multiple of the base clock dt_. "
		"On every clock step the ticks are examined to see which of them"
		"is due for updating. When a tick is updated, the 'process' call "
		"of all the objects scheduled on that tick is called."
		"The default scheduling (should not be overridden) has the "
		"following assignment of classes to Ticks:"
		"0. Biophysics: Init call on Compartments in EE method"
		"1. Biophysics: Channels"
		"2. Biophysics: Process call on Compartments"
		"3. Undefined "
		"4. Kinetics: Pools, or in ksolve mode: Mesh to handle diffusion"
		"5. Kinetics: Reacs, enzymes, etc, or in ksolve mode: Stoich/GSL"
		"6. Stimulus tables"
		"7. More stimulus tables"
		"8. Plots"
		"9. Postmaster. This must be called last of all and nothing else "
		"should use this Tick. The Postmaster is automatically scheduled "
		"at set up time. The Tick should be given the longest possible "
		"value, typically but not always equal to one of the other ticks, "
		"so as to batch the "
		"communications. For spiking-only communications, it is usually "
		"possible to space the communication tick by as much as 1-2 ms "
		"which is the axonal + synaptic delay. "
		"",
	};

	static Dinfo< Clock > dinfo;
	static Cinfo clockCinfo(
		"Clock",
		// "Clock class handles sequencing of operations in simulations",
		Neutral::initCinfo(),
		clockFinfos,
		sizeof(clockFinfos)/sizeof(Finfo *),
		&dinfo,
                doc,
                sizeof(doc)/sizeof(string)
	);

	return &clockCinfo;
}