[Avida-cvs] [avida-svn] r522 - in development: . source/analyze source/classification source/cpu source/drivers source/event source/main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Mar 17 04:01:57 PST 2006
Author: brysonda
Date: 2006-03-17 07:01:57 -0500 (Fri, 17 Mar 2006)
New Revision: 522
Modified:
development/CMakeLists.txt
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeJob.h
development/source/analyze/cAnalyzeJobQueue.cc
development/source/analyze/cAnalyzeJobQueue.h
development/source/analyze/cAnalyzeJobWorker.cc
development/source/analyze/cAnalyzeUtil.cc
development/source/analyze/tAnalyzeJob.h
development/source/classification/cGenotype.cc
development/source/classification/cSpecies.cc
development/source/cpu/cTestUtil.cc
development/source/drivers/cDefaultRunDriver.cc
development/source/event/cEventManager.cc
development/source/main/cAvidaContext.h
development/source/main/cFitnessMatrix.cc
development/source/main/cPopulation.cc
Log:
Modify cAnalyzeJobQueue to create a cRandomMT pool that is used to hand out pointers for job cAvidaContexts. Adjust cAvidaContext to hold a pointer to a cRandom object.
Also change the default CMake build to build only command-line avida, as per Sherri's request. It can obviously still be turned on using ccmake.
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2006-03-15 04:45:51 UTC (rev 521)
+++ development/CMakeLists.txt 2006-03-17 12:01:57 UTC (rev 522)
@@ -132,7 +132,7 @@
# By default, build the console interface to Avida.
OPTION(AVD_GUI_NCURSES
"Enable building Avida console interface."
- ON
+ OFF
)
# Make sure requisites are present for build of console interface. Give
# user feedback if they're missing.
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeGenotype.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -192,7 +192,7 @@
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
// Calculate the base fitness for the genotype we're working with...
// (This may not have been run already, and cost negligiably more time
Modified: development/source/analyze/cAnalyzeJob.h
===================================================================
--- development/source/analyze/cAnalyzeJob.h 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeJob.h 2006-03-17 12:01:57 UTC (rev 522)
@@ -10,13 +10,21 @@
#ifndef cAnalyzeJob_h
#define cAnalyzeJob_h
+class cAvidaContext;
+
class cAnalyzeJob
{
+private:
+ int m_id;
+
public:
- cAnalyzeJob() { ; }
+ cAnalyzeJob() : m_id(0) { ; }
virtual ~cAnalyzeJob() { ; }
- virtual void Run() = 0;
+ void SetID(int newid) { m_id = newid; }
+ int GetID() { return m_id; }
+
+ virtual void Run(cAvidaContext& ctx) = 0;
};
#endif
Modified: development/source/analyze/cAnalyzeJobQueue.cc
===================================================================
--- development/source/analyze/cAnalyzeJobQueue.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeJobQueue.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -12,6 +12,15 @@
#include "cAnalyzeJobWorker.h"
#include "cWorld.h"
+cAnalyzeJobQueue::cAnalyzeJobQueue(cWorld* world) : m_world(world), m_last_jobid(0)
+{
+ for (int i = 0; i < MT_RANDOM_POOL_SIZE; i++) {
+ m_rng_pool[i] = new cRandomMT(world->GetRandom().GetInt(0x7FFFFFFF));
+ }
+
+ pthread_mutex_init(&m_mutex, NULL);
+}
+
cAnalyzeJobQueue::~cAnalyzeJobQueue()
{
cAnalyzeJob* job;
Modified: development/source/analyze/cAnalyzeJobQueue.h
===================================================================
--- development/source/analyze/cAnalyzeJobQueue.h 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeJobQueue.h 2006-03-17 12:01:57 UTC (rev 522)
@@ -16,12 +16,18 @@
#ifndef tList_h
#include "tList.h"
#endif
+#ifndef cRandom_h
+#include "cRandom.h"
+#endif
#include <pthread.h>
class cWorld;
+const int MT_RANDOM_POOL_SIZE = 16;
+const int MT_RANDOM_INDEX_MASK = 0xF;
+
class cAnalyzeJobQueue
{
friend class cAnalyzeJobWorker;
@@ -29,18 +35,23 @@
private:
cWorld* m_world;
tList<cAnalyzeJob> m_queue;
+ int m_last_jobid;
+ cRandomMT* m_rng_pool[MT_RANDOM_POOL_SIZE];
pthread_mutex_t m_mutex;
+
cAnalyzeJobQueue(const cAnalyzeJobQueue&); // @not_implemented
cAnalyzeJobQueue& operator=(const cAnalyzeJobQueue&); // @not_implemented
public:
- cAnalyzeJobQueue(cWorld* world) : m_world(world) { pthread_mutex_init(&m_mutex, NULL); }
+ cAnalyzeJobQueue(cWorld* world);
~cAnalyzeJobQueue();
- void AddJob(cAnalyzeJob* job) { m_queue.PushRear(job); } // @DMB - warning: this method is NOT thread safe
+ void AddJob(cAnalyzeJob* job) { job->SetID(m_last_jobid++); m_queue.PushRear(job); } // @DMB - Warning: NOT thread safe
void Execute();
+
+ cRandom* GetRandom(int jobid) { return m_rng_pool[jobid & MT_RANDOM_INDEX_MASK]; }
};
#endif
Modified: development/source/analyze/cAnalyzeJobWorker.cc
===================================================================
--- development/source/analyze/cAnalyzeJobWorker.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeJobWorker.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -10,9 +10,11 @@
#include "cAnalyzeJobWorker.h"
#include "cAnalyzeJobQueue.h"
+#include "cAvidaContext.h"
void cAnalyzeJobWorker::Run()
{
+ cAvidaContext ctx(NULL);
cAnalyzeJob* job = NULL;
while (1) {
@@ -21,7 +23,8 @@
pthread_mutex_unlock(&m_queue->m_mutex);
if (job) {
- job->Run();
+ ctx.SetRandom(m_queue->GetRandom(job->GetID()));
+ job->Run(ctx);
} else {
break;
}
Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/cAnalyzeUtil.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -45,7 +45,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cCPUTestInfo test_info;
testcpu->TestGenome(ctx, test_info, genome);
@@ -71,7 +71,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cCPUTestInfo test_info;
const cInstruction inst_none = inst_set.GetInst("instruction_none");
@@ -121,7 +121,7 @@
cInstSet & inst_set)
{
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cLandscape landscape(world, genome, inst_set);
landscape.Process(ctx, dist);
@@ -161,7 +161,7 @@
int sample_size, int min_found, int max_sample_size, int update)
{
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cLandscape landscape(world, genome, inst_set);
ofstream& fp = world->GetDataFileOFStream("land_analyze.dat");
@@ -197,7 +197,7 @@
int sample_size, int update)
{
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cLandscape landscape(world, genome, inst_set);
@@ -344,7 +344,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cCPUTestInfo test_info;
testcpu->TestGenome(ctx, test_info, con_genome);
@@ -407,7 +407,7 @@
fp << "# (1) cell number (2) genotype name (3) length (4) fitness [test-cpu] (5) fitness (actual) (6) merit (7) no of breed trues occurred (8) lineage label (9) neutral metric (10) -... landscape data" << endl;
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
const double skip_prob = 1.0 - sample_prob;
for (int i = 0; i < pop->GetSize(); i++) {
@@ -503,7 +503,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue; // One use organisms.
@@ -726,7 +726,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
for (int i = 0; i < pop->GetSize(); i++) {
if (pop->GetCell(i).IsOccupied() == false) continue;
@@ -785,7 +785,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
for (int i = 0; i < pop->GetWorldX(); i++) {
for (int j = 0; j < pop->GetWorldY(); j++) {
Modified: development/source/analyze/tAnalyzeJob.h
===================================================================
--- development/source/analyze/tAnalyzeJob.h 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/analyze/tAnalyzeJob.h 2006-03-17 12:01:57 UTC (rev 522)
@@ -13,9 +13,6 @@
#ifndef cAnalyzeJob_h
#include "cAnalyzeJob.h"
#endif
-#ifndef cAvidaContext_h
-#include "cAvidaContext.h"
-#endif
template <class T> class tAnalyzeJob : public cAnalyzeJob
{
@@ -26,9 +23,8 @@
public:
tAnalyzeJob(T* target, void (T::*funJ)(cAvidaContext&)) : cAnalyzeJob(), m_target(target), JobTask(funJ) { ; }
- void Run()
+ void Run(cAvidaContext& ctx)
{
- cAvidaContext ctx(0);
(m_target->*JobTask)(ctx);
}
};
Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/classification/cGenotype.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -201,7 +201,7 @@
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cCPUTestInfo test_info;
testcpu->TestGenome(ctx, test_info, genome);
Modified: development/source/classification/cSpecies.cc
===================================================================
--- development/source/classification/cSpecies.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/classification/cSpecies.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -80,7 +80,7 @@
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cCPUTestInfo test_info;
Modified: development/source/cpu/cTestUtil.cc
===================================================================
--- development/source/cpu/cTestUtil.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/cpu/cTestUtil.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -42,7 +42,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cCPUTestInfo test_info;
test_info.TestThreads();
@@ -148,7 +148,7 @@
cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(world->GetRandom());
cCPUTestInfo test_info;
test_info.TestThreads();
Modified: development/source/drivers/cDefaultRunDriver.cc
===================================================================
--- development/source/drivers/cDefaultRunDriver.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/drivers/cDefaultRunDriver.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -51,7 +51,7 @@
const int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get();
const double point_mut_prob = m_world->GetConfig().POINT_MUT_PROB.Get();
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
while (!m_done) {
if (cChangeList* change_list = population.GetChangeList()) {
Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/event/cEventManager.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -1865,7 +1865,7 @@
if (cell_id == -1) cell_id = m_world->GetRandom().GetUInt(m_world->GetPopulation().GetSize());
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome genome =
cInstUtil::RandomGenome(ctx, length, m_world->GetHardwareManager().GetInstSet());
@@ -2288,7 +2288,7 @@
///// predict_w_landscape /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2319,7 +2319,7 @@
///// predict_nu_landscape /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2350,7 +2350,7 @@
///// sample_landscape /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2391,7 +2391,7 @@
///// random_landscape /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2899,7 +2899,7 @@
///// hillclimb /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2927,7 +2927,7 @@
///// hillclimb_neut /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2955,7 +2955,7 @@
///// hillclimb_rand /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -3160,7 +3160,7 @@
///// test_threads /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
testcpu->TestThreads(ctx, m_world->GetClassificationManager().GetBestGenotype()->GetGenome());
@@ -3188,7 +3188,7 @@
///// print_threads /////
void Process(){
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
testcpu->PrintThreads(ctx, m_world->GetClassificationManager().GetBestGenotype()->GetGenome() );
Modified: development/source/main/cAvidaContext.h
===================================================================
--- development/source/main/cAvidaContext.h 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/main/cAvidaContext.h 2006-03-17 12:01:57 UTC (rev 522)
@@ -10,16 +10,21 @@
#ifndef cAvidaContext_h
#define cAvidaContext_h
+class cRandom;
+
class cAvidaContext
{
private:
- int m_rng_id;
+ cRandom* m_rng;
public:
- cAvidaContext(int rng_id) : m_rng_id(rng_id) { ; }
+ cAvidaContext(cRandom& rng) : m_rng(&rng) { ; }
+ cAvidaContext(cRandom* rng) : m_rng(rng) { ; }
~cAvidaContext() { ; }
- int GetRandomID() { return m_rng_id; }
+ void SetRandom(cRandom& rng) { m_rng = &rng; }
+ void SetRandom(cRandom* rng) { m_rng = rng; }
+ cRandom& GetRandom() { return *m_rng; }
};
#endif
Modified: development/source/main/cFitnessMatrix.cc
===================================================================
--- development/source/main/cFitnessMatrix.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/main/cFitnessMatrix.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -22,7 +22,7 @@
m_DFS_NumRecorded(0)
{
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
m_start_genotype.SetNumInstructions( m_inst_set->GetSize());
m_start_genotype.CalcFitness(ctx);
@@ -126,7 +126,7 @@
// MyCodeArrayLessThan myLess;
// @DMB - Warning: Creating context out of band.
- cAvidaContext ctx(0);
+ cAvidaContext ctx(m_world->GetRandom());
for (list_iter = theMutants.begin(); list_iter != theMutants.end(); list_iter++)
{
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2006-03-15 04:45:51 UTC (rev 521)
+++ development/source/main/cPopulation.cc 2006-03-17 12:01:57 UTC (rev 522)
@@ -1750,7 +1750,7 @@
schedule = new cConstSchedule(cell_array.GetSize());
break;
case SLICE_PROB_MERIT:
- schedule = new cProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(1000000000));
+ schedule = new cProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF));
break;
case SLICE_INTEGRATED_MERIT:
schedule = new cIntegratedSchedule(cell_array.GetSize());
More information about the Avida-cvs
mailing list