PaCO++  0.05
DistributionBloc.h
Go to the documentation of this file.
1 #ifndef DISTRIBUTION_BLOC_1D_IS_DEFINED
2 #define DISTRIBUTION_BLOC_1D_IS_DEFINED
3 
4 #include "Type.h"
5 
6 #if defined(__cplusplus)
7 extern "C" {
8 #endif
9 
13 
14  // Definition of bloc: all but the last one have the same size. The last bloc size
15  // can be null !
16 
17  // Compute nb block
18  static inline unsigned MaxNumberOfBlock(const unsigned glen, const unsigned nbprocs, const unsigned bsz) {
19  unsigned nbbloc = (glen + bsz - 1) / bsz;
20  return ((nbbloc + nbprocs - 1 ) / nbprocs);
21  }
22 
23  static inline unsigned NumberOfBlockProc(const unsigned glen, const unsigned nbprocs, const unsigned bsz, const unsigned rank) {
24  unsigned nbbloc = (glen + bsz - 1 ) / bsz;
25  return (nbbloc / nbprocs) + (rank < (nbbloc % nbprocs ) ) ;
26  }
27 
28  // Compute the owner of a bloc
29  static inline unsigned OwnerBlock(const unsigned bid, const unsigned nbprocs) {
30  return bid % nbprocs;
31  }
32 
33  // Compute BlockSize
34  static inline unsigned blockSize(const unsigned glen, const unsigned nbprocs, const ParisBlock_param_t* param) {
35  switch(param->type)
36  {
37  case PARISBLOCK_BLOCK:
38  {
39  unsigned nbbloc = (glen + param->unitblocksize - 1) / param->unitblocksize;
40  return ((nbbloc + nbprocs - 1 ) / nbprocs) * param->unitblocksize;
41  }
42  case PARISBLOCK_CYCLIC: return 1; break;
43  case PARISBLOCK_BLOCKCYCLIC: return param->blocksize; break;
44  }
45  return 0;
46  }
47 
48  // Compute the number of element own by the processor of rank rank
49  static inline unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz) {
50 
51  unsigned nbblocfull = NumberOfBlockProc(glen, nbprocs, bsz, rank) - 1;
52  // Is the last full ?
53  unsigned long low = ( nbblocfull * nbprocs + rank ) * bsz;
54  unsigned long end = low + bsz;
55  unsigned long high = (glen < end ? glen : end);
56 
57  return nbblocfull * bsz + ( high - low );
58 
59  }
60 
61  // Compute the number of elemet of pos bloc
62  static inline unsigned BlockNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz,
63  const unsigned pos) {
64 
65  unsigned long low = ( pos * nbprocs + rank ) * bsz;
66  unsigned long end = low + bsz;
67  unsigned long high = (glen < end ? glen : end);
68 
69  return ( high - low );
70 
71  }
72 
73  // Compute the global bounds low & high of the process of rank rank for the local bloc number pos
74  static inline void computeBlockBounds(unsigned long *low, unsigned long *high, const unsigned glen,
75  const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos) {
76 
77  unsigned long start = (pos * nbprocs + rank) * bsz;
78  unsigned long end = start + bsz;
79  *low = start;
80  *high = ((glen <= end)?glen:end); // min
81  }
82 
83  // compute the global low bounds of local bloc number pos
84  static inline unsigned computeBlockBoundInf(const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos) {
85  return ( pos * nbprocs + rank) * bsz;
86  }
87 
88  static inline unsigned computeBlockBoundSup(const unsigned glen, const unsigned bsz, const unsigned rank,
89  const unsigned nbprocs, const unsigned pos) {
90  unsigned tmp = ( pos * nbprocs + rank + 1) * bsz;
91  return ((glen <= tmp)?glen:tmp); // min
92  }
93 
94 #if defined(__cplusplus)
95 }
96 #endif
97 
98 #endif
static unsigned BlockNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos)
static unsigned NumberOfBlockProc(const unsigned glen, const unsigned nbprocs, const unsigned bsz, const unsigned rank)
static unsigned computeBlockBoundSup(const unsigned glen, const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos)
static unsigned OwnerBlock(const unsigned bid, const unsigned nbprocs)
static void computeBlockBounds(unsigned long *low, unsigned long *high, const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz, const unsigned pos)
static unsigned TotalNumberOfElementProc(const unsigned glen, const unsigned rank, const unsigned nbprocs, const unsigned bsz)
static unsigned computeBlockBoundInf(const unsigned bsz, const unsigned rank, const unsigned nbprocs, const unsigned pos)
static unsigned MaxNumberOfBlock(const unsigned glen, const unsigned nbprocs, const unsigned bsz)
static unsigned blockSize(const unsigned glen, const unsigned nbprocs, const ParisBlock_param_t *param)
unsigned int blocksize
Definition: Type.h:13
unsigned int unitblocksize
Definition: Type.h:15
ParisBlock_distri_type_t type
Definition: Type.h:12