Ice Sheet System Model  4.18
Code documentation
Bucket.h
Go to the documentation of this file.
1 
5 #ifndef _BUCKET_H
6 #define _BUCKET_H
7 
8 /*Headers:*/
9 /*{{{*/
10 #include "../../datastructures/datastructures.h"
11 #include "../../shared/io/Comm/IssmComm.h"
12 #include "../toolkitsenums.h"
13 /*}}}*/
14 
15 /*how many ISSM_MPI_Isend requests does it take to transfer the contents of a bucket to another cpu?*/
16 #define MATRIXBUCKETSIZEOFREQUESTS 7
17 #define VECTORBUCKETSIZEOFREQUESTS 5
19 template <class doubletype> class Bucket: public Object{
20 
21  private:
22  int type; //either a VECTOR_BUCKET or MATRIX_BUCKET
23  int m,n; /*size of local matrix we are storing*/
24  /*row and column indices of the matrix we are storing*/
25  int* idxm;
26  int* idxn;
27  doubletype* values; /*local matrix*/
28  InsMode mode; /*mode of insertion for this bucket*/
29 
30  public:
31 
32  /*constructors, destructors: */
33  Bucket(){ /*{{{*/
34  this->Initialize();
35  } /*}}}*/
36  Bucket(int min,int* idxmin,int nin,int* idxnin,doubletype* valuesin,InsMode modein){ /*{{{*/
37 
38  this->Initialize();
39 
40  this->type=MATRIX_BUCKET;
41  this->m=min;
42  this->n=nin;
43  this->mode=modein;
44  if(this->m){
45  this->idxm=xNew<int>(this->m);
46  xMemCpy(this->idxm,idxmin,this->m);
47  }
48  if(this->n){
49  this->idxn=xNew<int>(this->n);
50  xMemCpy(this->idxn,idxnin,this->n);
51  }
52  if(this->m*this->n){
53  this->values=xNew<doubletype>(this->n*this->m);
54  xMemCpy(this->values,valuesin,this->n*this->m);
55  }
56  } /*}}}*/
57  Bucket(int min,int* idxmin,doubletype* valuesin,InsMode modein){ /*{{{*/
58  this->Initialize();
59 
60  this->type=VECTOR_BUCKET;
61  this->m=min;
62  this->mode=modein;
63  if(this->m){
64  this->idxm=xNew<int>(this->m);
65  xMemCpy(this->idxm,idxmin,this->m);
66 
67  this->values=xNew<doubletype>(this->m);
68  xMemCpy(this->values,valuesin,this->m);
69  }
70  } /*}}}*/
71  ~Bucket(){ /*{{{*/
72  xDelete<int>(idxm);
73  xDelete<int>(idxn);
74  xDelete<doubletype>(values);
75  } /*}}}*/
76  void Initialize(void){ /*{{{*/
77 
78  this->type=0;
79  this->m=0;
80  this->n=0;
81  this->idxm=NULL;
82  this->idxn=NULL;
83  this->values=NULL;
84  mode=INS_VAL;
85 
86  } /*}}}*/
87 
88  /*object virtual functions definitions:*/
89  void Echo(){ /*{{{*/
90  _printf_("Bucket echo (cpu #: "<<IssmComm::GetRank()<<")\n");
91  _printf_("bucket type: " << type << "\n");
92  _printf_("num rows: "<<this->m<<" num cols: "<<this->n << "\n");
93  } /*}}}*/
94  void DeepEcho(){ /*{{{*/
95  int i,j;
96 
97  _printf_("Bucket echo (cpu #: "<<IssmComm::GetRank()<<")\n");
98  _printf_("bucket type: " << type << "\n");
99  _printf_("num rows: "<<this->m<<" num cols: "<<this->n << "\n");
100  if(type==MATRIX_BUCKET){
101  for (i=0;i<this->m;i++){
102  _printf_("row "<<this->idxm[i]<<", column indices: \n");
103  for (j=0;j<this->n;j++){
104  _printf_(" "<<this->idxn[j] << "\n");
105  }
106  _printf_("values: \n");
107  for (j=0;j<this->n;j++){
108  _printf_(" "<<this->values[m*i+j] << "\n");
109  }
110  }
111  }
112  else if(type==VECTOR_BUCKET){
113  for (i=0;i<this->m;i++){
114  _printf_("row "<<this->idxm[i]<<", value " << this->values[i] << "\n");
115  }
116  }
117  else _error_("unknown type of bucket!");
118  }
119  /*}}}*/
120  int Id(){ /*{{{*/
121  return -1;
122  } /*}}}*/
123  int ObjectEnum(){ /*{{{*/
124  return -1;
125  } /*}}}*/
126  Object *copy() {/*{{{*/
127  if (this->type==MATRIX_BUCKET) return new Bucket(this->m,this->idxm,this->n,this->idxn,this->values,this->mode);
128  else if (this->type==VECTOR_BUCKET) return new Bucket(this->m,this->idxm,this->values,this->mode);
129  else _error_("No Copy of Bucket because its type is invalid."); };
130  /*}}}*/
131  void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
132  _error_("not implemented yet!");
133  }
134  /*}}}*/
135 
136  /*specific routines of Bucket: */
137  void SpawnBucketsPerCpu(DataSet* bucketsofcpu_i,int rank_i,int* rowranks){ /*{{{*/
138 
139  /*go through our idxm index of rows this bucket owns, and spawn buckets
140  *if these rows belong to cpu rank_i. Use rowranks to determine this.*/
141  for(int i=0;i<m;i++){
142  if (rowranks[idxm[i]]==rank_i){
143  /*This row belongs to cpu rank_i, so spawn a bucket with this row, and add it to the bucketsofcpu_i dataset: */
144  if(type==MATRIX_BUCKET){
145  bucketsofcpu_i->AddObject(new Bucket(1,idxm+i,n,idxn,values+n*i,mode));
146  }
147  else{
148  bucketsofcpu_i->AddObject(new Bucket(1,idxm+i,values+i,mode));
149  }
150  }
151  }
152 
153  }; /*}}}*/
154  int BucketType(void){ /*{{{*/
155 
156  return type;
157  };
158  /*}}}*/
159  void Marshall(int** prow_indices_forcpu,int** pcol_indices_forcpu,doubletype** pvalues_forcpu,int** pmodes_forcpu){ /*{{{*/
160 
161  /*intermediary: */
162  int i;
163  int j;
164 
165  /*buffers: */
166  int *row_indices_forcpu = NULL;
167  int *col_indices_forcpu = NULL;
168  doubletype *values_forcpu = NULL;
169  int *modes_forcpu = NULL;
170 
171  /*initialize buffers: */
172  row_indices_forcpu=*prow_indices_forcpu;
173  col_indices_forcpu=*pcol_indices_forcpu;
174  values_forcpu=*pvalues_forcpu;
175  modes_forcpu=*pmodes_forcpu;
176 
177  /*fill buffers with out values and indices and modes: */
178  for(i=0;i<m;i++){
179  for(j=0;j<n;j++){
180  row_indices_forcpu[i*n+j]=idxm[i];
181  col_indices_forcpu[i*n+j]=idxn[j];
182  values_forcpu[i*n+j]=values[i*n+j];
183  modes_forcpu[i*n+j]=mode;
184  }
185  }
186 
187  /*increment buffer for next Bucket who will marshall his data: */
188  row_indices_forcpu+=(m*n);
189  col_indices_forcpu+=(m*n);
190  values_forcpu+=(m*n);
191  modes_forcpu+=(m*n);
192 
193  /*output modified buffers: */
194  *prow_indices_forcpu=row_indices_forcpu;
195  *pcol_indices_forcpu=col_indices_forcpu;
196  *pvalues_forcpu=values_forcpu;
197  *pmodes_forcpu=modes_forcpu;
198  };
199  /*}}}*/
200  void Marshall(int** prow_indices_forcpu,doubletype** pvalues_forcpu,int** pmodes_forcpu){ /*{{{*/
201 
202  /*intermediary: */
203  int i;
204 
205  /*buffers: */
206  int *row_indices_forcpu = NULL;
207  doubletype *values_forcpu = NULL;
208  int *modes_forcpu = NULL;
209 
210  /*initialize buffers: */
211  row_indices_forcpu=*prow_indices_forcpu;
212  values_forcpu=*pvalues_forcpu;
213  modes_forcpu=*pmodes_forcpu;
214 
215  /*fill buffers with out values and indices and modes: */
216  for(i=0;i<m;i++){
217  row_indices_forcpu[i]=idxm[i];
218  values_forcpu[i]=values[i];
219  modes_forcpu[i]=mode;
220  }
221 
222  /*increment buffer for next Bucket who will marshall his data: */
223  row_indices_forcpu+=m;
224  values_forcpu+=m;
225  modes_forcpu+=m;
226 
227  /*output modified buffers: */
228  *prow_indices_forcpu=row_indices_forcpu;
229  *pvalues_forcpu=values_forcpu;
230  *pmodes_forcpu=modes_forcpu;
231  };
232  /*}}}*/
233  int MarshallSize(void){ /*{{{*/
234 
235  if(type==MATRIX_BUCKET){
236  return m*n;
237  }
238  else{
239  return m;
240  }
241  };
242  /*}}}*/
243 };
244 
245 #endif /* _BUCKET_H */
Bucket::Id
int Id()
Definition: Bucket.h:120
VECTOR_BUCKET
@ VECTOR_BUCKET
Definition: Bucket.h:18
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Bucket::m
int m
Definition: Bucket.h:23
Bucket::mode
InsMode mode
Definition: Bucket.h:28
Bucket::Bucket
Bucket(int min, int *idxmin, int nin, int *idxnin, doubletype *valuesin, InsMode modein)
Definition: Bucket.h:36
Bucket::BucketType
int BucketType(void)
Definition: Bucket.h:154
Bucket::~Bucket
~Bucket()
Definition: Bucket.h:71
Bucket
Definition: Bucket.h:19
Bucket::ObjectEnum
int ObjectEnum()
Definition: Bucket.h:123
Bucket::MarshallSize
int MarshallSize(void)
Definition: Bucket.h:233
Bucket::n
int n
Definition: Bucket.h:23
Bucket::idxn
int * idxn
Definition: Bucket.h:26
Object
Definition: Object.h:13
Bucket::Initialize
void Initialize(void)
Definition: Bucket.h:76
Bucket::Bucket
Bucket()
Definition: Bucket.h:33
Bucket::values
doubletype * values
Definition: Bucket.h:27
INS_VAL
@ INS_VAL
Definition: toolkitsenums.h:14
Bucket::Echo
void Echo()
Definition: Bucket.h:89
Bucket::type
int type
Definition: Bucket.h:22
Bucket::SpawnBucketsPerCpu
void SpawnBucketsPerCpu(DataSet *bucketsofcpu_i, int rank_i, int *rowranks)
Definition: Bucket.h:137
Bucket::Bucket
Bucket(int min, int *idxmin, doubletype *valuesin, InsMode modein)
Definition: Bucket.h:57
IssmComm::GetRank
static int GetRank(void)
Definition: IssmComm.cpp:34
Bucket::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Bucket.h:131
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
min
IssmDouble min(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:14
Bucket::Marshall
void Marshall(int **prow_indices_forcpu, doubletype **pvalues_forcpu, int **pmodes_forcpu)
Definition: Bucket.h:200
InsMode
InsMode
Definition: toolkitsenums.h:14
Bucket::copy
Object * copy()
Definition: Bucket.h:126
Bucket::idxm
int * idxm
Definition: Bucket.h:25
Bucket::Marshall
void Marshall(int **prow_indices_forcpu, int **pcol_indices_forcpu, doubletype **pvalues_forcpu, int **pmodes_forcpu)
Definition: Bucket.h:159
Bucket::DeepEcho
void DeepEcho()
Definition: Bucket.h:94
BucketType
BucketType
Definition: Bucket.h:18
xMemCpy
T * xMemCpy(T *dest, const T *src, unsigned int size)
Definition: MemOps.h:152
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
MATRIX_BUCKET
@ MATRIX_BUCKET
Definition: Bucket.h:18