Revision 08285dff src/sim/csimplemodule.cc

View differences:

src/sim/csimplemodule.cc
603 603
    return coroutine ? coroutine->getStackUsage() : 0;
604 604
}
605 605

  
606
void cSimpleModule::initLocalRNGs()
607
{
608
    //TODO
609
    unsigned nrNumGens;
610
    unsigned long * seeds;
611

  
612
    //
613
    // how many local random number generators do we need?
614
    // default is 1
615
    //
616
    nrNumGens = ev.getConfig()->parseLong(
617
            ev.getConfig()->getPerObjectConfigValue(getFullPath().c_str(),
618
                    "number-local-rngs"), "1", 1);
619

  
620
    //
621
    // read the seeds from ini file
622
    //
623
    const char * seedString = ev.getConfig()->getPerObjectConfigValue(
624
            getFullPath().c_str(), "local-rng-seed");
625

  
626
    //
627
    // setup seeds for each RNG
628
    //
629
    seeds = new unsigned long[nrNumGens];
630
    cStringTokenizer tokenizer(seedString);
631
    const char * token = NULL;
632
    for (unsigned i = 0; i < nrNumGens; i++)
633
    {
634
        if (tokenizer.hasMoreTokens())
635
        {
636
            token = tokenizer.nextToken();
637
            if (strcmp(token, "auto") == 0)
638
            {
639
                token = NULL;
640
            }
641
        }
642

  
643
        EnvirBase* e = dynamic_cast<EnvirBase*> (&ev);
644
        if (e != NULL)
645
        {
646
            if (token)
647
            {
648
                //if the seed is set in the ini for this module, use ini-settings
649
                //with fallback to autogeneration if parsing failes
650
                seeds[i] = ev.getConfig()->parseLong(token, "",
651
                        e->getSeedGenerator()->intRand());
652
            }
653
            else
654
            {
655
                //else use SeedGenerator for automatic seed generation.
656
                seeds[i] = e->getSeedGenerator()->intRand();
657
            }
658
            token = NULL;
659
        }
660
        else
661
        {
662
            throw cRuntimeError(
663
                    "cSimpleModule: Failed to initialize Number Generator, dynamic cast to EnvirBase failed.");
664
        }
665
    }
666

  
667
    //
668
    // generate the required number of RNGs with the corresponding seeds
669
    //
670
    setupSeeds(nrNumGens,seeds);
671
    delete[] seeds;
672

  
673
}
674

  
675 606
void cSimpleModule::setMessageMetaData(cMessage* msg)
676 607
{
677 608
    msg->setEventDuration(SimTime::simTimeUninitialized);

Also available in: Unified diff