RecBisection.h

Go to the documentation of this file.
00001 
00007 #ifndef RECBISECTION_H
00008 #define RECBISECTION_H
00009 
00010 #include "converse.h"
00011 
00012 class PatchMap;
00013 
00014 #if USE_TOPOMAP 
00015 /******
00016        NAMD likes the X dimension to be the largest, followed by Y and
00017        then Z. This structure stores the relationsip between x,y,z and
00018        virtualx, virtualy and virtualz.
00019 ***************/
00020 
00021 struct DimensionMap {
00022     int x;
00023     int y; 
00024     int z;
00025 };
00026 
00027 
00028 inline void findOptimalDimensions(int X, int Y, int Z, 
00029                                  int & new_X, int & new_Y, int &new_Z,
00030                                  DimensionMap &dm) {
00031     if(X == Y && Y == Z)
00032         return;
00033     
00034     if(X >= Y) {
00035         if(X >= Z) {
00036             new_X = X;
00037             dm.x = 0;
00038             
00039             if(Z >= Y) {
00040                 new_Y = Z;
00041                 new_Z = Y;
00042                 
00043                 dm.y = 2;
00044                 dm.z = 1;
00045             }
00046             else {
00047                 new_Y = Y;
00048                 new_Z = Z;
00049 
00050                 dm.y = 1;
00051                 dm.z = 2;
00052             }
00053         }
00054         else {
00055             new_X = Z;
00056             new_Y = X;
00057             new_Z = Y;
00058 
00059             dm.x = 1;
00060             dm.y = 2;
00061             dm.z = 0;
00062         }
00063     }
00064     else {
00065         if(Y >= Z) {
00066             new_X = Y;
00067             dm.y  = 0;
00068 
00069             if(Z >= X) {
00070                 new_Y = Z;
00071                 new_Z = X;
00072 
00073                 dm.x  = 2;
00074                 dm.z  = 1;
00075             }
00076             else {
00077                 new_Y = X;
00078                 new_Z = Z;
00079 
00080                 dm.x  = 1;
00081                 dm.z  = 2;              
00082             }
00083         }
00084         else {
00085             new_X = Z;
00086             new_Y = Y;
00087             new_Z = X;
00088 
00089             dm.x = 2;
00090             dm.y = 1;
00091             dm.z = 0;
00092         }
00093     }
00094 }
00095 #endif
00096 
00097 /* *********************************************************************** */
00098 /* This class performs a recursive coordinate bisection partitioning       */
00099 /* together with some communication and computation refinements            */
00100 /* *********************************************************************** */
00101 
00102 #define MAXNEIGHBOUR 26
00103 class RecBisection 
00104 {
00105     private:
00106 
00107       typedef struct {                          // a rectangular prism
00108          float  load;                           // is represented with
00109          struct { int x,y,z; } origin;          // origin and corner coordinates
00110          struct { int x,y,z; } corner;
00111       } Partition;
00112 
00113 
00114       typedef struct {                          // the cost of a patch
00115          float total;                           // is represented here
00116          float local;
00117          float edge;
00118          float icompute[MAXNEIGHBOUR];
00119       } PatchLoad;
00120 
00121       enum {XDIR=0,YDIR,ZDIR};
00122 
00123       // cost parameters 
00124       float c_local0;       // fixed cost per patch
00125       float c_local1;       // cost per atom in the patch
00126       float c_edge0;        // fixed cost for having a neighbor patch
00127       float c_edge1;        // cost per atom of the neighboring patch
00128       float c_icompute0;    // fixed cost per calc. forces for a neighbor
00129       float c_icompute1;    // cost per atom of the neihgbor that I calc force.
00130 
00131  
00132 
00133       int          numPatches;
00134       int          npartition; 
00135       int          currentp;
00136       Partition    *partitions;
00137 
00138       PatchLoad    *patchload;
00139       PatchMap *patchMap;     
00140       Partition    top_partition;
00141 
00142       void compute_patch_load();              // determine cost of each patch
00143       void rec_divide(int, const Partition&); // recursive  partitioning 
00144       void assignNodes();                     // assign partitions to nodes
00145       void assign_nodes_arr(int *);           // assign partitions to array
00146       void refine_edges();                    
00147       void refine_boundaries();
00148       void refine_surface();
00149       int  prev_better(float,float,float);   
00150 
00151     public:
00152 
00153       RecBisection(int, PatchMap *);
00154 
00155       ~RecBisection();
00156       int partition(int *);                    // perform partitioning.
00157                                                // if parameter=NULL, store
00158                                                // results in patchDistrib,
00159                                                // otherwise, store in array
00160       
00161 #if USE_TOPOMAP 
00162       RecBisection(int, int , int, PatchMap *);  //Pass in a 3d
00163                                                  //processor grid
00164       void assignPatchesToProcGrid(int *dest_arr, int X, int Y, int Z, 
00165                                    DimensionMap dm);
00166       int topogrid_rec_divide(Partition &proc_p, Partition &patch_p);     
00167       int partitionProcGrid(int X, int Y, int Z, int *dest_arr);
00168 #endif
00169 };
00170 
00171 #endif
00172 

Generated on Mon Nov 20 01:17:14 2017 for NAMD by  doxygen 1.4.7