[Avida-SVN] r3177 - in branches/interrupt/source: actions cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Mar 6 13:58:10 PST 2009


Author: beckma24
Date: 2009-03-06 16:58:10 -0500 (Fri, 06 Mar 2009)
New Revision: 3177

Modified:
   branches/interrupt/source/actions/PopulationActions.cc
   branches/interrupt/source/actions/PrintActions.cc
   branches/interrupt/source/cpu/cHardwareCPU.cc
   branches/interrupt/source/cpu/cOrganismThread.h
   branches/interrupt/source/main/cDeme.cc
   branches/interrupt/source/main/cDeme.h
   branches/interrupt/source/main/cOrganism.cc
   branches/interrupt/source/main/cOrganism.h
   branches/interrupt/source/main/cPopulation.cc
   branches/interrupt/source/main/cPopulationInterface.cc
   branches/interrupt/source/main/cStats.cc
   branches/interrupt/source/main/cStats.h
Log:
Add print action PrintDemeInterruptMsgType and deme replication type 'set-opinion'.  Also, optimized and simplified some commonly used code.  All tests pass.

Modified: branches/interrupt/source/actions/PopulationActions.cc
===================================================================
--- branches/interrupt/source/actions/PopulationActions.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/actions/PopulationActions.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -1955,6 +1955,8 @@
     'sat-mov-pred'  - ...demes whose movement predicate was previously satisfied
     'events-killed' ...demes that have killed a certian number of events
     'sat-msg-pred'  - ...demes whose message predicate was previously satisfied
+		'set-opinion'   - ...full demes containing orgs who have all set an opinion
+
 */
 
 class cActionReplicateDemes : public cAction
@@ -1976,6 +1978,7 @@
     else if (in_trigger == "sat-mov-pred") m_rep_trigger = 5;
     else if (in_trigger == "events-killed") m_rep_trigger = 6;
     else if (in_trigger == "sat-msg-pred") m_rep_trigger = 7;
+		else if (in_trigger == "set-opinion") m_rep_trigger = 8;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;

Modified: branches/interrupt/source/actions/PrintActions.cc
===================================================================
--- branches/interrupt/source/actions/PrintActions.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/actions/PrintActions.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -115,7 +115,9 @@
 STATS_OUT_FILE(PrintDemeCurrentTaskExeData,	deme_cur_task_exe.dat	);
 STATS_OUT_FILE(PrintDemeMigrationSuicidePoints,	deme_mig_suicide_points.dat	);
 STATS_OUT_FILE(PrintDemeInterrupt,					deme_interrupt.dat	);
+STATS_OUT_FILE(PrintDemeInterruptMsgType,		deme_interruptMsgType.dat	);
 
+
 STATS_OUT_FILE(PrintCurrentTaskCounts,      curr_task_counts.dat);
 STATS_OUT_FILE(PrintGermlineData,           germline.dat        );
 STATS_OUT_FILE(PrintPredicatedMessages,     messages.dat        );

Modified: branches/interrupt/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/cpu/cHardwareCPU.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -181,6 +181,7 @@
 				}
 
 				if(initializeInterruptState(msgHandlerString)) {
+					interruptMessageType = messageType;
 					hardware->IP().Retreat();
 					hardware->Inst_RetrieveMessage(m_world->GetDefaultContext());
 					hardware->IP().Advance();
@@ -209,12 +210,14 @@
 			}
 			
 			if(initializeInterruptState(msgHandlerString)) {
+				interruptMessageType = messageType;
 				hardware->IP().Retreat();
 				hardware->Inst_RetrieveMessage(m_world->GetDefaultContext());
 				hardware->IP().Advance();
 			}
 		} else { // interrupt -> normal
 			interrupted = false;
+			interruptMessageType = -1;
 			restoreState();
 		}
 	}
@@ -255,6 +258,7 @@
 	pushedState.next_label.Clear();
   
 	interrupted = false;
+	interruptMessageType = -1;
 	
   // Promoter model
   m_promoter_inst_executed = 0;

Modified: branches/interrupt/source/cpu/cOrganismThread.h
===================================================================
--- branches/interrupt/source/cpu/cOrganismThread.h	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/cpu/cOrganismThread.h	2009-03-06 21:58:10 UTC (rev 3177)
@@ -18,14 +18,16 @@
 protected:
 	int m_id;
 	bool interrupted;        //<! is thread interrupted
+	int interruptMessageType;
 
 public:
-	cOrganismThread() : m_id(-1), interrupted(false) {;}
+	cOrganismThread() : m_id(-1), interrupted(false), interruptMessageType(-1) {;}
 	virtual ~cOrganismThread() {;}
 	
 	int GetID() const { return m_id; }
 	void SetID(int in_id) { m_id = in_id; }
 	bool isInterrupted() const { return interrupted; }
+	int getInterruptMessageType() const { return interruptMessageType; }
 	
 	virtual void saveState() = 0;  //!< saves thread's current state
 	virtual void restoreState() = 0;  //!< restores thread's saved state

Modified: branches/interrupt/source/main/cDeme.cc
===================================================================
--- branches/interrupt/source/main/cDeme.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cDeme.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -863,3 +863,15 @@
 	} //End if world is a torus
 	
 } //End GetSurroundingCellIds()
+
+
+// return true if all organisms in deme have perviously set an opinion OR if the deme is empty
+bool cDeme::allOrgsHaveSetOpinion() {
+  for (int i=0; i<GetSize(); ++i) {
+		cOrganism* org = GetCell(i).GetOrganism();
+    if(org != NULL && !org->HasOpinion()) {
+			return false;
+		}
+  }
+	return true;
+}

Modified: branches/interrupt/source/main/cDeme.h
===================================================================
--- branches/interrupt/source/main/cDeme.h	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cDeme.h	2009-03-06 21:58:10 UTC (rev 3177)
@@ -335,8 +335,10 @@
 	void ClearMigrationOut() { migrations_out = 0; }
 	void ClearMigrationIn() { migrations_in = 0; }
 	void ClearSuicides() { suicides = 0; }
-
 	
+	// ----Opinions--- //
+	bool allOrgsHaveSetOpinion();
+	
   void GetSurroundingCellIds(tVector<int> &cells, const int absolute_cell_id, const int radius);
 };
 

Modified: branches/interrupt/source/main/cOrganism.cc
===================================================================
--- branches/interrupt/source/main/cOrganism.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cOrganism.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -652,10 +652,12 @@
 	std::pair<int, int> pos = m_world->GetPopulation().GetDeme(GetOrgInterface().GetDemeID()).GetCellPosition(GetCellID());
 	fp << "Location: (" << pos.first << "," << pos.second << ")\n";
 	
-	if(m_world->GetConfig().INTERRUPT_ENABLED.Get() == 1) {
-		cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
-		if(currentThread->isInterrupted())
+	static const bool INTERRUPT_ENABLED = m_world->GetConfig().INTERRUPT_ENABLED.Get();
+	if(INTERRUPT_ENABLED) {
+		if(isInterrupted()) {
+			cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
 			fp << "Interrupted: Saved IP " << (currentThread->pushedState.heads[0]).GetPosition() << endl;
+		}
 		else
 			fp << "NOT Interrupted " <<endl;
 	}
@@ -866,10 +868,12 @@
     m_msg->received.push_back(msg);
   }
 	
-	
+	static const bool INTERRUPT_ENABLED = m_world->GetConfig().INTERRUPT_ENABLED.Get();
+	if(INTERRUPT_ENABLED) {
 	cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
-	if(m_world->GetConfig().INTERRUPT_ENABLED.Get() && currentThread->isInterrupted() == false) {
-		currentThread->interruptContextSwitch(cLocalThread::MSG_INTERRUPT);
+		if(currentThread->isInterrupted() == false) {
+			currentThread->interruptContextSwitch(cLocalThread::MSG_INTERRUPT);
+		}
 	}
 	// else msg gets added to msg queue and will cause interrupt after current interrupt is processed
 }
@@ -973,3 +977,21 @@
   m_world->GetStats().SentFlash(*this);
   DoOutput(ctx);
 }
+
+////////////////////
+// Interrupt Model//
+////////////////////
+
+// is the organism currently interrupted?
+bool cOrganism::isInterrupted() {
+	// retruns true if current thread is interrupted
+	cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
+	return currentThread->isInterrupted();
+}
+
+// is the organism currently interrupted?
+int cOrganism::getInterruptedMessageType() {
+	cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
+	return currentThread->getInterruptMessageType();
+}
+

Modified: branches/interrupt/source/main/cOrganism.h
===================================================================
--- branches/interrupt/source/main/cOrganism.h	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cOrganism.h	2009-03-06 21:58:10 UTC (rev 3177)
@@ -440,11 +440,9 @@
 
   
   /***** context switch********/
-	bool isInterrupted() {
-		// retruns true if current thread is interrupted
-		cLocalThread* currentThread = static_cast<cHardwareCPU*>(m_hardware)->GetThread(m_hardware->GetCurThread());
-		return currentThread->isInterrupted();
-	}
+	bool isInterrupted();
+	int getInterruptedMessageType();
+	
   bool BcastAlarmMSG(cAvidaContext& ctx, int jump_label, int bcast_range);
   void moveIPtoAlarmLabel(int jump_label);
   

Modified: branches/interrupt/source/main/cPopulation.cc
===================================================================
--- branches/interrupt/source/main/cPopulation.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cPopulation.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -1237,6 +1237,7 @@
 5: 'sat-mov-pred'...demes whose movement predicate was previously satisfied
 6: 'events-killed' ...demes that have killed a certian number of events
 7: 'sat-msg-pred'...demes whose movement predicate was previously satisfied
+8: 'set-opinion'...full demes containing orgs who have all set an opinion
 
 */
 
@@ -1305,6 +1306,11 @@
         if(!(source_deme.MsgPredSatisfiedPreviously())) continue;
         break;
       }
+			case 8: {
+				if(!source_deme.IsFull() || !source_deme.allOrgsHaveSetOpinion()) 
+					continue; // no
+				break; // yes
+			}
       default: {
         cerr << "ERROR: Invalid replication trigger " << rep_trigger
         << " in cPopulation::ReplicateDemes()" << endl;

Modified: branches/interrupt/source/main/cPopulationInterface.cc
===================================================================
--- branches/interrupt/source/main/cPopulationInterface.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cPopulationInterface.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -290,6 +290,8 @@
 /* Send a message to the given organism */
 bool cPopulationInterface::SendMessage(cOrganism* recvr, cOrgMessage& msg) {
   assert(recvr != NULL);
+	static const double drop_prob = m_world->GetConfig().NET_DROP_PROB.Get();
+	assert(!(drop_prob > 0.0)); // message dropping is not implemented for this type of message sending
   recvr->ReceiveMessage(msg);
   return true;
 } //End SendMessage()

Modified: branches/interrupt/source/main/cStats.cc
===================================================================
--- branches/interrupt/source/main/cStats.cc	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cStats.cc	2009-03-06 21:58:10 UTC (rev 3177)
@@ -1952,8 +1952,8 @@
 		for(int j = 0; j < deme.GetSize() ; ++j) {
 			cOrganism* org = deme.GetOrganism(j);
 			if(org != NULL) {
-				cLocalThread* currentThread = static_cast<cHardwareCPU*>(org->GetHardware(false))->GetThread(org->GetHardware(false)->GetCurThread());
-				if(currentThread->isInterrupted()) {
+//				cLocalThread* currentThread = static_cast<cHardwareCPU*>(org->GetHardware(false))->GetThread(org->GetHardware(false)->GetCurThread());
+				if(org->isInterrupted()) {
 					++numInterrupted;
 				}
 			}
@@ -1963,6 +1963,39 @@
   df.Endl();
 }
 
+void cStats::PrintDemeInterruptMsgType(const cString& filename) {
+	static const int NUM_MESSAGE_TYPES = 8;
+	cDoubleSum variance;
+	cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment("Interrupt model message type stats averaged over all demes");
+	df.WriteComment("Assumes each organism only contains a single thread!");
+	df.WriteTimeStamp();
+	df.Write(m_update,   "Update");
+	int numDemes = m_world->GetPopulation().GetNumDemes();
+  for(int i=0; i<numDemes; ++i) {
+		tArray<int> messagetypes(NUM_MESSAGE_TYPES, 0);
+		cIntSum collecter;
+    cDeme& deme = m_world->GetPopulation().GetDeme(i);
+		for(int j = 0; j < deme.GetSize() ; ++j) {
+			cOrganism* org = deme.GetOrganism(j);
+			if(org != NULL) {
+				if(org->isInterrupted()) {
+					messagetypes[org->getInterruptedMessageType()]++;
+				}
+			}
+		}
+		for(int j = 0; j < NUM_MESSAGE_TYPES; j++) {
+			// for none then skip
+			if(messagetypes[j] > 0)
+				collecter.Add(messagetypes[j]);
+		}
+		variance.Add(collecter.Variance());
+  }
+	
+	df.Write(variance.Average(), "Average variance in demes");
+  df.Endl();
+}
+
 void cStats::CompeteDemes(const std::vector<double>& fitness) {
   m_deme_fitness = fitness;
 }

Modified: branches/interrupt/source/main/cStats.h
===================================================================
--- branches/interrupt/source/main/cStats.h	2009-03-06 21:09:17 UTC (rev 3176)
+++ branches/interrupt/source/main/cStats.h	2009-03-06 21:58:10 UTC (rev 3177)
@@ -843,6 +843,7 @@
   void PrintPerDemeGenPerFounderData(const cString& filename);
 	void PrintDemeMigrationSuicidePoints(const cString& filename);
 	void PrintDemeInterrupt(const cString& filename);
+	void PrintDemeInterruptMsgType(const cString& filename);
 	
 
 




More information about the Avida-cvs mailing list