[Avida-SVN] r2539 - in branches/jobScheduling/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Apr 18 08:25:46 PDT 2008
Author: beckma24
Date: 2008-04-18 11:25:45 -0400 (Fri, 18 Apr 2008)
New Revision: 2539
Modified:
branches/jobScheduling/source/cpu/cHardwareCPU.cc
branches/jobScheduling/source/cpu/cHardwareCPU.h
branches/jobScheduling/source/main/cAvidaConfig.h
branches/jobScheduling/source/main/cDeme.cc
branches/jobScheduling/source/main/cDeme.h
branches/jobScheduling/source/main/cOrganism.cc
branches/jobScheduling/source/main/cOrganism.h
branches/jobScheduling/source/main/cPopulation.cc
branches/jobScheduling/source/main/cPopulationInterface.cc
branches/jobScheduling/source/main/cTaskLib.cc
branches/jobScheduling/source/main/cTaskLib.h
Log:
Added some more event specific instructions and tasks.
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -212,6 +212,7 @@
// Data collection
tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData, nInstFlag::STALL),
tInstLibEntry<tMethod>("kill-cell-event", &cHardwareCPU::Inst_KillCellEvent, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("kill-faced-cell-event", &cHardwareCPU::Inst_KillFacedCellEvent, nInstFlag::STALL),
tInstLibEntry<tMethod>("collect-cell-data-and-kill-event", &cHardwareCPU::Inst_CollectCellDataAndKillEvent, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-rnd", &cHardwareCPU::Inst_DonateRandom, nInstFlag::STALL),
@@ -234,6 +235,7 @@
tInstLibEntry<tMethod>("rotate-label", &cHardwareCPU::Inst_RotateLabel, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-unoccupied-cell", &cHardwareCPU::Inst_RotateUnoccupiedCell, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-occupied-cell", &cHardwareCPU::Inst_RotateOccupiedCell, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("rotate-to-event-cell", &cHardwareCPU::Inst_RotateEventCell, nInstFlag::STALL),
tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
@@ -248,6 +250,7 @@
tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move, nInstFlag::STALL),
tInstLibEntry<tMethod>("move-to-event", &cHardwareCPU::Inst_MoveToEvent, nInstFlag::STALL),
tInstLibEntry<tMethod>("if-event-in-unoccupied-neighbor-cell", &cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell),
+ tInstLibEntry<tMethod>("if-event-in-faced-cell", &cHardwareCPU::Inst_IfFacingEventCell),
// Threading instructions
tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
@@ -3254,11 +3257,27 @@
if((organism->GetOrgInterface().GetDemeID() < 0) || (organism->GetCellID() < 0))
return false;
+ const int reg = FindModifiedRegister(REG_BX);
int eventID = organism->GetCellData();
- organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
+ GetRegister(reg) = organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
return true;
}
+bool cHardwareCPU::Inst_KillFacedCellEvent(cAvidaContext& ctx) {
+ // Fail if we're running in the test CPU.
+ if((organism->GetOrgInterface().GetDemeID() < 0) || (organism->GetCellID() < 0))
+ return false;
+
+ const int reg = FindModifiedRegister(REG_BX);
+ int eventID = organism->GetNeighborCellContents();
+ GetRegister(reg) = organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
+
+ if(GetRegister(reg))
+ organism->SetEventKilled();
+
+ return true;
+}
+
bool cHardwareCPU::Inst_CollectCellDataAndKillEvent(cAvidaContext& ctx) {
// Fail if we're running in the test CPU.
if((organism->GetOrgInterface().GetDemeID() < 0) || (organism->GetCellID() < 0))
@@ -3946,12 +3965,12 @@
const int reg_used = FindModifiedRegister(REG_BX);
for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
- if(!organism->IsNeighborCellOccupied()) // continue to rotate
+ if(!organism->IsNeighborCellOccupied()) // faced cell is unoccupied
{
GetRegister(reg_used) = 1;
return true;
}
- organism->Rotate(1);
+ organism->Rotate(1); // continue to rotate
}
GetRegister(reg_used) = 0;
return true;
@@ -3961,17 +3980,31 @@
const int reg_used = FindModifiedRegister(REG_BX);
for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
- if(organism->IsNeighborCellOccupied()) { // continue to rotate
+ if(organism->IsNeighborCellOccupied()) { // faced cell is occupied
GetRegister(reg_used) = 1;
return true;
}
- organism->Rotate(1);
+ organism->Rotate(1); // continue to rotate
}
GetRegister(reg_used) = 0;
return true;
}
+bool cHardwareCPU::Inst_RotateEventCell(cAvidaContext& ctx) {
+ const int reg_used = FindModifiedRegister(REG_BX);
+
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ if(organism->GetCellData() > 0) { // event in faced cell
+ GetRegister(reg_used) = 1;
+ return true;
+ }
+ organism->Rotate(1); // continue to rotate
+ }
+ GetRegister(reg_used) = 0;
+ return true;
+}
+
bool cHardwareCPU::Inst_SetCopyMut(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_BX);
@@ -4054,13 +4087,12 @@
int orginalFacing = organism->GetFacing();
for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
- if(organism->IsNeighborCellOccupied()) // cannot move into occupied cell
- organism->Rotate(1);
- else if(organism->GetNeighborCellContents() > 0) {
+ if(organism->GetNeighborCellContents() > 0) {
Inst_Move(ctx);
GetRegister(reg_used) = 1;
return true;
}
+ organism->Rotate(1);
}
assert(organism->GetFacing() == orginalFacing);
@@ -4068,22 +4100,28 @@
return true;
}
-
bool cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx) {
int orginalFacing = organism->GetFacing();
for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
- if(organism->IsNeighborCellOccupied()) // cannot move into occupied cell
- organism->Rotate(1);
- else if(organism->GetNeighborCellContents() > 0) {
+ if(organism->GetNeighborCellContents() > 0 && !organism->IsNeighborCellOccupied()) {
return true;
}
+ organism->Rotate(1);
}
assert(organism->GetFacing() == orginalFacing);
IP().Advance();
return true;
}
+bool cHardwareCPU::Inst_IfFacingEventCell(cAvidaContext& ctx) {
+ if(organism->GetNeighborCellContents() > 0) {
+ return true;
+ }
+ IP().Advance();
+ return true;
+}
+
// Multi-threading.
bool cHardwareCPU::Inst_ForkThread(cAvidaContext& ctx)
{
@@ -4931,7 +4969,8 @@
}
bool cHardwareCPU::Inst_Alarm_MSG(cAvidaContext& ctx) {
- return organism->BcastAlarmMSG(ctx, 1); // jump to Alarm-label-high
+ const int reg_used = FindModifiedRegister(REG_BX);
+ return organism->BcastAlarmMSG(ctx, GetRegister(reg_used)%2); // jump to Alarm-label- odd=high even=low
}
bool cHardwareCPU::Inst_Alarm_MSG_Bit_Cons24(cAvidaContext& ctx) {
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-18 15:25:45 UTC (rev 2539)
@@ -462,6 +462,7 @@
bool Inst_IfResources(cAvidaContext& ctx);
bool Inst_CollectCellData(cAvidaContext& ctx);
bool Inst_KillCellEvent(cAvidaContext& ctx);
+ bool Inst_KillFacedCellEvent(cAvidaContext& ctx);
bool Inst_CollectCellDataAndKillEvent(cAvidaContext& ctx);
void DoDonate(cOrganism * to_org);
@@ -492,6 +493,7 @@
bool Inst_RotateLabel(cAvidaContext& ctx);
bool Inst_RotateOccupiedCell(cAvidaContext& ctx);
bool Inst_RotateUnoccupiedCell(cAvidaContext& ctx);
+ bool Inst_RotateEventCell(cAvidaContext& ctx);
bool Inst_SetCopyMut(cAvidaContext& ctx);
bool Inst_ModCopyMut(cAvidaContext& ctx);
bool Inst_GetCellPosition(cAvidaContext& ctx);
@@ -504,6 +506,7 @@
bool Inst_Move(cAvidaContext& ctx);
bool Inst_MoveToEvent(cAvidaContext& ctx);
bool Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx);
+ bool Inst_IfFacingEventCell(cAvidaContext& ctx);
// Multi-threading...
Modified: branches/jobScheduling/source/main/cAvidaConfig.h
===================================================================
--- branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-18 15:25:45 UTC (rev 2539)
@@ -283,6 +283,8 @@
CONFIG_ADD_VAR(RANDOM_SEED, int, 0, "Random number seed (0 for based on time)");
CONFIG_ADD_VAR(HARDWARE_TYPE, int, 0, "0 = Original CPUs\n1 = New SMT CPUs\n2 = Transitional SMT\n3 = Experimental CPU\n4 = Gene Expression CPU");
CONFIG_ADD_VAR(SPECULATIVE, bool, 1, "Enable speculative execution");
+ CONFIG_ADD_VAR(BCAST_HOPS, int, 1, "Number of hops to broadcast an alarm");
+ CONFIG_ADD_VAR(ALARM_SELF, bool, 0, "Does sending an alarm move sender IP to alarm label?\n0=no\n1=yes");
CONFIG_ADD_GROUP(CONFIG_FILE_GROUP, "Configuration Files");
CONFIG_ADD_VAR(DATA_DIR, cString, "data", "Directory in which config files are found");
Modified: branches/jobScheduling/source/main/cDeme.cc
===================================================================
--- branches/jobScheduling/source/main/cDeme.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cDeme.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -332,9 +332,9 @@
}
}
-void cDeme::KillCellEvent(const int eventID) {
+bool cDeme::KillCellEvent(const int eventID) {
if(eventID <= 0)
- return;
+ return false;
for(int i = 0; i < cell_events.GetSize(); i++) {
cDemeCellEvent& event = cell_events[i];
if(event.IsActive() && event.GetEventID() == eventID) {
@@ -350,8 +350,10 @@
event.DeactivateEvent(); //event over
eventsKilled++;
eventsKilledThisSlot++;
+ return true;
}
}
+ return false;
}
double cDeme::CalculateTotalEnergy() {
Modified: branches/jobScheduling/source/main/cDeme.h
===================================================================
--- branches/jobScheduling/source/main/cDeme.h 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cDeme.h 2008-04-18 15:25:45 UTC (rev 2539)
@@ -169,7 +169,7 @@
bool static_position, int m_total_slots, int m_total_events_per_slot_max,
int m_total_events_per_slot_min, int m_tolal_event_flow_levels);
- void KillCellEvent(const int eventID);
+ bool KillCellEvent(const int eventID);
cDemeCellEvent* GetCellEvent(const int i) { return &cell_events[i]; };
int GetNumCellEvents() const { return cell_events.GetSize(); }
Modified: branches/jobScheduling/source/main/cOrganism.cc
===================================================================
--- branches/jobScheduling/source/main/cOrganism.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cOrganism.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -70,6 +70,7 @@
, m_is_running(false)
, m_is_sleeping(false)
, m_is_dead(false)
+ , killed_event(false)
, m_net(NULL)
, m_msg(0)
{
Modified: branches/jobScheduling/source/main/cOrganism.h
===================================================================
--- branches/jobScheduling/source/main/cOrganism.h 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cOrganism.h 2008-04-18 15:25:45 UTC (rev 2539)
@@ -124,6 +124,8 @@
bool m_is_sleeping; // Is this organisms sleeping?
bool m_is_dead; // Is this organism dead?
+ bool killed_event;
+
class cNetSupport
{
public:
@@ -362,6 +364,9 @@
void DivideOrgTestamentAmongDeme(double value) { m_interface->DivideOrgTestamentAmongDeme(value); }
+
+ void SetEventKilled() { killed_event = true; }
+ bool GetEventKilled() { return killed_event; }
};
Modified: branches/jobScheduling/source/main/cPopulation.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulation.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cPopulation.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -1149,7 +1149,13 @@
}
case 5: {
int currentSlotSuccessful = 0;
- double kill_ratio = static_cast<double>(source_deme.GetEventsKilledThisSlot()) / static_cast<double>(source_deme.GetSlotFlowRate());
+ double kill_ratio = 0.0;
+
+ if(source_deme.GetSlotFlowRate() == 0)
+ kill_ratio = 1.0;
+ else
+ kill_ratio = static_cast<double>(source_deme.GetEventsKilledThisSlot()) / static_cast<double>(source_deme.GetSlotFlowRate());
+
if(kill_ratio >= m_world->GetConfig().DEMES_MIM_EVENTS_KILLED_RATIO.Get())
currentSlotSuccessful = 1;
Modified: branches/jobScheduling/source/main/cPopulationInterface.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulationInterface.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cPopulationInterface.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -277,21 +277,53 @@
bool cPopulationInterface::BcastAlarm(int jump_label) {
- cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
- assert(cell.IsOccupied()); // This organism; sanity.
+ bool successfully_sent(false);
+ cPopulationCell& scell = m_world->GetPopulation().GetCell(m_cell_id);
+ assert(scell.IsOccupied()); // This organism; sanity.
+
+ const int BCAST_RANGE = m_world->GetConfig().BCAST_HOPS.Get();
+ const int ALARM_SELF = m_world->GetConfig().ALARM_SELF.Get(); // does an alarm affect the sender; 0=no non-0=yes
- for(int i = 0; i < cell.ConnectionList().GetSize(); i++) {
- cPopulationCell* rcell = cell.ConnectionList().GetPos(i);
- assert(rcell != NULL); // Cells should never be null.
+ if(BCAST_RANGE > 1) { // multi-hop messaging
+ cDeme& deme = m_world->GetPopulation().GetDeme(GetDemeID());
+ for(int i = 0; i < deme.GetSize(); i++) {
+ int possible_receiver_id = deme.GetCellID(i);
+ cPopulationCell& rcell = m_world->GetPopulation().GetCell(possible_receiver_id);
+
+ if(rcell.IsOccupied() && possible_receiver_id != GetCellID()) {
+ //check distance
+ pair<int, int> sender_pos = deme.GetCellPosition(GetCellID());
+ pair<int, int> possible_receiver_pos = deme.GetCellPosition(possible_receiver_id);
+ int hop_distance = max( abs(sender_pos.first - possible_receiver_pos.first),
+ abs(sender_pos.second - possible_receiver_pos.second));
+ if(hop_distance <= BCAST_RANGE) {
+ // send alarm to organisms
+ cOrganism* recvr = rcell.GetOrganism();
+ assert(recvr != NULL);
+ recvr->moveIPtoAlarmLabel(jump_label);
+ successfully_sent = true;
+ }
+ }
+ }
+ } else { // single hop messaging
+ for(int i = 0; i < scell.ConnectionList().GetSize(); i++) {
+ cPopulationCell* rcell = scell.ConnectionList().GetPos(i);
+ assert(rcell != NULL); // Cells should never be null.
- // Fail if the cell we're facing is not occupied.
- if(!rcell->IsOccupied())
- continue;
- cOrganism* recvr = rcell->GetOrganism();
- assert(recvr != NULL);
- recvr->moveIPtoAlarmLabel(jump_label);
+ // Fail if the cell we're facing is not occupied.
+ if(!rcell->IsOccupied())
+ continue;
+ cOrganism* recvr = rcell->GetOrganism();
+ assert(recvr != NULL);
+ recvr->moveIPtoAlarmLabel(jump_label);
+ successfully_sent = true;
+ }
}
- return true;
+
+ if(ALARM_SELF) {
+ scell.GetOrganism()->moveIPtoAlarmLabel(jump_label);
+ }
+ return successfully_sent;
}
void cPopulationInterface::DivideOrgTestamentAmongDeme(double value){
Modified: branches/jobScheduling/source/main/cTaskLib.cc
===================================================================
--- branches/jobScheduling/source/main/cTaskLib.cc 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cTaskLib.cc 2008-04-18 15:25:45 UTC (rev 2539)
@@ -388,6 +388,8 @@
//movement
if(name == "move_to_event")
NewTask(name, "Moved into cell containing event", &cTaskLib::Task_MoveToEvent);
+ else if(name == "event_killed")
+ NewTask(name, "Killed event", &cTaskLib::Task_EventKilled);
// Make sure we have actually found a task
if (task_array.GetSize() == start_size) {
@@ -2851,3 +2853,9 @@
}
return 0.0;
}
+
+double cTaskLib::Task_EventKilled(cTaskContext& ctx) const {
+ if(ctx.GetOrganism()->GetEventKilled())
+ return 1.0;
+ return 0.0;
+}
Modified: branches/jobScheduling/source/main/cTaskLib.h
===================================================================
--- branches/jobScheduling/source/main/cTaskLib.h 2008-04-18 14:26:58 UTC (rev 2538)
+++ branches/jobScheduling/source/main/cTaskLib.h 2008-04-18 15:25:45 UTC (rev 2539)
@@ -281,6 +281,7 @@
// movement
double Task_MoveToEvent(cTaskContext& ctx) const;
+ double Task_EventKilled(cTaskContext& ctx) const;
};
More information about the Avida-cvs
mailing list