MOAB: Mesh Oriented datABase  (version 5.4.1)
gs.hpp
Go to the documentation of this file.
00001 #ifndef GS_HPP
00002 #define GS_HPP
00003 
00004 #include "moab/MOABConfig.h"
00005 #include "moab/TupleList.hpp"
00006 #include "moab/Types.hpp"
00007 
00008 #ifdef MOAB_HAVE_MPI
00009 #include "moab_mpi.h"
00010 #endif
00011 
00012 namespace moab
00013 {
00014 
00015 class gs_data
00016 {
00017   public:
00018 #ifdef MOAB_HAVE_MPI
00019     class nonlocal_info
00020     {
00021       public:
00022         uint _np;           /* number of processors to communicate with          */
00023         uint* _target;      /* int target[np]: array of processor ids to comm w/ */
00024         uint* _nshared;     /* nshared[i] = number of points shared w/ target[i] */
00025         uint* _sh_ind;      /* list of shared point indices                      */
00026         slong* _slabels;    /* list of signed long labels (not including gid)    */
00027         Ulong* _ulabels;    /* list of unsigned long labels                      */
00028         MPI_Request* _reqs; /* pre-allocated for MPI calls                       */
00029         realType* _buf;     /* pre-allocated buffer to receive data              */
00030         uint _maxv;         /* maximum vector size                               */
00031 
00032         /**Constructor for nonlocal_info; takes all arguments and initializes
00033          * nonlocal_info
00034          *
00035          * param np        number of processors to communicate with
00036          * param count     number of partner processors
00037          * param nlabels   number of signed long labels (not including gid)
00038          * param nulabels  number of unsigned long labels
00039          * param maxv      maximum vector size
00040          */
00041         nonlocal_info( uint tmp_np, uint count, uint nlabels, uint nulabels, uint tmp_maxv )
00042         {
00043             this->initialize( tmp_np, count, nlabels, nulabels, tmp_maxv );
00044         }
00045 
00046         /**Initializes nonlocal_info; see constructor for parameter documentation
00047          */
00048         void initialize( uint np, uint count, uint nlabels, uint nulabels, uint maxv );
00049 
00050         ~nonlocal_info()
00051         {
00052             nlinfo_free();
00053         };
00054 
00055         void nonlocal( realType* u, int op, MPI_Comm comm );
00056         void nonlocal_vec( realType* u, uint n, int op, MPI_Comm comm );
00057         void nonlocal_many( realType** u, uint n, int op, MPI_Comm comm );
00058         void nlinfo_free();
00059     };
00060 
00061   public:
00062     /*---------------------------------------------------------------------------
00063 
00064       Crystal Router
00065 
00066       Accomplishes all-to-all communication in log P msgs per proc
00067       The routine is low-level; the format of the input/output is an
00068       array of integers, consisting of a sequence of messages with format:
00069 
00070       target proc
00071       source proc
00072       m
00073       integer
00074       integer
00075       ...
00076       integer  (m integers in total)
00077 
00078       Before moab_crystal_router is called, the source of each message should be
00079       set to this proc id; upon return from moab_crystal_router, the target of each
00080       message will be this proc id.
00081 
00082       Usage:
00083 
00084       MPI_Comm comm = ... ;
00085       moab_crystal_data crystal;
00086       //moab_crystal_data crystal(comm);  //or this to initialize on
00087       //instantiation
00088 
00089       crystal.initialize(comm);  // initialize the data structure
00090       // now crystal.id  = this proc
00091       // and crystal.num = num of procs
00092 
00093       // allocate space for at least MAX ints
00094       buffer_reserve(&crystal->all->buf, MAX*sizeof(uint));
00095 
00096       // fill up ((uint*)crystal->all->buf.ptr)[0 ... n-1]
00097       // and set crystal->all->n
00098 
00099       crystal.moab_crystal_router();
00100 
00101       // incoming messages available as
00102       // ((uint*)crystal->all->buf.ptr)[0 ... crystal->all->n-1]
00103 
00104       crystal.reset(); // release acquired memory
00105 
00106       ---------------------------------------------------------------------------*/
00107 
00108     class crystal_data
00109     {
00110       public:
00111         // moab_crystal_data member variables & data
00112         typedef struct
00113         {
00114             uint n;
00115             moab::TupleList::buffer buf;
00116         } crystal_buf;
00117         crystal_buf buffers[3];
00118         // crystal_buf provides buffer space for communications
00119         crystal_buf *all, *keep, *send;
00120         MPI_Comm _comm;
00121         uint _num, _id;
00122 
00123         /**Default constructor (Note:  moab_crystal_data must be initialized
00124          * before use!)
00125          */
00126         crystal_data();
00127 
00128         /**Constructor takes an MPI_Comm and initializes the moab_data_crystal
00129          */
00130         crystal_data( MPI_Comm cm )
00131         {
00132             initialize( cm );
00133         };
00134 
00135         ~crystal_data()
00136         {
00137             reset();
00138         };
00139 
00140         /**Initializes crystal_data members according to MPI_Comm passed in
00141          * Note:  moab_crystal_data must be initialized before it can be used
00142          *
00143          * param comm  MPI_Comm detailing where to send messages
00144          */
00145         void initialize( MPI_Comm comm );
00146 
00147         /**Frees buffers used by moab_crystal_data
00148          */
00149         void reset();
00150 
00151         /**Communicates messages with other processors; see class description for
00152          * more info and usage
00153          */
00154         void crystal_router();
00155 
00156         /**Treats one integer (not long) member of the TupleList as a target proc;
00157          * Sends out tuples accordingly, using the crystal router.
00158          * Target proc member overwritten with source proc.
00159          *
00160          * param dynamic   non-zero if the TupleList should grow to accomodate
00161          *                 arrivals
00162          * param tl        the TupleList
00163          * param pf        which tuple member specifies target proc
00164          */
00165         ErrorCode gs_transfer( int dynamic, moab::TupleList& tl, unsigned pf );
00166 
00167       private:
00168         // Used by moab_crystal_router:  see .cpp for more details
00169         void partition( uint cutoff, crystal_buf* lo, crystal_buf* hi );
00170 
00171         void send_( uint target, int recvn );
00172     };
00173 #else
00174     // If mpi is not used, moab_crystal_data cannot be used
00175     class crystal_data
00176     {
00177     };
00178 #endif
00179 
00180     sint* local_cm; /* local condense map */
00181 #ifdef MOAB_HAVE_MPI
00182     nonlocal_info* nlinfo;
00183     MPI_Comm _comm;
00184 #endif
00185 
00186     /**Constructor for moab_gs_data:  takes all arguments and initializes
00187      * moab_gs_data.  If needs_reset is false after calling constructor,
00188      * initialization has failed.
00189      *
00190      * param n         number of tuples in tuple list
00191      * param label     pointer to signed labels
00192      * param ulabel    pointer to unsigned labels
00193      * param maxv      max vector size
00194      * param nlabels   number of signed long labels (not including gid)
00195      * param nulabels  number of unsigned long labels
00196      * param crystal   moab_crystal_data contains MPI_Comm and is used for
00197      *                 message passing
00198      */
00199     gs_data( uint n,
00200              const long* label,
00201              const Ulong* ulabel,
00202              uint maxv,
00203              const unsigned int nlabels,
00204              const unsigned int nulabels,
00205              crystal_data* crystal,
00206              ErrorCode& Init_Result )
00207     {
00208         Init_Result = this->initialize( n, label, ulabel, maxv, nlabels, nulabels, crystal );
00209     };
00210 
00211     /**Default constructor (Note:  moab_gs_data must be initialized
00212      * before use!)
00213      */
00214     gs_data(){};
00215 
00216     ~gs_data()
00217     {
00218         reset();
00219     }
00220 
00221     /**Sets up the moab_gs_data; see constructor for parameter documentation
00222      */
00223     ErrorCode initialize( uint n,
00224                           const long* label,
00225                           const Ulong* ulabel,
00226                           uint maxv,
00227                           const unsigned int nlabels,
00228                           const unsigned int nulabels,
00229                           crystal_data* crystal );
00230 
00231     void reset();
00232 
00233     void gs_data_op( realType* u, int op );
00234     void gs_data_op_vec( realType* u, uint n, int op );
00235     void gs_data_op_many( realType** u, uint n, int op );
00236 
00237 #define GS_OP_ADD 1
00238 #define GS_OP_MUL 2
00239 #define GS_OP_MIN 3
00240 #define GS_OP_MAX 4
00241 #define GS_OP_BPR 5
00242 };
00243 
00244 }  // namespace moab
00245 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines