00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 #ifndef __CHARM_IDXL_H
00016 #define __CHARM_IDXL_H
00017 
00018 #include "mpi.h"
00019 #include "pup.h"
00020 #include "idxlc.h" 
00021 #include "idxl_comm.h" 
00022 #include "idxl_layout.h" 
00023 #include "tcharmc.h" 
00024 
00025 void IDXL_Abort(const char *callingRoutine,const char *msg,int m0=0,int m1=0,int m2=0);
00026 
00037 class IDXL_Comm {
00038 public: 
00039     typedef enum { send_t=17,recv_t,sum_t} op_t;
00040     
00043     class sto_t { public:
00044         const IDXL_Side *idx; 
00045         const IDXL_Layout *dtype; 
00046         void *data; 
00047         op_t op; 
00048         
00049         sto_t(const IDXL_Side *idx_,const IDXL_Layout *dtype_,void *data_,op_t op_)
00050             :idx(idx_), dtype(dtype_), data(data_), op(op_) {}
00051         sto_t(void) {}
00052     };
00053     
00055     class msg_t { 
00056         CkVec<char> buf; 
00057     public:
00058         sto_t *sto; 
00059         int ll; 
00060         void allocate(int len) {
00061             buf.resize(len);
00062         }
00063         void *getBuf(void) {return &buf[0];}
00064     };
00065 
00066 private:
00068     CkVec<sto_t> sto;
00073     CkVec<msg_t *> msg; 
00074     int nMsgs;
00075     
00078     CkVec<MPI_Request> msgReq;
00079     CkVec<MPI_Status> msgSts;
00080     
00081     int tag; MPI_Comm comm;
00082     bool isPost; 
00083     bool isDone; 
00084 public:
00085     IDXL_Comm(int tag,int context);
00086     void reset(int tag,int context);
00087     ~IDXL_Comm();
00088     
00089     
00090     void send(const IDXL_Side *idx,const IDXL_Layout *dtype,const void *src);
00091     
00092     
00093     void recv(const IDXL_Side *idx,const IDXL_Layout *dtype,void *dest);
00094     void sum(const IDXL_Side *idx,const IDXL_Layout *dtype,void *srcdest);
00095     
00096     
00097     void post(void);
00098     
00099     
00100     void wait(void);
00101     
00103     bool isPosted(void) { return isPost; }
00104     bool isComplete(void) {return isDone;}
00105 };
00106 
00107 
00108 enum {IDXL_globalID=32};
00109 
00117 class IDXL_Chunk {
00118   
00119   int mpi_comm;
00120   
00121   
00122   
00126   CkVec<IDXL *> static_idxls;
00127   
00131   CkVec<IDXL *> dynamic_idxls;
00132   
00133   
00134   int storeToFreeIndex(CkVec<IDXL *> &inList,IDXL *store) {
00135     int i;
00136     for (i=0;i<inList.size();i++)
00137         if (inList[i]==NULL) {
00138             inList[i]=store;
00139             return i;
00140         }
00141     i=inList.size();
00142     inList.push_back(store);
00143     return i;
00144   }
00145   
00146   
00147   IDXL_Comm *currentComm; 
00148   
00149   void init(void);
00150 public:
00151     IDXL_Chunk(int mpi_comm_);
00152     IDXL_Chunk(CkMigrateMessage *m);
00153     void pup(PUP::er &p);
00154     ~IDXL_Chunk();
00155     
00156   static IDXL_Chunk *getNULL(void) {
00157     return (IDXL_Chunk *)TCHARM_Get_global(IDXL_globalID);
00158   }
00159   static IDXL_Chunk *get(const char *callingRoutine);
00160     
00161 
00163   IDXL_t addDynamic(void);
00165   IDXL_t addStatic(IDXL *idx,IDXL_t at=-1);
00166   
00168   void check(IDXL_t u,const char *callingRoutine="") const;
00169   
00171   IDXL &lookup(IDXL_t u,const char *callingRoutine="");
00172   const IDXL &lookup(IDXL_t u,const char *callingRoutine="") const;
00173   
00175   void destroy(IDXL_t t,const char *callingRoutine="");
00176   
00177 
00178   IDXL_Layout_List layouts;
00179 
00180 
00181   IDXL_Comm_t addComm(int tag,int context);
00182   IDXL_Comm *lookupComm(IDXL_Comm_t uc,const char *callingRoutine="");
00183   void waitComm(IDXL_Comm *comm);
00184 };
00185 
00186 #define IDXLAPI(routineName) TCHARM_API_TRACE(routineName,"IDXL");
00187 
00188 #endif
00189 
00190 
00191