Changeset 14792
- Timestamp:
- 04/29/13 15:36:48 (12 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 7 added
- 3 deleted
- 10 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/Makefile.am
r14769 r14792 119 119 ./classes/matrix/ElementVector.h\ 120 120 ./classes/matrix/ElementVector.cpp\ 121 ./classes/matrix/Matrix.h\ 122 ./classes/matrix/Vector.h\ 121 ./classes/toolkits/toolkitobjects.h\ 122 ./classes/toolkits/Matrix.h\ 123 ./classes/toolkits/Vector.h\ 124 ./classes/toolkits/Solver.h\ 123 125 ./classes/objects/Params/Param.h\ 124 126 ./classes/objects/Params/GenericParam.h\ … … 229 231 ./toolkits/issm/IssmSeqVec.h\ 230 232 ./toolkits/issm/IssmVec.h\ 233 ./toolkits/issm/IssmSolver.h\ 234 ./toolkits/issm/IssmSolver.cpp\ 231 235 ./toolkits/triangle/triangleincludes.h\ 232 236 ./toolkitsenums.h\ … … 320 324 ./modules/Solverx/Solverx.cpp\ 321 325 ./modules/Solverx/Solverx.h\ 322 ./modules/Solverx/SolverxSeq.cpp\323 326 ./modules/VecMergex/VecMergex.cpp\ 324 327 ./modules/VecMergex/VecMergex.h\ … … 760 763 ./toolkits/petsc/objects/PetscVec.h\ 761 764 ./toolkits/petsc/objects/PetscVec.cpp\ 762 ./toolkits/petsc/ petscincludes.h\763 ./ modules/Solverx/SolverxPetsc.cpp\764 ./ modules/Solverx/DofTypesToIndexSet.cpp765 ./toolkits/petsc/objects/PetscSolver.cpp\ 766 ./toolkits/petsc/objects/PetscSolver.h\ 767 ./toolkits/petsc/petscincludes.h 765 768 766 769 #}}} -
issm/trunk-jpl/src/c/classes/classes.h
r14734 r14792 11 11 /*matrix: */ 12 12 #include "./matrix/matrixobjects.h" 13 14 /*toolkit objects: */ 15 #include "./toolkits/toolkitobjects.h" 13 16 14 17 /*bamg: */ -
issm/trunk-jpl/src/c/classes/matrix/matrixobjects.h
r13623 r14792 9 9 #include "./ElementMatrix.h" 10 10 #include "./ElementVector.h" 11 #include "./Vector.h"12 #include "./Matrix.h"13 11 14 12 #endif -
issm/trunk-jpl/src/c/classes/toolkits/Matrix.h
r14782 r14792 324 324 } 325 325 /*}}}*/ 326 326 327 }; 327 328 -
issm/trunk-jpl/src/c/modules/Solverx/CMakeLists.txt
r14284 r14792 5 5 # }}} 6 6 # CORE_SOURCES {{{ 7 set(CORE_SOURCES $ENV{ISSM_DIR}/src/c/modules/Solverx/Solverx.cpp 8 $ENV{ISSM_DIR}/src/c/modules/Solverx/SolverxSeq.cpp PARENT_SCOPE) 7 set(CORE_SOURCES $ENV{ISSM_DIR}/src/c/modules/Solverx/Solverx.cpp PARENT_SCOPE) 9 8 # }}} -
issm/trunk-jpl/src/c/modules/Solverx/Solverx.cpp
r14665 r14792 2 2 * \brief solver 3 3 */ 4 5 #include "./Solverx.h"6 #include "../../shared/shared.h"7 #include "../../include/include.h"8 #include "../../io/io.h"9 4 10 5 #ifdef HAVE_CONFIG_H … … 14 9 #endif 15 10 11 #include "./Solverx.h" 12 #include "../../shared/shared.h" 13 16 14 void Solverx(Vector<IssmDouble>** puf, Matrix<IssmDouble>* Kff, Vector<IssmDouble>* pf, Vector<IssmDouble>* uf0,Vector<IssmDouble>* df, Parameters* parameters){ 17 15 16 /*intermediary: */ 17 Solver<IssmDouble> *solver=NULL; 18 18 19 /*output: */ 19 20 Vector<IssmDouble> *uf=NULL; 20 21 21 /*In debugging mode, check that stiffness matrix and load vectors are not NULL (they can be empty)*/22 _assert_(Kff);23 _assert_(pf);24 25 22 if(VerboseModule()) _pprintLine_(" Solving matrix system"); 26 23 27 /*Initialize vector: */28 uf=new Vector<IssmDouble>();24 /*Initialize solver: */ 25 solver=new Solver<IssmDouble>(Kff,pf,uf0,df,parameters); 29 26 30 /*According to matrix type, use specific solvers: */ 31 switch(Kff->type){ 32 #ifdef _HAVE_PETSC_ 33 case PetscMatType:{ 34 PetscVec* uf0_vector = NULL; 35 PetscVec* df_vector = NULL; 36 if(uf0) uf0_vector = uf0->pvector; 37 if(df) df_vector = df->pvector; 38 SolverxPetsc(&uf->pvector,Kff->pmatrix,pf->pvector,uf0_vector,df_vector,parameters); 39 break;} 40 #endif 41 case IssmMatType:{ 42 SolverxSeq(&uf->ivector,Kff->imatrix,pf->ivector,parameters); 43 break;} 44 default: 45 _error_("Matrix type: " << Kff->type << " not supported yet!"); 46 } 27 /*Solve:*/ 28 uf=solver->Solve(); 47 29 48 30 /*Assign output pointers:*/ -
issm/trunk-jpl/src/c/modules/Solverx/Solverx.h
r14656 r14792 12 12 #endif 13 13 14 #include "../../classes/objects/objects.h" 15 #include "../../toolkits/toolkits.h" 14 #include "../../classes/toolkits/toolkitobjects.h" 16 15 17 16 /* local prototypes: */ 18 17 void Solverx(Vector<IssmDouble>** puf, Matrix<IssmDouble>* Kff, Vector<IssmDouble>* pf, Vector<IssmDouble>* uf0,Vector<IssmDouble>* df, Parameters* parameters); 19 18 20 #ifdef _HAVE_PETSC_21 void SolverxPetsc(PetscVec** puf, PetscMat* Kff, PetscVec* pf, PetscVec* uf0,PetscVec* df, Parameters* parameters);22 void SolverxPetsc(Vec* puf, Mat Kff, Vec pf, Vec uf0,Vec df, Parameters* parameters);23 void DofTypesToIndexSet(IS* pisv, IS* pisp, Vec df,int typeenum);24 #endif25 26 void SolverxSeq(IssmVec<IssmDouble>** puf,IssmMat<IssmDouble>* Kff, IssmVec<IssmDouble>* pf,Parameters* parameters);27 void SolverxSeq(IssmPDouble **pX, IssmPDouble *A, IssmPDouble *B,int n);28 void SolverxSeq(IssmPDouble *X, IssmPDouble *A, IssmPDouble *B,int n);29 30 #if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)31 void SolverxSeq(IssmDouble *X,IssmDouble *A,IssmDouble *B,int n, Parameters* parameters);32 // call back functions:33 ADOLC_ext_fct EDF_for_solverx;34 ADOLC_ext_fct_fos_forward EDF_fos_forward_for_solverx;35 ADOLC_ext_fct_fos_reverse EDF_fos_reverse_for_solverx;36 ADOLC_ext_fct_fov_forward EDF_fov_forward_for_solverx;37 ADOLC_ext_fct_fov_reverse EDF_fov_reverse_for_solverx;38 #endif39 40 19 #endif /* _SOLVERX_H */ -
issm/trunk-jpl/src/c/toolkits/issm/IssmMpiDenseMat.h
r14750 r14792 272 272 /*FUNCTION Norm{{{*/ 273 273 doubletype Norm(NormMode mode){ 274 _error_("not supported yet!"); 274 275 276 doubletype norm,local_norm; 277 doubletype absolute; 278 int i,j; 279 280 switch(mode){ 281 case NORM_INF: 282 local_norm=0; 283 for(i=0;i<this->M;i++){ 284 absolute=0; 285 for(j=0;j<this->N;j++){ 286 absolute+=fabs(this->matrix[N*i+j]); 287 } 288 local_norm=max(local_norm,absolute); 289 } 290 MPI_Reduce(&local_norm, &norm, 1, MPI_DOUBLE, MPI_MAX, 0, IssmComm::GetComm()); 291 MPI_Bcast(&norm,1,MPI_DOUBLE,0,IssmComm::GetComm()); 292 return norm; 293 break; 294 default: 295 _error_("unknown norm !"); 296 break; 297 } 275 298 } 276 299 /*}}}*/ 277 300 /*FUNCTION GetSize{{{*/ 278 301 void GetSize(int* pM,int* pN){ 279 _error_("not supported yet!"); 302 *pM=M; 303 *pN=N; 280 304 } 281 305 /*}}}*/ 282 306 /*FUNCTION GetLocalSize{{{*/ 283 307 void GetLocalSize(int* pM,int* pN){ 284 _error_("not supported yet!"); 308 *pM=m; 309 *pN=N; 285 310 } 286 311 /*}}}*/ 287 312 /*FUNCTION MatMult{{{*/ 288 313 void MatMult(IssmAbsVec<doubletype>* Xin,IssmAbsVec<doubletype>* AXin){ 289 _error_("not supported yet!"); 314 315 316 int i,j; 317 doubletype *X_serial = NULL; 318 319 320 /*A check on the types: */ 321 if(IssmVecTypeFromToolkitOptions()!=MpiEnum)_error_("MatMult operation only possible with 'mpi' vectors"); 322 323 /*Now that we are sure, cast vectors: */ 324 IssmMpiVec<doubletype>* X=(IssmMpiVec<doubletype>*)Xin; 325 IssmMpiVec<doubletype>* AX=(IssmMpiVec<doubletype>*)AXin; 326 327 /*Serialize input Xin: */ 328 X_serial=X->ToMPISerial(); 329 330 /*Every cpu has a serial version of the input vector. Use it to do the Matrix-Vector multiply 331 *locally and plug it into AXin: */ 332 for(i=0;i<this->m;i++){ 333 for(j=0;j<this->N;j++){ 334 AX->vector[i]+=this->matrix[i*N+j]*X_serial[j]; 335 } 336 } 337 338 /*Free ressources: */ 339 xDelete<doubletype>(X_serial); 290 340 } 291 341 /*}}}*/ 292 342 /*FUNCTION Duplicate{{{*/ 293 343 IssmMpiDenseMat<doubletype>* Duplicate(void){ 294 _error_("not supported yet!"); 344 345 IssmMpiDenseMat<doubletype>* dup=new IssmMpiDenseMat<doubletype>(this->matrix,this->M,this->N,0); 346 return dup; 347 295 348 } 296 349 /*}}}*/ … … 314 367 /*FUNCTION Convert{{{*/ 315 368 void Convert(MatrixType type){ 316 /*do nothing: */369 _error_("not supported yet!"); 317 370 } 318 371 /*}}}*/ -
issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h
r14750 r14792 22 22 #include "../../shared/Alloc/alloc.h" 23 23 #include "../../include/macros.h" 24 #include "../../io/io.h" 24 25 #ifdef _HAVE_MPI_ 25 26 #include "../mpi/mpiincludes.h" … … 303 304 /*FUNCTION AXPY{{{*/ 304 305 void AXPY(IssmAbsVec<doubletype>* Xin, doubletype a){ 305 printf("AXPY not implemented yet!"); 306 exit(1); 306 307 int i; 308 309 /*Assume X is of the correct type, and downcast: */ 310 IssmMpiVec* X=NULL; 311 312 X=(IssmMpiVec<doubletype>*)Xin; 313 314 /*y=a*x+y where this->vector is y*/ 315 for(i=0;i<this->m;i++)this->vector[i]=a*X->vector[i]+this->vector[i]; 316 317 307 318 } 308 319 /*}}}*/ 309 320 /*FUNCTION AYPX{{{*/ 310 321 void AYPX(IssmAbsVec<doubletype>* Xin, doubletype a){ 311 printf("AYPX not implemented yet!"); 312 exit(1); 322 int i; 323 324 /*Assume X is of the correct type, and downcast: */ 325 IssmMpiVec* X=NULL; 326 327 X=(IssmMpiVec<doubletype>*)Xin; 328 329 /*y=x+a*y where this->vector is y*/ 330 for(i=0;i<this->m;i++)this->vector[i]=X->vector[i]+a*this->vector[i]; 331 313 332 } 314 333 /*}}}*/ 315 334 /*FUNCTION ToMPISerial{{{*/ 316 335 doubletype* ToMPISerial(void){ 317 318 printf("IssmMpiVec ToMPISerial not implemented yet!"); 319 exit(1); 336 337 /*communicator info: */ 338 MPI_Comm comm; 339 int num_procs; 340 341 /*MPI_Allgatherv info: */ 342 int lower_row,upper_row; 343 int* recvcounts=NULL; 344 int* displs=NULL; 345 346 /*output: */ 347 doubletype* buffer=NULL; 348 349 /*initialize comm info: */ 350 comm=IssmComm::GetComm(); 351 num_procs=IssmComm::GetSize(); 352 353 /*Allocate: */ 354 buffer=xNew<doubletype>(M); 355 recvcounts=xNew<int>(num_procs); 356 displs=xNew<int>(num_procs); 357 358 /*recvcounts:*/ 359 MPI_Allgather(&this->m,1,MPI_INT,recvcounts,1,MPI_INT,comm); 360 361 /*get lower_row: */ 362 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,this->m,comm); 363 364 /*displs: */ 365 MPI_Allgather(&lower_row,1,MPI_INT,displs,1,MPI_INT,comm); 366 367 /*All gather:*/ 368 MPI_Allgatherv(this->vector, this->m, MPI_DOUBLE, buffer, recvcounts, displs, MPI_DOUBLE,comm); 369 370 /*free ressources: */ 371 xDelete<int>(recvcounts); 372 xDelete<int>(displs); 373 374 /*return: */ 375 return buffer; 320 376 321 377 } … … 338 394 /*FUNCTION Norm{{{*/ 339 395 doubletype Norm(NormMode mode){ 340 341 printf("IssmMpiVec Norm not implemented yet!"); 342 exit(1); 396 397 doubletype local_norm; 398 doubletype norm; 399 int i; 400 401 switch(mode){ 402 case NORM_INF: 403 //local_norm=0; for(i=0;i<this->m;i++)local_norm=max(local_norm,fabs(this->vector[i])); 404 local_norm=0; for(i=0;i<this->m;i++)local_norm=max(local_norm,this->vector[i]); 405 MPI_Reduce(&local_norm, &norm, 1, MPI_DOUBLE, MPI_MAX, 0, IssmComm::GetComm()); 406 return norm; 407 break; 408 case NORM_TWO: 409 local_norm=0; 410 for(i=0;i<this->m;i++)local_norm+=pow(this->vector[i],2); 411 MPI_Reduce(&local_norm, &norm, 1, MPI_DOUBLE, MPI_SUM, 0, IssmComm::GetComm()); 412 return sqrt(norm); 413 break; 414 default: 415 _error_("unknown norm !"); 416 break; 417 } 343 418 } 344 419 /*}}}*/ … … 392 467 /*}}}*/ 393 468 }; 394 #endif //#ifndef _ISSM_MPI_VEC_H_ 469 #endif //#ifndef _ISSM_MPI_VEC_H_ -
issm/trunk-jpl/src/c/toolkits/issm/issmtoolkit.h
r14685 r14792 18 18 #include "./IssmSeqVec.h" 19 19 #include "./IssmVec.h" 20 #include "./IssmSolver.h" 20 21 21 22 #ifdef _HAVE_MPI_ -
issm/trunk-jpl/src/c/toolkits/petsc/objects/petscobjects.h
r12850 r14792 8 8 #include "./PetscMat.h" 9 9 #include "./PetscVec.h" 10 #include "./PetscSolver.h" 10 11 11 12 #endif
Note:
See TracChangeset
for help on using the changeset viewer.