Revision 08285dff src/envir/envirbase.cc

View differences:

src/envir/envirbase.cc
202 202
    outscalarmgr = NULL;
203 203
    snapshotmgr = NULL;
204 204

  
205
    num_rngs = 0;
206
    rngs = NULL;
205
    num_rngs_per_module = 0;
207 206

  
208 207
#ifdef WITH_PARSIM
209 208
    parsimcomm = NULL;
......
223 222
    delete outscalarmgr;
224 223
    delete snapshotmgr;
225 224

  
226
    for (int i = 0; i < num_rngs; i++)
225
    for (int i = 0; i < rngs.size(); i++)
227 226
         delete rngs[i];
228
    delete [] rngs;
229 227

  
230 228
#ifdef WITH_PARSIM
231 229
    delete parsimcomm;
......
1447 1445
    delete testrng;
1448 1446

  
1449 1447
    // set up RNGs
1450
    int i;
1451
    for (i=0; i<num_rngs; i++)
1448
    for (int i = 0; i < rngs.size(); i++)
1452 1449
         delete rngs[i];
1453
    delete [] rngs;
1454 1450

  
1455
    num_rngs = opt_num_rngs;
1456
    rngs = new cRNG *[num_rngs];
1457
    for (i=0; i<num_rngs; i++)
1458
    {
1459
        cRNG *rng;
1460
        CREATE_BY_CLASSNAME(rng, opt_rng_class.c_str(), cRNG, "random number generator");
1461
        rngs[i] = rng;
1462
        rngs[i]->initialize(opt_seedset, i, num_rngs, getParsimProcId(), getParsimNumPartitions(), getConfig());
1463
    }
1464

  
1465
    // and  finally the private seed generator for all local generators of simple modules
1466
 	CREATE_BY_CLASSNAME(seedGenerator, opt_rng_class.c_str(), cRNG, "random number generator");
1467
 	seedGenerator->initializeAsMaster(opt_seedset, num_rngs+1, num_rngs, getParsimProcId(), getParsimNumPartitions(), getConfig());
1451
    num_rngs_per_module = opt_num_rngs;
1452
	createRNGs();
1468 1453

  
1469 1454
    // init nextuniquenumber -- startRun() is too late because simple module ctors have run by then
1470 1455
    nextuniquenumber = 0;
......
1483 1468
    }
1484 1469
}
1485 1470

  
1471
void EnvirBase::createRNGs()
1472
{
1473
	int offset=rngs.size();
1474
	int moduleId=offset/num_rngs_per_module;
1475
	for(int i=0;i<num_rngs_per_module;i++)
1476
	{
1477
		int pos=i+offset;
1478
		cRNG *rng;
1479
		CREATE_BY_CLASSNAME(rng, opt_rng_class.c_str(), cRNG, "random number generator");
1480
        assert(rngs.size()==pos);
1481
		rngs.push_back(rng);
1482
        rngs[pos]->initialize(opt_seedset*moduleId, i, num_rngs_per_module, getParsimProcId(), getParsimNumPartitions(), getConfig());
1483
	}
1484
}
1485

  
1486 1486
void EnvirBase::setEventlogRecording(bool enabled)
1487 1487
{
1488 1488
    // NOTE: eventlogmgr must be non-NULL when record_eventlog is true
......
1508 1508

  
1509 1509
//-------------------------------------------------------------
1510 1510

  
1511
int EnvirBase::getNumRNGs() const
1511
int EnvirBase::getNumRNGsPerModule() const
1512 1512
{
1513
    return num_rngs;
1513
    return num_rngs_per_module;
1514 1514
}
1515 1515

  
1516 1516
cRNG *EnvirBase::getRNG(int k)
1517 1517
{
1518
    if (k<0 || k>=num_rngs)
1519
        throw cRuntimeError("RNG index %d is out of range (num-rngs=%d, check the configuration)", k, num_rngs);
1518
    if (k<0 || k>=rngs.size())
1519
        throw cRuntimeError("RNG index %d is out of range (num-rngs=%d*<numberOfModules>=%d, check the configuration)", k, num_rngs_per_module, rngs.size());
1520 1520
    return rngs[k];
1521 1521
}
1522 1522

  
......
1544 1544
                                "numeric RNG indices expected",
1545 1545
                                suffix, value, component->getFullPath().c_str());
1546 1546

  
1547
        if (physRng>getNumRNGs())
1547
        if (physRng>rngs.size())
1548 1548
            throw cRuntimeError("Configuration error: rng-%d=%d of module/channel %s: "
1549 1549
                                "RNG index out of range (num-rngs=%d)",
1550
                                modRng, physRng, component->getFullPath().c_str(), getNumRNGs());
1550
                                modRng, physRng, component->getFullPath().c_str(), rngs.size());
1551 1551
        if (modRng>=mapsize)
1552 1552
        {
1553 1553
            if (modRng>=100)

Also available in: Unified diff