[Avida-SVN] r3102 - in development: Avida.xcodeproj source/actions source/analyze

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sun Jan 11 09:42:53 PST 2009


Author: brysonda
Date: 2009-01-11 12:42:53 -0500 (Sun, 11 Jan 2009)
New Revision: 3102

Added:
   development/source/analyze/tAnalyzeJobBatch.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/actions/LandscapeActions.cc
Log:
Add general purpose analyze job batch class.  This class can be used to build asynchronous multipart jobs for execution in cAnalyzeJobQueue.   The advantage of such batches is that they can be submitted and completed regardless of other activity in the queue.   Once the queue becomes a true global resource this will be particularly important.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2009-01-11 17:36:58 UTC (rev 3101)
+++ development/Avida.xcodeproj/project.pbxproj	2009-01-11 17:42:53 UTC (rev 3102)
@@ -34,7 +34,6 @@
 		56F555E70C3B402A00E2E929 /* viewer-text.cc in Sources */ = {isa = PBXBuildFile; fileRef = 56F555E40C3B402A00E2E929 /* viewer-text.cc */; };
 		700E2996085A1F6000CF158A /* avida in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* avida */; };
 		700E2B87085DE54400CF158A /* avida-viewer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 700E2B83085DE50C00CF158A /* avida-viewer */; };
-		701B5F170EEEF3030073ACB4 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
 		70211A5D0ECBD531004A293A /* cRCObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 70211A5B0ECBD531004A293A /* cRCObject.h */; };
 		70211A5E0ECBD531004A293A /* cRCObject.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70211A5C0ECBD531004A293A /* cRCObject.cc */; };
 		7023EC3A0C0A431B00362B9C /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
@@ -395,6 +394,7 @@
 		7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cTestCPUInterface.cc; sourceTree = "<group>"; };
 		7005A70909BA0FBE0007E16E /* cOrgInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgInterface.h; sourceTree = "<group>"; };
 		700AE91B09DB65F200A073FD /* cTaskContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTaskContext.h; sourceTree = "<group>"; };
+		700D9BD90F1A5D33002CC711 /* tAnalyzeJobBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tAnalyzeJobBatch.h; sourceTree = "<group>"; };
 		700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
 		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
 		7013845F09028B3E0087ED2E /* cAvidaConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAvidaConfig.h; sourceTree = "<group>"; };
@@ -1048,6 +1048,7 @@
 				70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */,
 				70AD4F990F194D2400AA50AC /* cGenotypeData.h */,
 				70AD4F9E0F194DD400AA50AC /* cGenotypeData.cc */,
+				700D9BD90F1A5D33002CC711 /* tAnalyzeJobBatch.h */,
 			);
 			path = analyze;
 			sourceTree = "<group>";
@@ -2134,7 +2135,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */,
-				701B5F170EEEF3030073ACB4 /* cPhenPlastGenotype.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2009-01-11 17:36:58 UTC (rev 3101)
+++ development/source/actions/LandscapeActions.cc	2009-01-11 17:42:53 UTC (rev 3102)
@@ -28,7 +28,6 @@
 #include "cActionLibrary.h"
 #include "cAnalyze.h"
 #include "cAnalyzeGenotype.h"
-#include "tAnalyzeJob.h"
 #include "cClassificationManager.h"
 #include "cGenotype.h"
 #include "cGenotypeBatch.h"
@@ -45,7 +44,10 @@
 #include "cString.h"
 #include "cWorld.h"
 #include "cWorldDriver.h"
+#include "tAnalyzeJob.h"
+#include "tAnalyzeJobBatch.h"
 #include "tSmartArray.h"
+
 #include "defs.h"
 
 
@@ -186,12 +188,12 @@
         m_world->GetDriver().NotifyComment("Precalculating landscape...");
       }
       
-      cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();      
+      tAnalyzeJobBatch<cAnalyzeGenotype> jobbatch(m_world->GetAnalyze().GetJobQueue());
       tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
       for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
-        jobqueue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
+        jobbatch.AddJob(cur_genotype, &cAnalyzeGenotype::CalcLandscape);
       }
-      jobqueue.Execute();
+      jobbatch.RunBatch();
     }
   }
 };

Added: development/source/analyze/tAnalyzeJobBatch.h
===================================================================
--- development/source/analyze/tAnalyzeJobBatch.h	                        (rev 0)
+++ development/source/analyze/tAnalyzeJobBatch.h	2009-01-11 17:42:53 UTC (rev 3102)
@@ -0,0 +1,95 @@
+/*
+ *  tAnalyzeJobBatch.h
+ *  Avida
+ *
+ *  Created by David on 1/11/09.
+ *  Copyright 2009 Digital Evolution Laboratory : Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef tAnalyzeJobBatch_h
+#define tAnalyzeJobBatch_h
+
+#include "cConditionVariable.h"
+#include "cMutex.h"
+#include "cAnalyzeJobQueue.h"
+#include "tAnalyzeJob.h"
+
+class cAvidaContext;
+
+
+template<class JobClass> class tAnalyzeJobBatch
+{
+protected:
+  template<class T> class tAnalyzeBatchJob;
+  friend class tAnalyzeBatchJob<JobClass>;
+  
+protected:
+  cAnalyzeJobQueue& m_queue;
+  
+  int m_jobs;
+  
+  cMutex m_mutex;
+  cConditionVariable m_cond;
+  
+  
+public:
+  tAnalyzeJobBatch(cAnalyzeJobQueue& queue) : m_queue(queue), m_jobs(0) { ; }
+  
+  void AddJob(JobClass* target, void (JobClass::*funJ)(cAvidaContext&))
+  {
+    m_mutex.Lock();
+    m_jobs++;
+    m_mutex.Unlock();
+    m_queue.AddJob(new tAnalyzeBatchJob<JobClass>(this, target, funJ));
+  }
+  
+  void RunBatch()
+  {
+    m_queue.Start();
+    m_mutex.Lock();
+    while (m_jobs > 0) {
+      m_cond.Wait(m_mutex);
+    }
+    m_mutex.Unlock();
+  }
+  
+protected:
+  template<class T> class tAnalyzeBatchJob : public tAnalyzeJob<T>
+  {
+  protected:
+    tAnalyzeJobBatch<T>* m_batch;
+    
+  public:
+    tAnalyzeBatchJob(tAnalyzeJobBatch<T>* batch, T* target, void (T::*funJ)(cAvidaContext&))
+      : tAnalyzeJob<T>(target, funJ), m_batch(batch) { ; }
+    
+    void Run(cAvidaContext& ctx)
+    {
+      tAnalyzeJob<T>::Run(ctx);
+      
+      m_batch->m_mutex.Lock();
+      m_batch->m_jobs--;
+      m_batch->m_mutex.Unlock();
+      m_batch->m_cond.Signal();
+    }
+  };
+};
+
+
+#endif




More information about the Avida-cvs mailing list