Changeset 25995 for issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h
- Timestamp:
- 02/17/21 09:25:47 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h
r25336 r25995 1 1 /*!\file: IssmMpiVec.h 2 * \brief implementation of parallel dense ISSM vector. Internally, the parallel dense vector is 3 * split in rows across each cpu. Each vector (representing a subset of rows) on each cpu is fully 4 * dense, and is represented by a linear buffer of type doubletype. 5 * This object needs to answer the API defined by the virtual functions in IssmAbsVec, 2 * \brief implementation of parallel dense ISSM vector. Internally, the parallel dense vector is 3 * split in rows across each cpu. Each vector (representing a subset of rows) on each cpu is fully 4 * dense, and is represented by a linear buffer of type doubletype. 5 * This object needs to answer the API defined by the virtual functions in IssmAbsVec, 6 6 * and the contructors required by IssmVec (see IssmVec.h) 7 */ 7 */ 8 8 9 9 #ifndef _ISSM_MPI_VEC_H_ … … 26 26 /*}}}*/ 27 27 28 /*We need to template this class, in case we want to create vectors that hold IssmDouble* vector or IssmPDouble* vector. 29 Such vectors would be useful for use without or with the matlab or python interface (which do not care for IssmDouble types, 28 /*We need to template this class, in case we want to create vectors that hold IssmDouble* vector or IssmPDouble* vector. 29 Such vectors would be useful for use without or with the matlab or python interface (which do not care for IssmDouble types, 30 30 but only rely on IssmPDouble types)*/ 31 31 template <class doubletype> class IssmAbsVec; 32 32 33 template <class doubletype> 33 template <class doubletype> 34 34 class IssmMpiVec:public IssmAbsVec<doubletype>{ 35 35 … … 206 206 207 207 /*Recap, each cpu has num_procs datasets of buckets. For a certain cpu j, for a given dataset i, the buckets this {{{ 208 * 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 208 * 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 209 209 * vectors that will be shipped around the cluster: */ 210 210 this->BucketsBuildScatterBuffers(&numvalues_forcpu,&row_indices_forcpu,&values_forcpu,&modes_forcpu,bucketsforcpu,num_procs); … … 244 244 245 245 /*Scatter values around: {{{*/ 246 /*Now, to scatter values across the cluster, we need sendcnts and displs. Our sendbufs have been built by BucketsBuildScatterBuffers, with a stride given 247 * by numvalues_forcpu. Get this ready to go before starting the scatter itslef. For reference, here is the ISSM_MPI_Scatterv prototype: 246 /*Now, to scatter values across the cluster, we need sendcnts and displs. Our sendbufs have been built by BucketsBuildScatterBuffers, with a stride given 247 * by numvalues_forcpu. Get this ready to go before starting the scatter itslef. For reference, here is the ISSM_MPI_Scatterv prototype: 248 248 * 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) :*/ 249 249 sendcnts=xNew<int>(num_procs); … … 308 308 xDelete<int>(sendcnts); 309 309 xDelete<int>(displs); 310 310 311 311 /*Get rid of all buckets, as we have already added them to the matrix!: */ 312 312 delete this->buckets; … … 318 318 void SetValues(int ssize, int* list, doubletype* values, InsMode mode){/*{{{*/ 319 319 320 /*we need to store all the values we collect here in order to Assemble later. 321 * Indeed, the values we are collecting here most of the time will not belong 320 /*we need to store all the values we collect here in order to Assemble later. 321 * Indeed, the values we are collecting here most of the time will not belong 322 322 * to us, but to another part of the vector on another cpu: */ 323 323 _assert_(buckets); … … 329 329 void SetValue(int dof, doubletype value, InsMode mode){/*{{{*/ 330 330 331 /*we need to store the value we collect here in order to Assemble later. 332 * Indeed, the value we are collecting here most of the time will not belong 331 /*we need to store the value we collect here in order to Assemble later. 332 * Indeed, the value we are collecting here most of the time will not belong 333 333 * to us, but to another part of the vector on another cpu: */ 334 334 _assert_(buckets); … … 365 365 366 366 /*Get Ownership range*/ 367 int lower_row,upper_row; 367 int lower_row,upper_row; 368 368 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm()); 369 int range=upper_row-lower_row; 369 int range=upper_row-lower_row; 370 370 371 371 /*return NULL if no range*/ … … 377 377 378 378 /*Build indices*/ 379 int* indices=xNew<int>(range); 379 int* indices=xNew<int>(range); 380 380 for(int i=0;i<range;i++) indices[i]=lower_row+i; 381 381 … … 518 518 break; 519 519 case NORM_TWO: 520 local_norm=0.; 520 local_norm=0.; 521 521 for(i=0;i<this->m;i++)local_norm+=this->vector[i]*this->vector[i]; 522 522 ISSM_MPI_Reduce(&local_norm, &norm, 1, ISSM_MPI_DOUBLE, ISSM_MPI_SUM, 0, IssmComm::GetComm()); … … 570 570 /*pointwise w=x/y where this->vector is w: */ 571 571 for(i=0;i<this->m;i++)this->vector[i]=x->vector[i]/y->vector[i]; 572 } 573 /*}}}*/ 574 void PointwiseMult(IssmAbsVec<doubletype>* xin,IssmAbsVec<doubletype>* yin){/*{{{*/ 575 576 int i; 577 578 /*Assume xin and yin are of the correct type, and downcast: */ 579 IssmMpiVec* x=NULL; 580 IssmMpiVec* y=NULL; 581 582 x=(IssmMpiVec<doubletype>*)xin; 583 y=(IssmMpiVec<doubletype>*)yin; 584 585 /*pointwise w=x*y where this->vector is w: */ 586 for(i=0;i<this->m;i++)this->vector[i]=x->vector[i]*y->vector[i]; 587 } 588 /*}}}*/ 589 void Pow(doubletype scale_factor){/*{{{*/ 590 591 int i; 592 for(i=0;i<this->M;i++)this->vector[i]=pow(this->vector[i],scale_factor); 593 572 594 } 573 595 /*}}}*/ … … 623 645 624 646 /*we are going to march through the buffers, and marshall data onto them, so in order to not 625 *lose track of where these buffers are located in memory, we are going to work using copies 647 *lose track of where these buffers are located in memory, we are going to work using copies 626 648 of them: */ 627 649 temp_row_indices_forcpu=row_indices_forcpu; … … 649 671 *pmodes_forcpu = modes_forcpu; 650 672 } 651 /*}}}*/ 673 /*}}}*/ 652 674 }; 653 #endif //#ifndef _ISSM_MPI_VEC_H_ 675 #endif //#ifndef _ISSM_MPI_VEC_H_
Note:
See TracChangeset
for help on using the changeset viewer.