Revision fbe00e73 src/sim/csimulation.cc

View differences:

src/sim/csimulation.cc
40 40
#include "cconfiguration.h"
41 41
#include "ccoroutine.h"
42 42
#include "cthreadpool.h"
43
#include "casyncmodule.h"
44 43
#include "cbarriermessage.h"
45 44
#include "cconfiguration.h"
46 45
#include "cconfigoption.h"
......
677 676
            throw cRuntimeError("Activity-Model not supported with Horizon.");
678 677
        }
679 678

  
680
        // check if this module supports parallel execution
681
        if (mod->isAsyncModule())
682
        {
683
            // yes, it does. Next, check if this event should be executed
684
            // in parallel
685
            cAsyncModule* aMod = (cAsyncModule*) mod;
686

  
687
            simtime_t duration = msg->getEventDuration();
688
            bool sequentialExecution = (duration == SimTime::simTimeSequentialExecution);
689

  
690
            if (sequentialExecution)
691
                duration = SimTime::simTimeZero;
692

  
693
            if (duration < SimTime::simTimeZero)
694
            {
695
                throw cRuntimeError("negative event duration not allowed.");
696
            }
697

  
698
            bool mayPar = aMod->mayParallelize(msg, duration);
699
            // execute this event in parallel
700
            if (mayPar && threaded && !sequentialExecution)
701
            {
702
                //printf("Offloading: %s\n",mod->getName());
703
                threadPool->insertTask(msg, duration);
704
                // the threadpool unsets the module busy after it finishes the event
705
            }
706
            else
707
            {
708
                // set the context for sequential execution
709
                setContext(mod);
710
                setContextType(CTX_EVENT);
711

  
712
                EVCB.simulationEvent(msg);
713

  
714
                msg->setPreviousEventNumber(event_num);
715

  
716
                sequentialWatch.reset();
717
                sequentialWatch.startTicking();
718
                // take ownership in callHandleMessage after concurrency check
719
                aMod->callHandleMessage(msg);
720
                sequentialWatch.stopTicking();
721

  
722
                //Store measured complexity and write to file
723
                EVCB.simulationEventEnd(sequentialWatch.getTicksTime());
724

  
725
                // take ownership in callHandleMessage after concurrency check
726
                // unset busy to release module for further events
727
                aMod->unsetBusy();
728
            }
729
        }
730
        else
731
        { //The module is not a cAsyncModule
732

  
733
            // set the context for sequential execution
734
            setContext(mod);
735
            setContextType(CTX_EVENT);
736

  
737
            //Disabled logging for simpleModules as we assume to have a duration.
738
            //EVCB.simulationEvent(msg);
739
            // store arrival event number of this message; it is useful input for the
740
            // sequence chart tool if the message doesn't get immediately deleted or
741
            // sent out again
742
            msg->setPreviousEventNumber(event_num);
743

  
744
            // take owner here: no danger of a race condition since
745
            // simple modules are only called from here
746
            mod->take(msg);
747
            // if there was an error during simulation, handleMessage()
748
            // will come back with an exception
749
            mod->handleMessage(msg);
750
        }
679
		simtime_t duration = msg->getEventDuration();
680
		bool sequentialExecution = (duration == SimTime::simTimeSequentialExecution);
681

  
682
		if (sequentialExecution)
683
			duration = SimTime::simTimeZero;
684

  
685
		if (duration < SimTime::simTimeZero)
686
		{
687
			throw cRuntimeError("negative event duration not allowed.");
688
		}
689

  
690
		bool mayPar = mod->mayParallelize(msg, duration);
691
		// execute this event in parallel
692
		if (mayPar && threaded && !sequentialExecution)
693
		{
694
			//printf("Offloading: %s\n",mod->getName());
695
			threadPool->insertTask(msg, duration);
696
			// the threadpool unsets the module busy after it finishes the event
697
		}
698
		else
699
		{
700
			// set the context for sequential execution
701
			setContext(mod);
702
			setContextType(CTX_EVENT);
703

  
704
			EVCB.simulationEvent(msg);
705

  
706
			msg->setPreviousEventNumber(event_num);
707

  
708
			sequentialWatch.reset();
709
			sequentialWatch.startTicking();
710
			// take ownership in callHandleMessage after concurrency check
711
			mod->callHandleMessage(msg);
712
			sequentialWatch.stopTicking();
713

  
714
			//Store measured complexity and write to file
715
			EVCB.simulationEventEnd(sequentialWatch.getTicksTime());
716

  
717
			// take ownership in callHandleMessage after concurrency check
718
			// unset busy to release module for further events
719
			mod->unsetBusy();
720
		}
751 721

  
752 722
        //We have handled the Message, return
753 723
        setGlobalContext();
......
877 847
void cSimulation::setupLocalRNGs() {
878 848

  
879 849
    //
880
    // Walk through vect[] and setup RNGs for each cAsyncModule
850
    // Walk through vect[] and setup RNGs for each cSimpleModule
881 851
    //
882 852
    // TODO: Better way to do this? What about dynamically created Modules?
883
    cAsyncModule* mod = NULL;
853
    cSimpleModule* mod = NULL;
884 854
    for (int i = 1; i <= last_id; i++) {
885 855
        if (vect[i]) {
886
            mod = dynamic_cast<cAsyncModule*>(vect[i]);
856
            mod = dynamic_cast<cSimpleModule*>(vect[i]);
887 857
            if (mod) {
888 858
                mod->initLocalRNGs();
889 859
            }

Also available in: Unified diff