parallel_batch.h
Go to the documentation of this file.
00001 #ifndef PARALLEL_BATCH_H
00002 #define PARALLEL_BATCH_H
00003 
00004 #include "parallel_common.h"
00005 
00006 namespace parallel_ode
00007 {
00008 
00009 namespace BatchTypes
00010 {
00012   enum BatchType { BATCH_RANDOM,
00013                    BATCH_GREEDY,
00014                    BATCH_COLORED,
00015                    DEFAULT_BATCH_TYPE = BATCH_RANDOM };
00016 }
00017 typedef BatchTypes::BatchType BatchType;
00018 
00020 
00025 class BatchStrategy
00026 {
00027 public:
00028 
00029   typedef IntVector BatchVector;
00030 
00036   BatchStrategy( int maxBatches = ParallelOptions::MAXBATCHES )
00037       :  maxBatches_( maxBatches ),
00038          bAlign_( false ),
00039          alignment_( ParallelOptions::DEFAULTALIGN ) {
00040 
00041   }
00042 
00046   virtual ~BatchStrategy( ) { }
00047 
00063   virtual int batch( const int* pairList, const int numConstraints, const int numBodies,
00064                      BatchVector& constraintIndices,
00065                      BatchVector& bodyRepetitionCount0,
00066                      BatchVector& bodyRepetitionCount1,
00067                      BatchVector& maxBodyRepetitionCountInBatch,
00068                      BatchVector& batchIndices,
00069                      BatchVector& batchSizes );
00070 
00071   inline int getMaxBatches() const { return maxBatches_; }
00072   inline void setMaxBatches( int maxBatches ) { maxBatches_ = maxBatches_; }
00073 
00074   inline bool isAligning() const { return bAlign_; }
00075   inline void setAlign( bool bAlign ) { bAlign_ = bAlign; }
00076 
00077   inline int getAlignment() const { return alignment_; }
00078   inline void setAlignment( int alignment ) { alignment_ = alignment; }
00079 
00080 protected:
00081 
00087   int baseBatch( const int* pairList,
00088                  const BatchVector& constraintIndices,
00089                  const BatchVector& batchSizes,
00090                  BatchVector& batchIndices,
00091                  BatchVector& bodyRepetitionCount0,
00092                  BatchVector& bodyRepetitionCount1,
00093                  BatchVector& maxBodyRepetitionCountInBatch );
00094 
00100   int batchRepetitionCount( const int* pairList,
00101                             const BatchVector& constraintIndices,
00102                             const BatchVector& batchIndices,
00103                             BatchVector& bodyRepetitionCount0,
00104                             BatchVector& bodyRepetitionCount1,
00105                             BatchVector& maxBodyRepetitionCountInBatch );
00106 
00115   static void batchIndicesFromBatchSizes( const BatchVector& batchSizes, BatchVector& batchIndices, bool bAlign, int alignment );
00116 
00117 private:
00118 
00119   int maxBatches_;                      
00120   bool bAlign_;                         
00121   int alignment_;                       
00122 };
00123 
00125 
00126 //* A greedy batch strategy
00130 class GreedyBatchStrategy : public BatchStrategy
00131 {
00132 
00133 public:
00134 
00140   GreedyBatchStrategy( int maxBatches = ParallelOptions::MAXBATCHES ) : BatchStrategy( maxBatches ) { }
00141 
00146   virtual int batch( const int* pairList, const int numPairs, const int numBodies,
00147                      BatchVector& bodyRepetitionCount0,
00148                      BatchVector& bodyRepetitionCount1,
00149                      BatchVector& maxBodyRepetitionCountInBatch,
00150                      BatchVector& constraintIndices,
00151                      BatchVector& batchIndices,
00152                      BatchVector& batchSizes );
00153 
00154 };
00155 
00157 
00158 //* A coloring batch strategy
00162 class ColoringBatchStrategy : public BatchStrategy
00163 {
00164 
00165 public:
00166 
00172   ColoringBatchStrategy( int maxBatches =  ParallelOptions::MAXBATCHES ) : BatchStrategy( maxBatches ) { }
00173 
00177   virtual int batch( const int* pairList, const int numPairs, const int numBodies,
00178                      BatchVector& bodyRepetitionCount0,
00179                      BatchVector& bodyRepetitionCount1,
00180                      BatchVector& maxBodyRepetitionCountInBatch,
00181                      BatchVector& constraintIndices,
00182                      BatchVector& batchIndices,
00183                      BatchVector& batchSizes );
00184 
00185 };
00186 
00188 
00192 class BatchStrategyFactory
00193 {
00194 public:
00195 
00206   static BatchStrategy* create( BatchType batchType, int numBatches, bool bAlign = false, int alignment = ParallelOptions::DEFAULTALIGN )
00207   {
00208     BatchStrategy* newStrategy = NULL;
00209     switch(batchType)
00210     {
00211       case BatchTypes::BATCH_RANDOM:
00212         newStrategy = new BatchStrategy( numBatches );
00213         break;
00214       case BatchTypes::BATCH_GREEDY:
00215         newStrategy = new GreedyBatchStrategy( numBatches );
00216         break;
00217       case BatchTypes::BATCH_COLORED:
00218       default:
00219         newStrategy = new ColoringBatchStrategy( numBatches );
00220         break;
00221     }
00222     newStrategy->setAlign( bAlign );
00223     newStrategy->setAlignment( alignment );
00224     return newStrategy;
00225   }
00226 };
00227 
00228 }
00229 
00230 #endif


parallel_quickstep
Author(s): Jared Duke
autogenerated on Wed Apr 23 2014 10:23:51