Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

dist_matrix.h

Go to the documentation of this file.
00001 /***
00002  * Copyright (c) 2005, SkeTo Project
00003  * All rights reserved.
00004  */
00012 #ifndef __DIST_MATRIX_H__
00013 #define __DIST_MATRIX_H__
00014 
00015 
00016 
00017 #include <mpi.h>
00018 #include <iostream>
00019 #include <iomanip>
00020 
00021 #include "Serializer.h"
00022 #include "matrix.h"
00023 #include "template_mpitype.h"
00024 #include "../util/skeleton.h"
00028 typedef enum {
00029     TAG_NOTHING,             
00030     TAG_DISTRIBUTE,          
00031     TAG_DISTRIBUTE2,         
00032     TAG_GATHER1,             
00033     TAG_GATHER2,             
00034     TAG_GATHER3,             
00035     TAG_PERMUTE1,            
00036     TAG_PERMUTE2,            
00037     TAG_PERMUTE3,            
00038     TAG_SCAN12,              
00039     TAG_SCAN12s,             
00040     TAG_SCAN22,              
00041     TAG_SCAN22s,             
00042     TAG_REDUCE1,             
00043     TAG_REDUCE2,             
00044     TAG_REDUCE3,             
00045     TAG_REDUCE4,             
00046     TAG_ALLREDUCEROW1,          
00047     TAG_ALLREDUCEROW2,          
00048     TAG_ALLREDUCEROW3,          
00049     TAG_ALLREDUCEROW4,          
00050     TAG_ALLREDUCECOL1,          
00051     TAG_ALLREDUCECOL2,          
00052     TAG_ALLREDUCECOL3,          
00053     TAG_ALLREDUCECOL4,          
00054     TAG_GLOBAL_GET1,             
00055     TAG_GLOBAL_GET2,             
00056     TAG_GLOBAL_GET22,             
00057     TAG_GLOBAL_GET3,             
00058     TAG_GLOBAL_GET32,             
00059     TAG_GLOBAL_SET1,             
00060     TAG_GLOBAL_SET2,             
00061     TAG_GLOBAL_SET22,             
00062     TAG_GLOBAL_SET3,             
00063     TAG_GLOBAL_SET32             
00064 } dist_matrix_tag_t;
00065 
00069 static const MPI_Datatype BYTE_TYPE = MPI_BYTE;
00070 
00071 static const SKEL_MPI_INTRACOMM DEFAULT_COMM = SKEL_MPI_COMM_WORLD;
00072 
00073 class matrix_skeletons;
00074 
00076 struct matrixStructure{
00077     int idxRow;          
00078     int idxCol;          
00079     int localRows;       
00080     int localCols;       
00081 };
00082 
00083 
00084 
00085 
00086 
00107 template< typename A >
00108 class dist_matrix
00109 {
00110   friend class matrix_skeletons; 
00111 private:
00113     // Member variables
00114 private:
00116     int myrank; 
00118     int n;              
00120     int m;
00122     int rows;       
00124     int cols;
00126     int localRows;      
00128     int localCols;
00130     int blocks;
00132     int bir;            
00134     int bic;
00136     A *ele;
00138     A **idxEle;
00140     int idxRow;
00142     int idxCol;
00144     int posX; 
00146     int posY;
00147 
00149     MPI_Datatype mpitype;
00150 
00152     const SKEL_MPI_INTRACOMM comm;
00153 public:
00155     // constructor and destructor
00156 public:
00162     dist_matrix();
00180     dist_matrix(int nn, int mm, const SKEL_MPI_INTRACOMM &com = SKEL_MPI_COMM_WORLD, int r = -1, int c = -1);
00210     template<typename F>
00211     dist_matrix(int nn, int mm, const F &f, const SKEL_MPI_INTRACOMM &com = SKEL_MPI_COMM_WORLD, int r = -1, int c = -1);
00227     dist_matrix(const matrix<A> *mat, const SKEL_MPI_INTRACOMM &com = SKEL_MPI_COMM_WORLD, int r = -1, int c = -1);
00231     dist_matrix(const dist_matrix<A> &dmat);
00235  public:
00236     ~dist_matrix();
00237 
00238 
00240     // Private Utilities
00241 private:
00247     void init(int r, int c);
00251     void init2();
00257     matrixStructure createStructure(int rnk) const;
00265     void broadcastMatrixParameters(int *nn, int *mm, int *r, int *c);
00279     template <typename B>
00280     unsigned char *sendSerializingData(int target, B *dat, int num, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2, SKEL_MPI_Request &reqs, const SKEL_MPI_INTRACOMM &com) const;
00293     template <typename B>
00294     unsigned char *sendSerializingData(int target, B *dat, int num, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2, SKEL_MPI_Request &reqs) const;
00305     unsigned char *sendSerializingData(int target, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2, SKEL_MPI_Request &reqs) const;
00315     template <typename B>
00316     void recvSerializingData(int target, B *dat, int num, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2) const;
00327     template <typename B>
00328     void recvSerializingData(int target, B *dat, int num, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2, const SKEL_MPI_INTRACOMM &com) const;
00335     void recvSerializingData(int target, dist_matrix_tag_t tag1, dist_matrix_tag_t tag2);
00336 
00338     // Public Utilities
00339  public:
00357     template <typename F>
00358     void generate(const F &f);
00365     void distribute(const matrix<A> *mat);
00373     void gather(matrix<A> *mat) const;
00382     void gatherB(matrix<A> *mat) const;
00390     void print(std::ostream& os) const;
00397     template <typename B>
00398     void shapeCopy(const dist_matrix<B> *mat);
00399 
00400 
00401 
00403     // access methods
00404 public:
00408     int getRows() const {return n;}
00412     int getCols() const {return m;}
00416     int getLocalRows() const {return localRows;}
00420     int getLocalCols() const {return localCols;}
00424     int getBlocksInRow() const {return bir;}
00428     int getBlocksInCol() const {return bic;}
00432     int getIdxRow() const {return idxRow;}
00436     int getIdxCol() const {return idxCol;}
00440     int getPosX() const {return posX;}
00444     int getPosY() const {return posY;}
00451     A &get(int i, int j) const {return idxEle[i][j];}
00458     A &at(int i, int j) {return idxEle[i][j];}
00465     const A &at(int i, int j) const {return idxEle[i][j];}
00473     void set(int i, int j, const A &v) {idxEle[i][j] = v;}
00477     int getRank() const { return myrank;}
00481     matrix<A> *getMatrix() const {  return new matrix<A>(n, m, ele, idxEle, false); }
00487     const MPI_Datatype &getType() const { return mpitype; }
00488 
00498     A* globalGet(int i, int j) const;
00507     void globalSet(int i, int j, const A& val) const;
00516     template<typename B>
00517     static void bcast(B *res, const dist_matrix<A> *mat);
00518 
00519 private:
00527     template<typename B>
00528     static void bcast(B *res, const SKEL_MPI_INTRACOMM &com);
00529     
00530 };
00531 
00532 template<typename A>
00533 class template_mpitype< matrix < A > > {
00541  public:
00542     static const MPI_Datatype type() { return template_mpitype< A >::type( );}
00543 };
00544 
00545 
00546 #include "dist_matrix.tpp"
00547 
00548 #endif // __DIST_MATRIX_H__

Generated on Wed Jan 18 22:19:27 2006 for SkeTo -- Skeleton Library in Tokyo by  doxygen 1.4.4