Changeset 14834
- Timestamp:
- 05/01/13 15:56:42 (12 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/classes/objects/Bucket.h
r14833 r14834 187 187 int *modes_forcpu = NULL; 188 188 189 189 190 /*initialize buffers: */ 190 191 row_indices_forcpu=*prow_indices_forcpu; … … 216 217 }; 217 218 /*}}}*/ 219 void Marshall(int** prow_indices_forcpu,doubletype** pvalues_forcpu,int** pmodes_forcpu){ /*{{{*/ 220 221 /*intermediary: */ 222 int i; 223 int j; 224 225 /*buffers: */ 226 int *row_indices_forcpu = NULL; 227 doubletype *values_forcpu = NULL; 228 int *modes_forcpu = NULL; 229 230 231 /*initialize buffers: */ 232 row_indices_forcpu=*prow_indices_forcpu; 233 values_forcpu=*pvalues_forcpu; 234 modes_forcpu=*pmodes_forcpu; 235 236 /*fill buffers with out values and indices and modes: */ 237 for(i=0;i<m;i++){ 238 row_indices_forcpu[i]=idxm[i]; 239 values_forcpu[i]=values[i*n+j]; 240 modes_forcpu[i]=mode; 241 } 242 243 /*increment buffer for next Bucket who will marshall his data: */ 244 row_indices_forcpu+=m; 245 values_forcpu+=m; 246 modes_forcpu+=m; 247 248 /*output modified buffers: */ 249 *prow_indices_forcpu=row_indices_forcpu; 250 *pvalues_forcpu=values_forcpu; 251 *pmodes_forcpu=modes_forcpu; 252 }; 253 /*}}}*/ 218 254 int MarshallSize(void){ /*{{{*/ 219 255 220 if(type= MATRIX_BUCKET){256 if(type==MATRIX_BUCKET){ 221 257 return m*n; 222 258 } -
issm/trunk-jpl/src/c/toolkits/issm/IssmAbsMat.h
r14822 r14834 34 34 */ 35 35 36 template <class doubletype> class IssmAbsVec; 37 class Parameters; 38 36 39 template <class doubletype> 37 40 class IssmAbsMat{ … … 53 56 virtual void SetValues(int m,int* idxm,int n,int* idxn,doubletype* values,InsMode mode)=0; 54 57 virtual void Convert(MatrixType type)=0; 58 virtual IssmAbsVec<IssmDouble>* Solve(IssmAbsVec<IssmDouble>* pf, Parameters* parameters)=0; 55 59 }; 56 60 -
issm/trunk-jpl/src/c/toolkits/issm/IssmDenseMat.h
r14671 r14834 44 44 45 45 /*IssmDenseMat constructors, destructors*/ 46 /* FUNCTIONIssmDenseMat(){{{*/46 /*IssmDenseMat(){{{*/ 47 47 IssmDenseMat(){ 48 48 … … 52 52 } 53 53 /*}}}*/ 54 /* FUNCTIONIssmDenseMat(int M,int N){{{*/54 /*IssmDenseMat(int M,int N){{{*/ 55 55 IssmDenseMat(int pM,int pN){ 56 56 … … 61 61 } 62 62 /*}}}*/ 63 /* FUNCTIONIssmDenseMat(int M,int N, doubletype sparsity){{{*/63 /*IssmDenseMat(int M,int N, doubletype sparsity){{{*/ 64 64 IssmDenseMat(int pM,int pN, doubletype sparsity){ 65 65 … … 70 70 } 71 71 /*}}}*/ 72 /* FUNCTIONIssmDenseMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz){{{*/72 /*IssmDenseMat(int m,int n,int M,int N,int* d_nnz,int* o_nnz){{{*/ 73 73 IssmDenseMat(int m,int n,int pM,int pN,int* d_nnz,int* o_nnz){ 74 74 … … 79 79 } 80 80 /*}}}*/ 81 /* FUNCTIONIssmDenseMat(doubletype* serial_mat,int M,int N,doubletype sparsity){{{*/81 /*IssmDenseMat(doubletype* serial_mat,int M,int N,doubletype sparsity){{{*/ 82 82 IssmDenseMat(doubletype* serial_mat,int pM,int pN,doubletype sparsity){ 83 83 … … 92 92 } 93 93 /*}}}*/ 94 /* FUNCTIONIssmDenseMat(int M,int N, int connectivity, int numberofdofspernode){{{*/94 /*IssmDenseMat(int M,int N, int connectivity, int numberofdofspernode){{{*/ 95 95 IssmDenseMat(int pM,int pN, int connectivity,int numberofdofspernode){ 96 96 … … 101 101 } 102 102 /*}}}*/ 103 /* FUNCTION~IssmDenseMat(){{{*/103 /*~IssmDenseMat(){{{*/ 104 104 ~IssmDenseMat(){ 105 105 … … 110 110 /*}}}*/ 111 111 112 /*Issm DenseMat specific routines*/113 /* FUNCTIONEcho{{{*/112 /*IssmAbsMat virtual functions*/ 113 /*Echo{{{*/ 114 114 void Echo(void){ 115 115 … … 124 124 } 125 125 /*}}}*/ 126 /* FUNCTIONAssemble{{{*/126 /*Assemble{{{*/ 127 127 void Assemble(void){ 128 128 … … 131 131 } 132 132 /*}}}*/ 133 /* FUNCTIONNorm{{{*/133 /*Norm{{{*/ 134 134 doubletype Norm(NormMode mode){ 135 135 … … 156 156 } 157 157 /*}}}*/ 158 /* FUNCTIONGetSize{{{*/158 /*GetSize{{{*/ 159 159 void GetSize(int* pM,int* pN){ 160 160 … … 164 164 } 165 165 /*}}}*/ 166 /* FUNCTIONGetLocalSize{{{*/166 /*GetLocalSize{{{*/ 167 167 void GetLocalSize(int* pM,int* pN){ 168 168 … … 172 172 } 173 173 /*}}}*/ 174 /* FUNCTIONMatMult{{{*/174 /*MatMult{{{*/ 175 175 void MatMult(IssmAbsVec<doubletype>* Xin,IssmAbsVec<doubletype>* AXin){ 176 176 … … 203 203 } 204 204 /*}}}*/ 205 /* FUNCTIONDuplicate{{{*/205 /*Duplicate{{{*/ 206 206 IssmDenseMat<doubletype>* Duplicate(void){ 207 207 … … 212 212 } 213 213 /*}}}*/ 214 /* FUNCTIONToSerial{{{*/214 /*ToSerial{{{*/ 215 215 doubletype* ToSerial(void){ 216 216 … … 225 225 } 226 226 /*}}}*/ 227 /* FUNCTIONSetValues{{{*/227 /*SetValues{{{*/ 228 228 void SetValues(int m,int* idxm,int n,int* idxn,doubletype* values,InsMode mode){ 229 229 … … 243 243 } 244 244 /*}}}*/ 245 /* FUNCTIONConvert{{{*/245 /*Convert{{{*/ 246 246 void Convert(MatrixType type){ 247 247 … … 250 250 } 251 251 /*}}}*/ 252 /*Solve{{{*/ 253 IssmAbsVec<IssmDouble>* Solve(IssmAbsVec<IssmDouble>* pfin, Parameters* parameters){ 254 255 /*First off, we assume that the type of IssmAbsVec is IssmSeqVec. So downcast: */ 256 IssmSeqVec<IssmDouble>* pf=(IssmSeqVec<IssmDouble>*)pfin; 257 258 #ifdef _HAVE_GSL_ 259 /*Intermediary: */ 260 int M,N,N2; 261 IssmSeqVec<IssmDouble> *uf = NULL; 262 263 Kff->GetSize(&M,&N); 264 pf->GetSize(&N2); 265 266 if(N!=N2)_error_("Right hand side vector of size " << N2 << ", when matrix is of size " << M << "-" << N << " !"); 267 if(M!=N)_error_("Stiffness matrix should be square!"); 268 #ifdef _HAVE_ADOLC_ 269 ensureContiguousLocations(N); 270 #endif 271 IssmDouble *x = xNew<IssmDouble>(N); 272 #ifdef _HAVE_ADOLC_ 273 SolverxSeq(x,Kff->matrix,pf->vector,N,parameters); 274 #els 275 SolverxSeq(x,Kff->matrix,pf->vector,N); 276 #endif 277 278 uf=new IssmSeqVec<IssmDouble>(x,N); 279 xDelete(x); 280 281 /*Assign output pointers:*/ 282 IssmVec<IssmDouble>* out=new IssmVec<IssmDouble>(); 283 out->vector=(IssmAbsVec<IssmDouble>*)uf; 284 *pout=out; 285 286 #else 287 _error_("GSL support not compiled in!"); 288 #endif 289 290 }/*}}}*/ 252 291 253 292 }; -
issm/trunk-jpl/src/c/toolkits/issm/IssmMat.h
r14822 r14834 34 34 template <class doubletype> class IssmDenseMat; 35 35 template <class doubletype> class IssmMpiDenseMat; 36 class Parameters; 36 37 37 38 template <class doubletype> … … 199 200 matrix->convert(type); 200 201 }/*}}}*/ 202 IssmVec<doubletype>* Solve(IssmVec<doubletype>* pf, Parameters* parameters){ /*{{{*/ 203 204 IssmVec<doubletype>* outvector=NULL; 205 206 outvector=new IssmVec<doubletype>(); 207 208 outvector->vector=this->matrix->Solve(pf->vector,parameters); 209 210 }/*}}}*/ 201 211 202 212 }; -
issm/trunk-jpl/src/c/toolkits/issm/IssmMpiDenseMat.h
r14833 r14834 142 142 printf("%g ",this->matrix[j*this->N+k]); 143 143 } 144 printf("\n"); 144 145 } 145 146 } … … 302 303 RowRank=DetermineRowRankFromLocalSize(M,m,comm); 303 304 304 /*Now, sort out our dataset of buckets according to cpu ownership of rows: */305 /*Now, sort out our dataset of buckets according to cpu ownership of rows: {{{*/ 305 306 bucketsforcpu=xNew<DataSet*>(num_procs); 306 307 … … 313 314 bucketsforcpu[i]=bucketsofcpu_i; 314 315 } 315 316 /*Recap, each cpu has num_procs datasets of buckets. For a certain cpu j, for a given dataset i, the buckets this 316 /*}}}*/ 317 318 /*Recap, each cpu has num_procs datasets of buckets. For a certain cpu j, for a given dataset i, the buckets this {{{ 317 319 * 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 318 320 * vectors that will be shipped around the cluster: */ 319 321 this->BucketsBuildScatterBuffers(&numvalues_forcpu,&row_indices_forcpu,&col_indices_forcpu,&values_forcpu,&modes_forcpu,bucketsforcpu,num_procs); 320 321 /*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 322 /*}}}*/ 323 324 /*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 {{{ 322 325 *some scatter calls: */ 323 326 numvalues_fromcpu = xNew<int>(num_procs); 324 327 for(i=0;i<num_procs;i++){ 325 MPI_Scatter(numvalues_forcpu,num_procs,MPI_INT,numvalues_fromcpu+i,1,MPI_INT,i,comm); 326 } 327 for(i=0;i<num_procs;i++){ 328 row_indices_fromcpu[i]=xNew<int>(numvalues_fromcpu[i]); 329 col_indices_fromcpu[i]=xNew<int>(numvalues_fromcpu[i]); 330 values_fromcpu[i]=xNew<doubletype>(numvalues_fromcpu[i]); 331 modes_fromcpu[i]=xNew<int>(numvalues_fromcpu[i]); 332 } 333 328 MPI_Scatter(numvalues_forcpu,1,MPI_INT,numvalues_fromcpu+i,1,MPI_INT,i,comm); 329 } 330 331 row_indices_fromcpu=xNew<int*>(num_procs); 332 col_indices_fromcpu=xNew<int*>(num_procs); 333 values_fromcpu=xNew<doubletype*>(num_procs); 334 modes_fromcpu=xNew<int*>(num_procs); 335 for(i=0;i<num_procs;i++){ 336 int size=numvalues_fromcpu[i]; 337 if(size){ 338 row_indices_fromcpu[i]=xNew<int>(size); 339 col_indices_fromcpu[i]=xNew<int>(size); 340 values_fromcpu[i]=xNew<doubletype>(size); 341 modes_fromcpu[i]=xNew<int>(size); 342 } 343 else{ 344 row_indices_fromcpu[i]=NULL; 345 col_indices_fromcpu[i]=NULL; 346 values_fromcpu[i]=NULL; 347 modes_fromcpu[i]=NULL; 348 } 349 } 350 /*}}}*/ 351 352 /*Scatter values around: {{{*/ 334 353 /*Now, to scatter values across the cluster, we need sendcnts and displs. Our sendbufs have been built by BucketsBuildScatterBuffers, with a stride given 335 354 * by numvalues_forcpu. Get this ready to go before starting the scatter itslef. For reference, here is the MPI_Scatterv prototype: … … 344 363 } 345 364 346 /*Start the scattering: */347 365 for(i=0;i<num_procs;i++){ 348 366 MPI_Scatterv( row_indices_forcpu, sendcnts, displs, MPI_INT, row_indices_fromcpu[i], numvalues_fromcpu[i], MPI_INT, i, comm); … … 351 369 MPI_Scatterv( modes_forcpu, sendcnts, displs, MPI_INT, modes_fromcpu[i], numvalues_fromcpu[i], MPI_INT, i, comm); 352 370 } 353 354 /*Plug values into global matrix: */ 371 /*}}}*/ 372 373 /*Plug values into global matrix: {{{*/ 355 374 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,comm); 356 375 for(i=0;i<num_procs;i++){ … … 366 385 } 367 386 } 368 387 /*}}}*/ 388 369 389 /*Free ressources:{{{*/ 370 390 xDelete<int>(RowRank); … … 523 543 524 544 /*figure out size of buffers per cpu: */ 545 546 numvalues_forcpu=xNew<int>(num_procs); 525 547 for(i=0;i<num_procs;i++){ 526 548 DataSet *buckets = bucketsforcpu[i]; … … 565 587 } 566 588 589 /*sanity check: */ 590 if (temp_row_indices_forcpu!=row_indices_forcpu+total_size)_error_("problem with marshalling of buckets"); 591 if (temp_col_indices_forcpu!=col_indices_forcpu+total_size)_error_("problem with marshalling of buckets"); 592 if (temp_values_forcpu!=values_forcpu+total_size)_error_("problem with marshalling of buckets"); 593 if (temp_modes_forcpu!=modes_forcpu+total_size)_error_("problem with marshalling of buckets"); 594 567 595 /*output buffers: */ 568 *pnumvalues_forcpu = row_indices_forcpu;596 *pnumvalues_forcpu = numvalues_forcpu; 569 597 *prow_indices_forcpu = row_indices_forcpu; 570 598 *pcol_indices_forcpu = col_indices_forcpu; … … 573 601 } 574 602 /*}}}*/ 603 /*Solve{{{*/ 604 IssmAbsVec<IssmDouble>* Solve(IssmAbsVec<IssmDouble>* pfin, Parameters* parameters){ 605 606 printf("IssmMpiDenseMat solve not implemented yet!"); 607 exit(1); 608 609 }/*}}}*/ 575 610 }; 576 611 -
issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h
r14822 r14834 126 126 /*FUNCTION Assemble{{{*/ 127 127 void Assemble(){ 128 129 130 int i,j; 131 132 int *RowRank = NULL; 133 int num_procs; 134 135 int *row_indices_forcpu = NULL; 136 int *col_indices_forcpu = NULL; 137 int *modes_forcpu = NULL; 138 doubletype *values_forcpu = NULL; 139 int *numvalues_forcpu = NULL; 140 DataSet **bucketsforcpu = NULL; 141 142 int **row_indices_fromcpu = NULL; 143 int **col_indices_fromcpu = NULL; 144 int **modes_fromcpu = NULL; 145 doubletype **values_fromcpu = NULL; 146 int *numvalues_fromcpu = NULL; 147 148 int lower_row; 149 int upper_row; 150 int* sendcnts = NULL; 151 int* displs = NULL; 152 int count = 0; 153 154 /*some communicator info: */ 155 num_procs=IssmComm::GetSize(); 156 MPI_Comm comm=IssmComm::GetComm(); 157 158 159 /*First, make a vector of size M, which for each row between 0 and M-1, tells which cpu this row belongs to: */ 160 RowRank=DetermineRowRankFromLocalSize(M,m,comm); 161 162 163 /*Now, sort out our dataset of buckets according to cpu ownership of rows: {{{*/ 164 bucketsforcpu=xNew<DataSet*>(num_procs); 165 166 for(i=0;i<num_procs;i++){ 167 DataSet* bucketsofcpu_i=new DataSet(); 168 for (j=0;j<buckets->Size();j++){ 169 Bucket<doubletype>* bucket=(Bucket<doubletype>*)buckets->GetObjectByOffset(j); 170 bucket->SpawnBucketsPerCpu(bucketsofcpu_i,i,RowRank); 171 } 172 bucketsforcpu[i]=bucketsofcpu_i; 173 } 174 /*}}}*/ 175 176 /*Recap, each cpu has num_procs datasets of buckets. For a certain cpu j, for a given dataset i, the buckets this {{{ 177 * 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 178 * vectors that will be shipped around the cluster: */ 179 this->BucketsBuildScatterBuffers(&numvalues_forcpu,&row_indices_forcpu,&values_forcpu,&modes_forcpu,bucketsforcpu,num_procs); 180 /*}}}*/ 181 182 /*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 {{{ 183 *some scatter calls: */ 184 numvalues_fromcpu = xNew<int>(num_procs); 185 for(i=0;i<num_procs;i++){ 186 MPI_Scatter(numvalues_forcpu,1,MPI_INT,numvalues_fromcpu+i,1,MPI_INT,i,comm); 187 } 188 189 row_indices_fromcpu=xNew<int*>(num_procs); 190 values_fromcpu=xNew<doubletype*>(num_procs); 191 modes_fromcpu=xNew<int*>(num_procs); 192 for(i=0;i<num_procs;i++){ 193 int size=numvalues_fromcpu[i]; 194 if(size){ 195 row_indices_fromcpu[i]=xNew<int>(size); 196 values_fromcpu[i]=xNew<doubletype>(size); 197 modes_fromcpu[i]=xNew<int>(size); 198 } 199 else{ 200 row_indices_fromcpu[i]=NULL; 201 values_fromcpu[i]=NULL; 202 modes_fromcpu[i]=NULL; 203 } 204 } 205 /*}}}*/ 206 207 /*Scatter values around: {{{*/ 208 /*Now, to scatter values across the cluster, we need sendcnts and displs. Our sendbufs have been built by BucketsBuildScatterBuffers, with a stride given 209 * by numvalues_forcpu. Get this ready to go before starting the scatter itslef. For reference, here is the MPI_Scatterv prototype: 210 * int MPI_Scatterv( void *sendbuf, int *sendcnts, int *displs, MPI_Datatype sendtype, void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) :*/ 211 sendcnts=xNew<int>(num_procs); 212 displs=xNew<int>(num_procs); 213 count=0; 214 for(i=0;i<num_procs;i++){ 215 sendcnts[i]=numvalues_forcpu[i]; 216 displs[i]=count; 217 count+=numvalues_forcpu[i]; 218 } 219 220 for(i=0;i<num_procs;i++){ 221 MPI_Scatterv( row_indices_forcpu, sendcnts, displs, MPI_INT, row_indices_fromcpu[i], numvalues_fromcpu[i], MPI_INT, i, comm); 222 MPI_Scatterv( values_forcpu, sendcnts, displs, MPI_DOUBLE, values_fromcpu[i], numvalues_fromcpu[i], MPI_DOUBLE, i, comm); 223 MPI_Scatterv( modes_forcpu, sendcnts, displs, MPI_INT, modes_fromcpu[i], numvalues_fromcpu[i], MPI_INT, i, comm); 224 } 225 /*}}}*/ 226 227 /*Plug values into global vector: {{{*/ 228 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,comm); 229 for(i=0;i<num_procs;i++){ 230 int numvalues=numvalues_fromcpu[i]; 231 int* rows=row_indices_fromcpu[i]; 232 doubletype* values=values_fromcpu[i]; 233 int* mods=modes_fromcpu[i]; 234 235 for(j=0;j<numvalues;j++){ 236 if(mods[j]==ADD_VAL) *(vector+(rows[j]-lower_row))+=values[j]; 237 else *(vector+(rows[j]-lower_row))=values[j]; 238 } 239 } 240 /*}}}*/ 241 242 /*Free ressources:{{{*/ 243 xDelete<int>(RowRank); 244 xDelete<int>(row_indices_forcpu); 245 xDelete<int>(modes_forcpu); 246 xDelete<doubletype>(values_forcpu); 247 xDelete<int>(numvalues_forcpu); 248 249 for(i=0;i<num_procs;i++){ 250 DataSet* buckets=bucketsforcpu[i]; 251 delete buckets; 252 } 253 xDelete<DataSet*>(bucketsforcpu); 254 255 for(i=0;i<num_procs;i++){ 256 int* rows=row_indices_fromcpu[i]; 257 int* modes=modes_fromcpu[i]; 258 doubletype* values=values_fromcpu[i]; 259 260 xDelete<int>(rows); 261 xDelete<int>(modes); 262 xDelete<doubletype>(values); 263 } 264 xDelete<int*>(row_indices_fromcpu); 265 xDelete<int*>(modes_fromcpu); 266 xDelete<doubletype*>(values_fromcpu); 267 xDelete<int>(numvalues_fromcpu); 268 269 xDelete<int>(sendcnts); 270 xDelete<int>(displs); 271 /*}}}*/ 272 273 274 } 275 /*}}}*/ 276 /*FUNCTION Assemble2{{{*/ 277 void Assemble2(){ 128 278 129 279 int i; … … 461 611 } 462 612 /*}}}*/ 613 /*FUNCTION BucketsBuildScatterBuffers{{{*/ 614 void BucketsBuildScatterBuffers(int** pnumvalues_forcpu,int** prow_indices_forcpu,doubletype** pvalues_forcpu,int** pmodes_forcpu,DataSet** bucketsforcpu,int num_procs){ 615 616 617 /*intermediary: */ 618 int i,j; 619 int count = 0; 620 int total_size = 0; 621 int *temp_row_indices_forcpu = NULL; 622 doubletype *temp_values_forcpu = NULL; 623 int *temp_modes_forcpu = NULL; 624 625 /*output: */ 626 int *numvalues_forcpu = NULL; 627 int *row_indices_forcpu = NULL; 628 doubletype *values_forcpu = NULL; 629 int *modes_forcpu = NULL; 630 631 /*figure out size of buffers per cpu: */ 632 633 numvalues_forcpu=xNew<int>(num_procs); 634 for(i=0;i<num_procs;i++){ 635 DataSet *buckets = bucketsforcpu[i]; 636 637 count=0; 638 for(j=0;j<buckets->Size();j++){ 639 Bucket<doubletype>* bucket =(Bucket<doubletype>*)buckets->GetObjectByOffset(j); 640 count+=bucket->MarshallSize(); 641 } 642 643 numvalues_forcpu[i]=count; 644 } 645 646 /*now, figure out size of total buffers (for all cpus!): */ 647 count=0; 648 for(i=0;i<num_procs;i++){ 649 count+=numvalues_forcpu[i]; 650 } 651 total_size=count; 652 653 /*Allocate buffers: */ 654 row_indices_forcpu = xNew<int>(total_size); 655 values_forcpu = xNew<doubletype>(total_size); 656 modes_forcpu = xNew<int>(total_size); 657 658 /*we are going to march through the buffers, and marshall data onto them, so in order to not 659 *lose track of where these buffers are located in memory, we are going to work using copies 660 of them: */ 661 temp_row_indices_forcpu=row_indices_forcpu; 662 temp_values_forcpu=values_forcpu; 663 temp_modes_forcpu=modes_forcpu; 664 665 /*Fill buffers: */ 666 for(i=0;i<num_procs;i++){ 667 DataSet *buckets = bucketsforcpu[i]; 668 for(j=0;j<buckets->Size();j++){ 669 Bucket<doubletype>* bucket =(Bucket<doubletype>*)buckets->GetObjectByOffset(j); 670 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. 671 } 672 } 673 674 /*sanity check: */ 675 if (temp_row_indices_forcpu!=row_indices_forcpu+total_size)_error_("problem with marshalling of buckets"); 676 if (temp_values_forcpu!=values_forcpu+total_size)_error_("problem with marshalling of buckets"); 677 if (temp_modes_forcpu!=modes_forcpu+total_size)_error_("problem with marshalling of buckets"); 678 679 /*output buffers: */ 680 *pnumvalues_forcpu = numvalues_forcpu; 681 *prow_indices_forcpu = row_indices_forcpu; 682 *pvalues_forcpu = values_forcpu; 683 *pmodes_forcpu = modes_forcpu; 684 } 685 /*}}}*/ 463 686 }; 464 687 #endif //#ifndef _ISSM_MPI_VEC_H_ -
issm/trunk-jpl/src/c/toolkits/issm/IssmSolver.cpp
r14792 r14834 1 /*!\file SolverxSeq2 * \brief implementation of s equential solver using the GSL librarie1 /*!\file IssmSolver 2 * \brief implementation of solver 3 3 */ 4 4 … … 20 20 #endif 21 21 22 void IssmSolve(IssmVec<IssmDouble>** pout,IssmMat<IssmDouble>* Kffin, IssmVec<IssmDouble>* pfin, Parameters* parameters){/*{{{*/ 23 24 /*First off, we assume that the type of IssmVec is IssmSeqVec and the type of IssmMat is IssmDenseMat. So downcast: */ 25 IssmSeqVec<IssmDouble>* pf=(IssmSeqVec<IssmDouble>*)pfin->vector; 26 IssmDenseMat<IssmDouble>* Kff=(IssmDenseMat<IssmDouble>*)Kffin->matrix; 27 28 #ifdef _HAVE_GSL_ 29 /*Intermediary: */ 30 int M,N,N2; 31 IssmSeqVec<IssmDouble> *uf = NULL; 32 33 Kff->GetSize(&M,&N); 34 pf->GetSize(&N2); 35 36 if(N!=N2)_error_("Right hand side vector of size " << N2 << ", when matrix is of size " << M << "-" << N << " !"); 37 if(M!=N)_error_("Stiffness matrix should be square!"); 38 #ifdef _HAVE_ADOLC_ 39 ensureContiguousLocations(N); 40 #endif 41 IssmDouble *x = xNew<IssmDouble>(N); 42 #ifdef _HAVE_ADOLC_ 43 SolverxSeq(x,Kff->matrix,pf->vector,N,parameters); 44 #else 45 SolverxSeq(x,Kff->matrix,pf->vector,N); 46 #endif 47 48 uf=new IssmSeqVec<IssmDouble>(x,N); 49 xDelete(x); 50 51 /*Assign output pointers:*/ 52 IssmVec<IssmDouble>* out=new IssmVec<IssmDouble>(); 53 out->vector=(IssmAbsVec<IssmDouble>*)uf; 54 *pout=out; 55 56 #else 57 _error_("GSL support not compiled in!"); 58 #endif 59 60 }/*}}}*/ 22 void IssmSolve(IssmVec<IssmDouble>** pout,IssmMat<IssmDouble>* Kff, IssmVec<IssmDouble>* pf, Parameters* parameters){/*{{{*/ 23 24 /*Let matrix decide, to retain object orientation: */ 25 IssmVec<IssmDouble>* outvector=NULL; 26 27 outvector=Kff->Solve(pf,parameters); 28 29 *pout=outvector; 30 } 31 /*}}}*/ 61 32 void SolverxSeq(IssmPDouble **pX, IssmPDouble *A, IssmPDouble *B,int n){ /*{{{*/ 62 33
Note:
See TracChangeset
for help on using the changeset viewer.