Ice Sheet System Model  4.18
Code documentation
Public Member Functions | Data Fields
IssmMpiVec< doubletype > Class Template Reference

#include <IssmMpiVec.h>

Inheritance diagram for IssmMpiVec< doubletype >:
IssmAbsVec< doubletype >

Public Member Functions

 IssmMpiVec ()
 
 IssmMpiVec (int Min)
 
 IssmMpiVec (int min, int Min)
 
 IssmMpiVec (int Min, bool fromlocalsize)
 
 IssmMpiVec (doubletype *buffer, int Min)
 
 IssmMpiVec (doubletype *buffer, int Min, int min)
 
void Init (int Min, bool fromlocalsize)
 
 ~IssmMpiVec ()
 
void Echo (void)
 
void Assemble ()
 
void SetValues (int ssize, int *list, doubletype *values, InsMode mode)
 
void SetValue (int dof, doubletype value, InsMode mode)
 
void GetValue (doubletype *pvalue, int dof)
 
void GetSize (int *pM)
 
void GetLocalSize (int *pM)
 
void GetLocalVector (doubletype **pvector, int **pindices)
 
IssmMpiVec< doubletype > * Duplicate (void)
 
void Set (doubletype value)
 
void AXPY (IssmAbsVec< doubletype > *Xin, doubletype a)
 
void AYPX (IssmAbsVec< doubletype > *Xin, doubletype a)
 
doubletype * ToMPISerial (void)
 
doubletype * ToMPISerial0 (void)
 
void Shift (doubletype shift)
 
void Copy (IssmAbsVec< doubletype > *toin)
 
doubletype Norm (NormMode mode)
 
void Scale (doubletype scale_factor)
 
doubletype Dot (IssmAbsVec< doubletype > *inputin)
 
void PointwiseDivide (IssmAbsVec< doubletype > *xin, IssmAbsVec< doubletype > *yin)
 
void BucketsBuildScatterBuffers (int **pnumvalues_forcpu, int **prow_indices_forcpu, doubletype **pvalues_forcpu, int **pmodes_forcpu, DataSet **bucketsforcpu, int num_procs)
 
- Public Member Functions inherited from IssmAbsVec< doubletype >
virtual ~IssmAbsVec ()
 

Data Fields

int M
 
int m
 
doubletype * vector
 
DataSetbuckets
 

Detailed Description

template<class doubletype>
class IssmMpiVec< doubletype >

Definition at line 34 of file IssmMpiVec.h.

Constructor & Destructor Documentation

◆ IssmMpiVec() [1/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( )
inline

Definition at line 44 of file IssmMpiVec.h.

44  {/*{{{*/
45 
46  this->M=0;
47  this->m=0;
48  this->vector=NULL;
49  this->buckets=new DataSet();
50  }

◆ IssmMpiVec() [2/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( int  Min)
inline

Definition at line 52 of file IssmMpiVec.h.

52  {/*{{{*/
53  this->Init(Min,false);
54  }

◆ IssmMpiVec() [3/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( int  min,
int  Min 
)
inline

Definition at line 56 of file IssmMpiVec.h.

56  {/*{{{*/
57  this->Init(min,true);
58  }

◆ IssmMpiVec() [4/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( int  Min,
bool  fromlocalsize 
)
inline

Definition at line 60 of file IssmMpiVec.h.

60  {/*{{{*/
61  this->Init(Min,fromlocalsize);
62  }

◆ IssmMpiVec() [5/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( doubletype *  buffer,
int  Min 
)
inline

Definition at line 64 of file IssmMpiVec.h.

64  {/*{{{*/
65 
66  this->Init(Min,false);
67 
68  if(this->M){
69 // AD performance is sensitive to calls to ensurecontiguous.
70 // Providing "t" will cause ensurecontiguous to be called.
71 #ifdef _HAVE_AD_
72  this->vector=xNew<doubletype>(this->m,"t");
73 #else
74  this->vector=xNew<doubletype>(this->m);
75 #endif
76 
77  xMemCpy<doubletype>(this->vector,buffer,this->m);
78  }
79  }

◆ IssmMpiVec() [6/6]

template<class doubletype >
IssmMpiVec< doubletype >::IssmMpiVec ( doubletype *  buffer,
int  Min,
int  min 
)
inline

Definition at line 81 of file IssmMpiVec.h.

81  {/*{{{*/
82 
83  this->vector=NULL;
84  this->buckets=new DataSet();
85  this->M=Min;
86  this->m=min;
87 
88  if(this->m){
89 // AD performance is sensitive to calls to ensurecontiguous.
90 // Providing "t" will cause ensurecontiguous to be called.
91 #ifdef _HAVE_AD_
92  this->vector=xNew<doubletype>(this->m,"t");
93 #else
94  this->vector=xNew<doubletype>(this->m);
95 #endif
96 
97  xMemCpy<doubletype>(this->vector,buffer,this->m);
98  }
99  }

◆ ~IssmMpiVec()

template<class doubletype >
IssmMpiVec< doubletype >::~IssmMpiVec ( )
inline

Definition at line 128 of file IssmMpiVec.h.

128  {/*{{{*/
129  xDelete<doubletype>(this->vector);
130  this->M=0;
131  this->m=0;
132  delete buckets;
133  }

Member Function Documentation

◆ Init()

template<class doubletype >
void IssmMpiVec< doubletype >::Init ( int  Min,
bool  fromlocalsize 
)
inline

Definition at line 101 of file IssmMpiVec.h.

101  {/*{{{*/
102 
103  this->buckets=new DataSet();
104 
105  if(fromlocalsize){
106  this->m=Min;
107  this->M=DetermineGlobalSize(this->m,IssmComm::GetComm());
108  }
109  else{
110  this->M=Min;
111  this->m=DetermineLocalSize(this->M,IssmComm::GetComm());
112  }
113 
114  /*Initialize pointer: */
115  this->vector=NULL;
116 
117  /*Allocate: */
118 // AD performance is sensitive to calls to ensurecontiguous.
119 // Providing "t" will cause ensurecontiguous to be called.
120 #ifdef _HAVE_AD_
121  if (m)this->vector=xNewZeroInit<doubletype>(this->m,"t");
122 #else
123  if (m)this->vector=xNewZeroInit<doubletype>(this->m);
124 #endif
125 
126  }

◆ Echo()

template<class doubletype >
void IssmMpiVec< doubletype >::Echo ( void  )
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 137 of file IssmMpiVec.h.

137  {/*{{{*/
138 
139  int i,j;
140 
141  /*Do a synchronized dump across all the rows: */
142  for(i=0;i<IssmComm::GetSize();i++){
144  }
145  }

◆ Assemble()

template<class doubletype >
void IssmMpiVec< doubletype >::Assemble ( void  )
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 147 of file IssmMpiVec.h.

147  {/*{{{*/
148 
149  int i,j;
150 
151  int *RowRank = NULL;
152  int num_procs;
153 
154  int *row_indices_forcpu = NULL;
155  int *modes_forcpu = NULL;
156  doubletype *values_forcpu = NULL;
157  int *numvalues_forcpu = NULL;
158  DataSet **bucketsforcpu = NULL;
159 
160  int **row_indices_fromcpu = NULL;
161  int **col_indices_fromcpu = NULL;
162  int **modes_fromcpu = NULL;
163  doubletype **values_fromcpu = NULL;
164  int *numvalues_fromcpu = NULL;
165 
166  int lower_row;
167  int upper_row;
168  int* sendcnts = NULL;
169  int* displs = NULL;
170  int count = 0;
171 
172  /*some communicator info: */
173  num_procs=IssmComm::GetSize();
175 
176  /*First, make a vector of size M, which for each row between 0 and M-1, tells which cpu this row belongs to: */
177  RowRank=DetermineRowRankFromLocalSize(M,m,comm);
178 
179  /*Now, sort out our dataset of buckets according to cpu ownership of rows: {{{*/
180  bucketsforcpu=xNew<DataSet*>(num_procs);
181 
182  for(i=0;i<num_procs;i++){
183  DataSet* bucketsofcpu_i=new DataSet();
184  for (j=0;j<buckets->Size();j++){
186  bucket->SpawnBucketsPerCpu(bucketsofcpu_i,i,RowRank);
187  }
188  bucketsforcpu[i]=bucketsofcpu_i;
189  }
190  /*}}}*/
191 
192  /*Recap, each cpu has num_procs datasets of buckets. For a certain cpu j, for a given dataset i, the buckets this {{{
193  * dataset owns correspond to rows that are owned by cpu i, not j!. Out of all the buckets we own, make row,col,value,insert_mode
194  * vectors that will be shipped around the cluster: */
195  this->BucketsBuildScatterBuffers(&numvalues_forcpu,&row_indices_forcpu,&values_forcpu,&modes_forcpu,bucketsforcpu,num_procs);
196  /*}}}*/
197 
198  /*Now, we need to allocate on each cpu arrays to receive data from all the other cpus. To know what we need to allocate, we need {{{
199  *some scatter calls: */
200  numvalues_fromcpu = xNew<int>(num_procs);
201  for(i=0;i<num_procs;i++){
202  ISSM_MPI_Scatter(numvalues_forcpu,1,ISSM_MPI_INT,numvalues_fromcpu+i,1,ISSM_MPI_INT,i,comm);
203  }
204 
205  row_indices_fromcpu=xNew<int*>(num_procs);
206  values_fromcpu=xNew<doubletype*>(num_procs);
207  modes_fromcpu=xNew<int*>(num_procs);
208  for(i=0;i<num_procs;i++){
209  int size=numvalues_fromcpu[i];
210  if(size){
211  row_indices_fromcpu[i]=xNew<int>(size);
212 // AD performance is sensitive to calls to ensurecontiguous.
213 // Providing "t" will cause ensurecontiguous to be called.
214 #ifdef _HAVE_AD_
215  values_fromcpu[i]=xNew<doubletype>(size,"t");
216 #else
217  values_fromcpu[i]=xNew<doubletype>(size);
218 #endif
219 
220  modes_fromcpu[i]=xNew<int>(size);
221  }
222  else{
223  row_indices_fromcpu[i]=NULL;
224  values_fromcpu[i]=NULL;
225  modes_fromcpu[i]=NULL;
226  }
227  }
228  /*}}}*/
229 
230  /*Scatter values around: {{{*/
231  /*Now, to scatter values across the cluster, we need sendcnts and displs. Our sendbufs have been built by BucketsBuildScatterBuffers, with a stride given
232  * by numvalues_forcpu. Get this ready to go before starting the scatter itslef. For reference, here is the ISSM_MPI_Scatterv prototype:
233  * int ISSM_MPI_Scatterv( void *sendbuf, int *sendcnts, int *displs, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcnt, ISSM_MPI_Datatype recvtype, int root, ISSM_MPI_Comm comm) :*/
234  sendcnts=xNew<int>(num_procs);
235  displs=xNew<int>(num_procs);
236  count=0;
237  for(i=0;i<num_procs;i++){
238  sendcnts[i]=numvalues_forcpu[i];
239  displs[i]=count;
240  count+=numvalues_forcpu[i];
241  }
242 
243  for(i=0;i<num_procs;i++){
244  ISSM_MPI_Scatterv( row_indices_forcpu, sendcnts, displs, ISSM_MPI_INT, row_indices_fromcpu[i], numvalues_fromcpu[i], ISSM_MPI_INT, i, comm);
245  ISSM_MPI_Scatterv( values_forcpu, sendcnts, displs, TypeToMPIType<doubletype>(), values_fromcpu[i], numvalues_fromcpu[i], TypeToMPIType<doubletype>(), i, comm);
246  ISSM_MPI_Scatterv( modes_forcpu, sendcnts, displs, ISSM_MPI_INT, modes_fromcpu[i], numvalues_fromcpu[i], ISSM_MPI_INT, i, comm);
247  }
248  /*}}}*/
249 
250  /*Plug values into global vector: {{{*/
251  GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,comm);
252  for(i=0;i<num_procs;i++){
253  int numvalues=numvalues_fromcpu[i];
254  int* rows=row_indices_fromcpu[i];
255  doubletype* values=values_fromcpu[i];
256  int* mods=modes_fromcpu[i];
257 
258  for(j=0;j<numvalues;j++){
259  if(mods[j]==ADD_VAL) *(vector+(rows[j]-lower_row))+=values[j];
260  else *(vector+(rows[j]-lower_row))=values[j];
261  }
262  }
263  /*}}}*/
264 
265  /*Free ressources:{{{*/
266  xDelete<int>(RowRank);
267  xDelete<int>(row_indices_forcpu);
268  xDelete<int>(modes_forcpu);
269  xDelete<doubletype>(values_forcpu);
270  xDelete<int>(numvalues_forcpu);
271 
272  for(i=0;i<num_procs;i++){
273  DataSet* bucketsn=bucketsforcpu[i];
274  delete bucketsn;
275  }
276  xDelete<DataSet*>(bucketsforcpu);
277 
278  for(i=0;i<num_procs;i++){
279  int* rows=row_indices_fromcpu[i];
280  int* modes=modes_fromcpu[i];
281  doubletype* values=values_fromcpu[i];
282 
283  xDelete<int>(rows);
284  xDelete<int>(modes);
285  xDelete<doubletype>(values);
286  }
287  xDelete<int*>(row_indices_fromcpu);
288  xDelete<int*>(modes_fromcpu);
289  xDelete<doubletype*>(values_fromcpu);
290  xDelete<int>(numvalues_fromcpu);
291 
292  xDelete<int>(sendcnts);
293  xDelete<int>(displs);
294 
295  /*Get rid of all buckets, as we have already added them to the matrix!: */
296  delete this->buckets;
297  this->buckets=new DataSet();
298  /*}}}*/
299 
300  }

◆ SetValues()

template<class doubletype >
void IssmMpiVec< doubletype >::SetValues ( int  ssize,
int *  list,
doubletype *  values,
InsMode  mode 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 302 of file IssmMpiVec.h.

302  {/*{{{*/
303 
304  /*we need to store all the values we collect here in order to Assemble later.
305  * Indeed, the values we are collecting here most of the time will not belong
306  * to us, but to another part of the vector on another cpu: */
307  _assert_(buckets);
308 
309  buckets->AddObject(new Bucket<doubletype>(ssize, list, values, mode));
310 
311  }

◆ SetValue()

template<class doubletype >
void IssmMpiVec< doubletype >::SetValue ( int  dof,
doubletype  value,
InsMode  mode 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 313 of file IssmMpiVec.h.

313  {/*{{{*/
314 
315  /*we need to store the value we collect here in order to Assemble later.
316  * Indeed, the value we are collecting here most of the time will not belong
317  * to us, but to another part of the vector on another cpu: */
318  _assert_(buckets);
319 
320  buckets->AddObject(new Bucket<doubletype>(1,&dof,&value, mode));
321  }

◆ GetValue()

template<class doubletype >
void IssmMpiVec< doubletype >::GetValue ( doubletype *  pvalue,
int  dof 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 323 of file IssmMpiVec.h.

323  {/*{{{*/
324  _error_("Get value on a MpiVec vector not implemented yet!");
325  }

◆ GetSize()

template<class doubletype >
void IssmMpiVec< doubletype >::GetSize ( int *  pM)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 327 of file IssmMpiVec.h.

327  {/*{{{*/
328 
329  *pM=this->M;
330 
331  }

◆ GetLocalSize()

template<class doubletype >
void IssmMpiVec< doubletype >::GetLocalSize ( int *  pM)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 333 of file IssmMpiVec.h.

333  {/*{{{*/
334 
335  *pM=this->m;
336 
337  }

◆ GetLocalVector()

template<class doubletype >
void IssmMpiVec< doubletype >::GetLocalVector ( doubletype **  pvector,
int **  pindices 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 339 of file IssmMpiVec.h.

339  {/*{{{*/
340 
341  /*First, check that vector size is not 0*/
342  int vector_size;
343  this->GetSize(&vector_size);
344  if(vector_size==0){
345  *pvector=NULL;
346  *pindices=NULL;
347  return;
348  }
349 
350  /*Get Ownership range*/
351  int lower_row,upper_row;
352  GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
353  int range=upper_row-lower_row;
354 
355  /*return NULL if no range*/
356  if(range==0){
357  *pvector=NULL;
358  *pindices=NULL;
359  return;
360  }
361 
362  /*Build indices*/
363  int* indices=xNew<int>(range);
364  for(int i=0;i<range;i++) indices[i]=lower_row+i;
365 
366  /*Get vector*/
367  _assert_(range==this->m);
368  doubletype* values =xNew<doubletype>(range);
369  xMemCpy<doubletype>(values,this->vector,this->m);
370 
371  *pvector = values;
372  *pindices = indices;
373  } /*}}}*/

◆ Duplicate()

template<class doubletype >
IssmMpiVec<doubletype>* IssmMpiVec< doubletype >::Duplicate ( void  )
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 374 of file IssmMpiVec.h.

374  {/*{{{*/
375 
376  return new IssmMpiVec<doubletype>(this->vector,this->M,this->m);
377 
378  }

◆ Set()

template<class doubletype >
void IssmMpiVec< doubletype >::Set ( doubletype  value)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 380 of file IssmMpiVec.h.

380  {/*{{{*/
381 
382  for(int i=0;i<this->m;i++)this->vector[i]=value;
383 
384  }

◆ AXPY()

template<class doubletype >
void IssmMpiVec< doubletype >::AXPY ( IssmAbsVec< doubletype > *  Xin,
doubletype  a 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 386 of file IssmMpiVec.h.

386  {/*{{{*/
387 
388  int i;
389 
390  /*Assume X is of the correct type, and downcast: */
391  IssmMpiVec* X=NULL;
392 
393  X=(IssmMpiVec<doubletype>*)Xin;
394 
395  /*y=a*x+y where this->vector is y*/
396  for(i=0;i<this->m;i++)this->vector[i]=a*X->vector[i]+this->vector[i];
397 
398  }

◆ AYPX()

template<class doubletype >
void IssmMpiVec< doubletype >::AYPX ( IssmAbsVec< doubletype > *  Xin,
doubletype  a 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 400 of file IssmMpiVec.h.

400  {/*{{{*/
401  int i;
402 
403  /*Assume X is of the correct type, and downcast: */
404  IssmMpiVec* X=NULL;
405 
406  X=(IssmMpiVec<doubletype>*)Xin;
407 
408  /*y=x+a*y where this->vector is y*/
409  for(i=0;i<this->m;i++)this->vector[i]=X->vector[i]+a*this->vector[i];
410 
411  }

◆ ToMPISerial()

template<class doubletype >
doubletype* IssmMpiVec< doubletype >::ToMPISerial ( void  )
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 413 of file IssmMpiVec.h.

413  {/*{{{*/
414 
415  /*communicator info: */
416  ISSM_MPI_Comm comm;
417  int num_procs;
418 
419  /*ISSM_MPI_Allgatherv info: */
420  int lower_row,upper_row;
421  int* recvcounts=NULL;
422  int* displs=NULL;
423 
424  /*output: */
425  doubletype* buffer=NULL;
426 
427  /*initialize comm info: */
428  comm=IssmComm::GetComm();
429  num_procs=IssmComm::GetSize();
430 
431 
432  /*Allocate: */
433 // AD performance is sensitive to calls to ensurecontiguous.
434 // Providing "t" will cause ensurecontiguous to be called.
435 #ifdef _HAVE_AD_
436  buffer=xNew<doubletype>(M,"t");
437 #else
438  buffer=xNew<doubletype>(M);
439 #endif
440 
441  recvcounts=xNew<int>(num_procs);
442  displs=xNew<int>(num_procs);
443 
444  /*recvcounts:*/
445  ISSM_MPI_Allgather(&this->m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,comm);
446 
447  /*get lower_row: */
448  GetOwnershipBoundariesFromRange(&lower_row,&upper_row,this->m,comm);
449 
450  /*displs: */
451  ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,comm);
452 
453  /*All gather:*/
454  ISSM_MPI_Allgatherv(this->vector, this->m, TypeToMPIType<doubletype>(), buffer, recvcounts, displs, TypeToMPIType<doubletype>(),comm);
455  /*free ressources: */
456  xDelete<int>(recvcounts);
457  xDelete<int>(displs);
458 
459  /*return: */
460  return buffer;
461 
462  }

◆ ToMPISerial0()

template<class doubletype >
doubletype* IssmMpiVec< doubletype >::ToMPISerial0 ( void  )
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 464 of file IssmMpiVec.h.

464  {/*{{{*/
465 
466  /*FIXME: Should not broadcast to every cpu*/
467  return this->ToMPISerial();
468 
469  }

◆ Shift()

template<class doubletype >
void IssmMpiVec< doubletype >::Shift ( doubletype  shift)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 471 of file IssmMpiVec.h.

471  {/*{{{*/
472  for(int i=0;i<this->m;i++)this->vector[i]+=shift;
473  }

◆ Copy()

template<class doubletype >
void IssmMpiVec< doubletype >::Copy ( IssmAbsVec< doubletype > *  toin)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 475 of file IssmMpiVec.h.

475  {/*{{{*/
476 
477  int i;
478 
479  /*Assume toin is of the correct type, and downcast: */
480  IssmMpiVec* to=NULL;
481 
482  to=(IssmMpiVec<doubletype>*)toin;
483 
484  to->M=this->M;
485  for(i=0;i<this->m;i++)to->vector[i]=this->vector[i];
486 
487  }

◆ Norm()

template<class doubletype >
doubletype IssmMpiVec< doubletype >::Norm ( NormMode  mode)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 489 of file IssmMpiVec.h.

489  {/*{{{*/
490 
491  doubletype local_norm;
492  doubletype norm;
493  int i;
494 
495  switch(mode){
496  case NORM_INF:
497  local_norm=0.; for(i=0;i<this->m;i++)local_norm=max(local_norm,fabs(this->vector[i]));
498  //local_norm=0; for(i=0;i<this->m;i++)local_norm=max(local_norm,this->vector[i]);
499  ISSM_MPI_Reduce(&local_norm, &norm, 1, ISSM_MPI_DOUBLE, ISSM_MPI_MAX, 0, IssmComm::GetComm());
501  return norm;
502  break;
503  case NORM_TWO:
504  local_norm=0.;
505  for(i=0;i<this->m;i++)local_norm+=this->vector[i]*this->vector[i];
506  ISSM_MPI_Reduce(&local_norm, &norm, 1, ISSM_MPI_DOUBLE, ISSM_MPI_SUM, 0, IssmComm::GetComm());
508  return sqrt(norm);
509  break;
510  default:
511  _error_("unknown norm !");
512  break;
513  }
514  }

◆ Scale()

template<class doubletype >
void IssmMpiVec< doubletype >::Scale ( doubletype  scale_factor)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 516 of file IssmMpiVec.h.

516  {/*{{{*/
517 
518  int i;
519  for(i=0;i<this->M;i++)this->vector[i]=scale_factor*this->vector[i];
520 
521  }

◆ Dot()

template<class doubletype >
doubletype IssmMpiVec< doubletype >::Dot ( IssmAbsVec< doubletype > *  inputin)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 523 of file IssmMpiVec.h.

523  {/*{{{*/
524 
525  int i;
526  doubletype local_dot=0;
527  doubletype dot=0;
528 
529  /*Assume inputin is of the correct type, and downcast: */
530  IssmMpiVec* input=NULL;
531 
532  input=(IssmMpiVec<doubletype>*)inputin;
533 
534  for(i=0;i<this->m;i++)local_dot+=this->vector[i]*input->vector[i];
535 
536  /*ISSM_MPI_SUM all the dots across the cluster: */
537  ISSM_MPI_Reduce(&local_dot, &dot, 1, ISSM_MPI_DOUBLE, ISSM_MPI_SUM, 0, IssmComm::GetComm());
539 
540  return dot;
541  }

◆ PointwiseDivide()

template<class doubletype >
void IssmMpiVec< doubletype >::PointwiseDivide ( IssmAbsVec< doubletype > *  xin,
IssmAbsVec< doubletype > *  yin 
)
inlinevirtual

Implements IssmAbsVec< doubletype >.

Definition at line 543 of file IssmMpiVec.h.

543  {/*{{{*/
544 
545  int i;
546 
547  /*Assume xin and yin are of the correct type, and downcast: */
548  IssmMpiVec* x=NULL;
549  IssmMpiVec* y=NULL;
550 
551  x=(IssmMpiVec<doubletype>*)xin;
552  y=(IssmMpiVec<doubletype>*)yin;
553 
554  /*pointwise w=x/y where this->vector is w: */
555  for(i=0;i<this->m;i++)this->vector[i]=x->vector[i]/y->vector[i];
556  }

◆ BucketsBuildScatterBuffers()

template<class doubletype >
void IssmMpiVec< doubletype >::BucketsBuildScatterBuffers ( int **  pnumvalues_forcpu,
int **  prow_indices_forcpu,
doubletype **  pvalues_forcpu,
int **  pmodes_forcpu,
DataSet **  bucketsforcpu,
int  num_procs 
)
inline

Definition at line 558 of file IssmMpiVec.h.

558  {/*{{{*/
559 
560  /*intermediary: */
561  int i,j;
562  int count = 0;
563  int total_size = 0;
564  int *temp_row_indices_forcpu = NULL;
565  doubletype *temp_values_forcpu = NULL;
566  int *temp_modes_forcpu = NULL;
567 
568  /*output: */
569  int *numvalues_forcpu = NULL;
570  int *row_indices_forcpu = NULL;
571  doubletype *values_forcpu = NULL;
572  int *modes_forcpu = NULL;
573 
574  /*figure out size of buffers per cpu: */
575 
576  numvalues_forcpu=xNew<int>(num_procs);
577  for(i=0;i<num_procs;i++){
578  DataSet *buckets = bucketsforcpu[i];
579 
580  count=0;
581  for(j=0;j<buckets->Size();j++){
583  count+=bucket->MarshallSize();
584  }
585 
586  numvalues_forcpu[i]=count;
587  }
588 
589  /*now, figure out size of total buffers (for all cpus!): */
590  count=0;
591  for(i=0;i<num_procs;i++){
592  count+=numvalues_forcpu[i];
593  }
594  total_size=count;
595 
596  /*Allocate buffers: */
597  row_indices_forcpu = xNew<int>(total_size);
598 // AD performance is sensitive to calls to ensurecontiguous.
599 // Providing "t" will cause ensurecontiguous to be called.
600 #ifdef _HAVE_AD_
601  values_forcpu = xNew<doubletype>(total_size,"t");
602 #else
603  values_forcpu = xNew<doubletype>(total_size);
604 #endif
605 
606  modes_forcpu = xNew<int>(total_size);
607 
608  /*we are going to march through the buffers, and marshall data onto them, so in order to not
609  *lose track of where these buffers are located in memory, we are going to work using copies
610  of them: */
611  temp_row_indices_forcpu=row_indices_forcpu;
612  temp_values_forcpu=values_forcpu;
613  temp_modes_forcpu=modes_forcpu;
614 
615  /*Fill buffers: */
616  for(i=0;i<num_procs;i++){
617  DataSet *buckets = bucketsforcpu[i];
618  for(j=0;j<buckets->Size();j++){
620  bucket->Marshall(&temp_row_indices_forcpu,&temp_values_forcpu,&temp_modes_forcpu); //pass in the address of the buffers, so as to have the Marshall routine increment them.
621  }
622  }
623 
624  /*sanity check: */
625  if (temp_row_indices_forcpu!=row_indices_forcpu+total_size)_error_("problem with marshalling of buckets");
626  if (temp_values_forcpu!=values_forcpu+total_size)_error_("problem with marshalling of buckets");
627  if (temp_modes_forcpu!=modes_forcpu+total_size)_error_("problem with marshalling of buckets");
628 
629  /*output buffers: */
630  *pnumvalues_forcpu = numvalues_forcpu;
631  *prow_indices_forcpu = row_indices_forcpu;
632  *pvalues_forcpu = values_forcpu;
633  *pmodes_forcpu = modes_forcpu;
634  }

Field Documentation

◆ M

template<class doubletype >
int IssmMpiVec< doubletype >::M

Definition at line 38 of file IssmMpiVec.h.

◆ m

template<class doubletype >
int IssmMpiVec< doubletype >::m

Definition at line 39 of file IssmMpiVec.h.

◆ vector

template<class doubletype >
doubletype* IssmMpiVec< doubletype >::vector

Definition at line 40 of file IssmMpiVec.h.

◆ buckets

template<class doubletype >
DataSet* IssmMpiVec< doubletype >::buckets

Definition at line 41 of file IssmMpiVec.h.


The documentation for this class was generated from the following file:
DataSet::Size
int Size()
Definition: DataSet.cpp:399
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmMpiVec::vector
doubletype * vector
Definition: IssmMpiVec.h:40
DataSet::AddObject
int AddObject(Object *object)
Definition: DataSet.cpp:252
ISSM_MPI_SUM
#define ISSM_MPI_SUM
Definition: issmmpi.h:134
ADD_VAL
@ ADD_VAL
Definition: toolkitsenums.h:14
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
GetOwnershipBoundariesFromRange
void GetOwnershipBoundariesFromRange(int *plower_row, int *pupper_row, int range, ISSM_MPI_Comm comm)
Definition: GetOwnershipBoundariesFromRange.cpp:16
NORM_INF
@ NORM_INF
Definition: toolkitsenums.h:15
ISSM_MPI_MAX
#define ISSM_MPI_MAX
Definition: issmmpi.h:131
Bucket
Definition: Bucket.h:19
NORM_TWO
@ NORM_TWO
Definition: toolkitsenums.h:15
DetermineLocalSize
int DetermineLocalSize(int global_size, ISSM_MPI_Comm comm)
Definition: DetermineLocalSize.cpp:9
Bucket::MarshallSize
int MarshallSize(void)
Definition: Bucket.h:233
IssmMpiVec::ToMPISerial
doubletype * ToMPISerial(void)
Definition: IssmMpiVec.h:413
DetermineGlobalSize
int DetermineGlobalSize(int local_size, ISSM_MPI_Comm comm)
Definition: DetermineGlobalSize.cpp:10
ISSM_MPI_DOUBLE
#define ISSM_MPI_DOUBLE
Definition: issmmpi.h:125
ISSM_MPI_INT
#define ISSM_MPI_INT
Definition: issmmpi.h:127
IssmMpiVec::buckets
DataSet * buckets
Definition: IssmMpiVec.h:41
IssmComm::GetSize
static int GetSize(void)
Definition: IssmComm.cpp:46
IssmMpiVec::Init
void Init(int Min, bool fromlocalsize)
Definition: IssmMpiVec.h:101
IssmMpiVec::BucketsBuildScatterBuffers
void BucketsBuildScatterBuffers(int **pnumvalues_forcpu, int **prow_indices_forcpu, doubletype **pvalues_forcpu, int **pmodes_forcpu, DataSet **bucketsforcpu, int num_procs)
Definition: IssmMpiVec.h:558
ISSM_MPI_Bcast
int ISSM_MPI_Bcast(void *buffer, int count, ISSM_MPI_Datatype datatype, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:162
Bucket::SpawnBucketsPerCpu
void SpawnBucketsPerCpu(DataSet *bucketsofcpu_i, int rank_i, int *rowranks)
Definition: Bucket.h:137
ISSM_MPI_Allgather
int ISSM_MPI_Allgather(void *sendbuf, int sendcount, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcount, ISSM_MPI_Datatype recvtype, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:45
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
DataSet::GetObjectByOffset
Object * GetObjectByOffset(int offset)
Definition: DataSet.cpp:334
min
IssmDouble min(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:14
ISSM_MPI_Comm
int ISSM_MPI_Comm
Definition: issmmpi.h:118
IssmMpiVec::m
int m
Definition: IssmMpiVec.h:39
ISSM_MPI_Allgatherv
int ISSM_MPI_Allgatherv(void *sendbuf, int sendcount, ISSM_MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, ISSM_MPI_Datatype recvtype, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:79
IssmMpiVec::GetSize
void GetSize(int *pM)
Definition: IssmMpiVec.h:327
ISSM_MPI_Barrier
int ISSM_MPI_Barrier(ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:148
IssmMpiVec
Definition: IssmMpiVec.h:34
ISSM_MPI_Reduce
int ISSM_MPI_Reduce(void *sendbuf, void *recvbuf, int count, ISSM_MPI_Datatype datatype, ISSM_MPI_Op op, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:373
max
IssmDouble max(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:24
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
bamg::Min
T Min(const T &a, const T &b)
Definition: extrema.h:6
IssmMpiVec::M
int M
Definition: IssmMpiVec.h:38
DetermineRowRankFromLocalSize
int * DetermineRowRankFromLocalSize(int global_size, int localsize, ISSM_MPI_Comm comm)
Definition: DetermineRowRankFromLocalSize.cpp:12
ISSM_MPI_Scatter
int ISSM_MPI_Scatter(void *sendbuf, int sendcnt, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcnt, ISSM_MPI_Datatype recvtype, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:407
ISSM_MPI_Scatterv
int ISSM_MPI_Scatterv(void *sendbuf, int *sendcnts, int *displs, ISSM_MPI_Datatype sendtype, void *recvbuf, int recvcnt, ISSM_MPI_Datatype recvtype, int root, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:444