moab
gs.hpp
Go to the documentation of this file.
00001 #ifndef GS_HPP
00002 #define GS_HPP
00003 
00004 
00005 #include "moab/TupleList.hpp"
00006 #include "moab/Types.hpp"
00007 
00008 #ifdef USE_MPI
00009 #include "moab_mpi.h"
00010 #endif
00011 
00012 namespace moab {
00013 
00014   class gs_data
00015   {
00016   public:
00017 #ifdef USE_MPI
00018     class nonlocal_info
00019     {
00020     public:
00021       uint _np;           /* number of processors to communicate with          */
00022       uint *_target;      /* int target[np]: array of processor ids to comm w/ */
00023       uint *_nshared;     /* nshared[i] = number of points shared w/ target[i] */
00024       uint *_sh_ind;      /* list of shared point indices                      */
00025       slong *_slabels;    /* list of signed long labels (not including gid)    */
00026       ulong *_ulabels;    /* list of unsigned long labels                      */
00027       MPI_Request *_reqs; /* pre-allocated for MPI calls                       */
00028       realType *_buf;         /* pre-allocated buffer to receive data              */
00029       uint _maxv;         /* maximum vector size                               */
00030     
00040       nonlocal_info (uint tmp_np, uint count, uint nlabels, 
00041              uint nulabels, uint tmp_maxv) {
00042     this->initialize(tmp_np, count, nlabels, nulabels, tmp_maxv);
00043       }
00044 
00047       void initialize(uint np, uint count, uint nlabels,
00048               uint nulabels, uint maxv);
00049 
00050       ~nonlocal_info () { nlinfo_free(); };
00051 
00052       void nonlocal(realType *u, int op, MPI_Comm comm);
00053       void nonlocal_vec(realType *u, uint n, int op, MPI_Comm comm);
00054       void nonlocal_many(realType **u, uint n, int op, MPI_Comm comm);
00055       void nlinfo_free();
00056     } ;
00057   public:
00058 
00059     /*---------------------------------------------------------------------------
00060 
00061       Crystal Router
00062 
00063       Accomplishes all-to-all communication in log P msgs per proc
00064       The routine is low-level; the format of the input/output is an
00065       array of integers, consisting of a sequence of messages with format:
00066 
00067       target proc
00068       source proc
00069       m
00070       integer
00071       integer
00072       ...
00073       integer  (m integers in total)
00074 
00075       Before moab_crystal_router is called, the source of each message should be
00076       set to this proc id; upon return from moab_crystal_router, the target of each
00077       message will be this proc id.
00078 
00079       Usage:
00080 
00081       MPI_Comm comm = ... ;
00082       moab_crystal_data crystal; 
00083       //moab_crystal_data crystal(comm);  //or this to initialize on 
00084       //instantiation
00085 
00086       crystal.initialize(comm);  // initialize the data structure
00087       // now crystal.id  = this proc
00088       // and crystal.num = num of procs
00089 
00090       // allocate space for at least MAX ints
00091       buffer_reserve(&crystal->all->buf, MAX*sizeof(uint));
00092 
00093       // fill up ((uint*)crystal->all->buf.ptr)[0 ... n-1]
00094       // and set crystal->all->n
00095 
00096       crystal.moab_crystal_router();
00097 
00098       // incoming messages available as
00099       // ((uint*)crystal->all->buf.ptr)[0 ... crystal->all->n-1]
00100 
00101       crystal.reset(); // release acquired memory
00102 
00103       ---------------------------------------------------------------------------*/
00104 
00105     class crystal_data
00106     {
00107     public:
00108       //moab_crystal_data member variables & data
00109       typedef struct { uint n; moab::TupleList::buffer buf; } crystal_buf;
00110       crystal_buf buffers[3];
00111       //crystal_buf provides buffer space for communications
00112       crystal_buf *all, *keep, *send;
00113       MPI_Comm _comm;
00114       uint _num, _id;
00115 
00119       crystal_data();
00120 
00123       crystal_data(MPI_Comm cm) { initialize(cm); };
00124 
00125       ~crystal_data(){ reset(); };
00126 
00132       void initialize(MPI_Comm comm);
00133 
00136       void reset();
00137 
00141       void crystal_router();
00142 
00152       ErrorCode gs_transfer(int dynamic, moab::TupleList &tl,
00153                   unsigned pf);
00154 
00155     private:
00156       //Used by moab_crystal_router:  see .cpp for more details
00157       void partition(uint cutoff, crystal_buf *lo, crystal_buf *hi);
00158 
00159       void send_(uint target, int recvn);
00160 
00161     };
00162 #else
00163     //If mpi is not used, moab_crystal_data cannot be used
00164     class crystal_data{};
00165 #endif
00166 
00167     sint *local_cm; /* local condense map */
00168 #ifdef USE_MPI
00169     nonlocal_info *nlinfo;
00170     MPI_Comm _comm;
00171 #endif
00172 
00186     gs_data (uint n, const long *label, const ulong *ulabel,
00187          uint maxv, const unsigned int nlabels,
00188          const unsigned int nulabels,
00189          crystal_data *crystal, ErrorCode &Init_Result) {
00190       Init_Result = this->initialize (n, label, ulabel, maxv, nlabels,
00191                       nulabels, crystal);
00192     };
00193   
00194   
00198     gs_data () {
00199     };
00200 
00201     ~gs_data () { reset(); }
00202 
00205     ErrorCode initialize (uint n, const long *label, const ulong *ulabel,
00206                 uint maxv, const unsigned int nlabels,
00207                 const unsigned int nulabels,
00208                 crystal_data *crystal);
00209 
00210     void reset();
00211 
00212     void gs_data_op(realType *u, int op);
00213     void gs_data_op_vec(realType *u, uint n, int op);
00214     void gs_data_op_many(realType **u, uint n, int op);
00215 
00216 #define GS_OP_ADD 1
00217 #define GS_OP_MUL 2
00218 #define GS_OP_MIN 3
00219 #define GS_OP_MAX 4
00220 #define GS_OP_BPR 5
00221   } ;
00222 
00223 }
00224 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines