PaCO++
0.05
|
00001 #ifndef DISTRIBUTION_BLOC_1D_IS_DEFINED 00002 #define DISTRIBUTION_BLOC_1D_IS_DEFINED 00003 00004 #include "Type.h" 00005 00006 #if defined(__cplusplus) 00007 extern "C" { 00008 #endif 00009 00013 00014 // Definition of bloc: all but the last one have the same size. The last bloc size 00015 // can be null ! 00016 00017 // Compute nb block 00018 static inline unsigned MaxNumberOfBlock(const unsigned glen, const unsigned nbprocs, const unsigned bsz) { 00019 unsigned nbbloc = (glen + bsz - 1) / bsz; 00020 return ((nbbloc + nbprocs - 1 ) / nbprocs); 00021 } 00022 00023 static inline unsigned NumberOfBlockProc(const unsigned glen, const unsigned nbprocs, const unsigned bsz, const unsigned rank) { 00024 unsigned nbbloc = (glen + bsz - 1 ) / bsz; 00025 return (nbbloc / nbprocs) + (rank < (nbbloc % nbprocs ) ) ; 00026 } 00027 00028 // Compute the owner of a bloc 00029 static inline unsigned OwnerBlock(const unsigned bid, const unsigned nbprocs) { 00030 return bid % nbprocs; 00031 } 00032 00033 // Compute BlockSize 00034 static inline unsigned blockSize(const unsigned glen, const unsigned nbprocs, const ParisBlock_param_t* param) { 00035 switch(param->type) 00036 { 00037 case PARISBLOCK_BLOCK: 00038 { 00039 unsigned nbbloc = (glen + param->unitblocksize - 1) / param->unitblocksize; 00040 return ((nbbloc + nbprocs - 1 ) / nbprocs) * param->unitblocksize; 00041 } 00042 case PARISBLOCK_CYCLIC: return 1; break; 00043 case PARISBLOCK_BLOCKCYCLIC: return param->blocksize; break; 00044 } 00045 return 0; 00046 } 00047 00048 // Compute the number of element own by the processor of rank rank 00049 static inline unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz) { 00050 00051 unsigned nbblocfull = NumberOfBlockProc(glen, nbprocs, bsz, rank) - 1; 00052 // Is the last full ? 00053 unsigned long low = ( nbblocfull * nbprocs + rank ) * bsz; 00054 unsigned long end = low + bsz; 00055 unsigned long high = (glen < end ? glen : end); 00056 00057 return nbblocfull * bsz + ( high - low ); 00058 00059 } 00060 00061 // Compute the number of elemet of pos bloc 00062 static inline unsigned BlockNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz, 00063 const unsigned pos) { 00064 00065 unsigned long low = ( pos * nbprocs + rank ) * bsz; 00066 unsigned long end = low + bsz; 00067 unsigned long high = (glen < end ? glen : end); 00068 00069 return ( high - low ); 00070 00071 } 00072 00073 // Compute the global bounds low & high of the process of rank rank for the local bloc number pos 00074 static inline void computeBlockBounds(unsigned long *low, unsigned long *high, const unsigned glen, 00075 const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos) { 00076 00077 unsigned long start = (pos * nbprocs + rank) * bsz; 00078 unsigned long end = start + bsz; 00079 *low = start; 00080 *high = ((glen <= end)?glen:end); // min 00081 } 00082 00083 // compute the global low bounds of local bloc number pos 00084 static inline unsigned computeBlockBoundInf(const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos) { 00085 return ( pos * nbprocs + rank) * bsz; 00086 } 00087 00088 static inline unsigned computeBlockBoundSup(const unsigned glen, const unsigned bsz, const unsigned rank, 00089 const unsigned nbprocs, const unsigned pos) { 00090 unsigned tmp = ( pos * nbprocs + rank + 1) * bsz; 00091 return ((glen <= tmp)?glen:tmp); // min 00092 } 00093 00094 #if defined(__cplusplus) 00095 } 00096 #endif 00097 00098 #endif