Changeset 16137 for issm/trunk/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp
- Timestamp:
- 09/16/13 09:43:55 (12 years ago)
- Location:
- issm/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
- Property svn:ignore
-
old new 1 nightlylog 2 configure.sh 1 3 par 2 4 ad
-
- Property svn:mergeinfo changed
/issm/trunk-jpl merged: 15397-15401,15403-15487,15489-15701,15704-15735,15737-16076,16082-16133
- Property svn:ignore
-
issm/trunk/src
- Property svn:mergeinfo changed
-
issm/trunk/src/c
- Property svn:ignore
-
old new 14 14 probe.results 15 15 stXXXX* 16 16 .deps 17 .dirstamp
-
- Property svn:ignore
-
issm/trunk/src/c/toolkits
-
Property svn:ignore
set to
.deps
.dirstamp
-
Property svn:ignore
set to
-
issm/trunk/src/c/toolkits/mumps
-
Property svn:ignore
set to
.deps
.dirstamp
-
Property svn:ignore
set to
-
issm/trunk/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp
r14950 r16137 13 13 #include "../../shared/MemOps/MemOps.h" 14 14 #include "../../shared/Exceptions/exceptions.h" 15 #include "../../shared/io/Comm/Comm.h" 16 #include "../mpi/patches/mpipatches.h" 15 #include "../../shared/io/Comm/IssmComm.h" 16 #include "../../classes/Params/GenericParam.h" 17 #include "../../classes/Params/Parameters.h" 18 #include "../mpi/issmmpi.h" 19 #include "../adolc/adolcincludes.h" 20 #include "./mumpsincludes.h" 17 21 18 22 /*Mumps header files: */ 19 23 #include "dmumps_c.h" 20 21 #define JOB_INIT -122 #define JOB_SOLVE 623 #define JOB_END -224 24 /*}}}*/ 25 25 26 void MpiDenseMumpsSolve( /*output: */ IssmPDouble* uf, int uf_M, int uf_m, /*matrix input: */ IssmPDouble* Kff, int Kff_M, int Kff_N, int Kff_m, /*right hand side vector: */ IssmPDouble* pf, int pf_M, int pf_m){ /*{{{*/ 26 void MumpsInit(DMUMPS_STRUC_C &theMumpsStruc) { 27 theMumpsStruc.par = 1; 28 theMumpsStruc.sym = 0; 29 theMumpsStruc.comm_fortran = MPI_Comm_c2f(IssmComm::GetComm()); 30 theMumpsStruc.job = -1; 31 dmumps_c(&theMumpsStruc); 32 } 33 34 // must be preceded by a call to MumpsInit 35 void MumpsSettings(DMUMPS_STRUC_C &theMumpsStruc) { 36 /*Control statements:{{{ */ 37 theMumpsStruc.icntl[1-1] = 6; //error verbose 38 theMumpsStruc.icntl[2-1] = 1; //std verbose 39 theMumpsStruc.icntl[4-1] = 4; //verbose everything 40 theMumpsStruc.icntl[5-1] = 0; 41 theMumpsStruc.icntl[18-1] = 3; 42 43 theMumpsStruc.icntl[20-1] = 0; 44 theMumpsStruc.icntl[21-1] = 0; 45 theMumpsStruc.icntl[30-1] = 0; 46 /*}}}*/ 47 } 48 49 // must be preceded by a call to MumpsInit 50 void MumpsAnalyze(DMUMPS_STRUC_C &theMumpsStruc) { 51 theMumpsStruc.job = 1; 52 dmumps_c(&theMumpsStruc); 53 } 54 55 // must be preceded by a call to MumpsAnalyze 56 void MumpsFactorize(DMUMPS_STRUC_C &theMumpsStruc) { 57 theMumpsStruc.job = 2; 58 dmumps_c(&theMumpsStruc); 59 } 60 61 // must be preceded by a call to MumpsFactorize 62 void MumpsBacksubstitute(DMUMPS_STRUC_C &theMumpsStruc) { 63 theMumpsStruc.job = 3; 64 dmumps_c(&theMumpsStruc); 65 } 66 67 // must be preceded at least by a call to MumpsInit 68 void MumpsFinalize(DMUMPS_STRUC_C &theMumpsStruc) { 69 theMumpsStruc.job = -2; 70 dmumps_c(&theMumpsStruc); 71 } 72 73 void MumpsSolve(int n, 74 int nnz, 75 int local_nnz, 76 int* irn_loc, 77 int* jcn_loc, 78 IssmPDouble *a_loc, 79 IssmPDouble *rhs, 80 Parameters* parameters=0 /*unused here*/) { 81 /*Initialize mumps: {{{*/ 82 DMUMPS_STRUC_C theMumpsStruc; 83 MumpsInit(theMumpsStruc); 84 MumpsSettings(theMumpsStruc); 85 /*}}}*/ 86 // now setup the rest of theMumpsStruc 87 theMumpsStruc.n=n; 88 theMumpsStruc.nz=nnz; 89 theMumpsStruc.nz_loc=local_nnz; 90 theMumpsStruc.irn_loc=irn_loc; 91 theMumpsStruc.jcn_loc=jcn_loc; 92 theMumpsStruc.a_loc=a_loc; 93 theMumpsStruc.rhs=rhs; 94 theMumpsStruc.nrhs=1; 95 theMumpsStruc.lrhs=1; 96 /*Solve system: {{{*/ 97 MumpsAnalyze(theMumpsStruc); 98 MumpsFactorize(theMumpsStruc); 99 MumpsBacksubstitute(theMumpsStruc); 100 /*}}}*/ 101 MumpsFinalize(theMumpsStruc); 102 } 103 104 #ifdef _HAVE_ADOLC_ 105 // prototype for active variant 106 void MumpsSolve(int n, 107 int nnz, 108 int local_nnz, 109 int* irn_loc, 110 int* jcn_loc, 111 IssmDouble *a_loc, 112 IssmDouble *rhs, 113 Parameters* parameters); 114 #endif 115 116 void MpiDenseMumpsSolve( /*output: */ IssmDouble* uf, int uf_M, int uf_m, /*matrix input: */ IssmDouble* Kff, int Kff_M, int Kff_N, int Kff_m, /*right hand side vector: */ IssmDouble* pf, int pf_M, int pf_m, Parameters* parameters){ /*{{{*/ 27 117 28 118 /*Variables: {{{*/ 29 119 30 MPI_Comm comm;120 ISSM_MPI_Comm comm; 31 121 int my_rank; 32 122 int num_procs; … … 36 126 int *irn_loc = NULL; 37 127 int *jcn_loc = NULL; 38 Issm PDouble *a_loc = NULL;128 IssmDouble *a_loc = NULL; 39 129 int count; 40 130 int lower_row; 41 131 int upper_row; 42 Issm PDouble* rhs=NULL;132 IssmDouble* rhs=NULL; 43 133 int* recvcounts=NULL; 44 134 int* displs=NULL; … … 54 144 if (uf_m!=Kff_m | uf_m!=pf_m)_error_("solution vector should be locally the same size as stiffness matrix Kff and load vector pf"); 55 145 /*}}}*/ 56 /*Initialize mumps: {{{*/57 DMUMPS_STRUC_C id;58 id.job = JOB_INIT;59 id.par = 1;60 id.sym = 0;61 id.comm_fortran = MPI_Comm_c2f(comm);62 dmumps_c(&id);63 /*}}}*/64 /*Control statements:{{{ */65 id.icntl[1-1] = 6; //error verbose66 id.icntl[2-1] = 1; //std verbose67 id.icntl[4-1] = 4; //verbose everything68 id.icntl[5-1] = 0;69 id.icntl[18-1] = 3;70 71 id.icntl[20-1] = 0;72 id.icntl[21-1] = 0;73 id.icntl[30-1] = 0;74 /*}}}*/75 146 /*Initialize matrix:{{{ */ 76 id.n=Kff_M;77 147 78 148 /*figure out number of non-zero entries: */ … … 84 154 } 85 155 86 MPI_Reduce(&local_nnz,&nnz,1,MPI_INT,MPI_SUM,0,comm); 87 MPI_Bcast(&nnz,1,MPI_INT,0,comm); 88 id.nz=nnz; 89 id.nz_loc=local_nnz; 156 ISSM_MPI_Reduce(&local_nnz,&nnz,1,ISSM_MPI_INT,ISSM_MPI_SUM,0,comm); 157 ISSM_MPI_Bcast(&nnz,1,ISSM_MPI_INT,0,comm); 90 158 91 159 /*Allocate: */ … … 93 161 irn_loc=xNew<int>(local_nnz); 94 162 jcn_loc=xNew<int>(local_nnz); 95 a_loc=xNew<Issm PDouble>(local_nnz);163 a_loc=xNew<IssmDouble>(local_nnz); 96 164 } 97 165 … … 109 177 } 110 178 } 111 id.irn_loc=irn_loc; 112 id.jcn_loc=jcn_loc; 113 id.a_loc=a_loc; 114 115 /*Deal with right hand side. We need to MPI_Gather it onto cpu 0: */ 116 rhs=xNew<IssmPDouble>(pf_M); 179 /*Deal with right hand side. We need to ISSM_MPI_Gather it onto cpu 0: */ 180 rhs=xNew<IssmDouble>(pf_M); 117 181 118 182 recvcounts=xNew<int>(num_procs); … … 120 184 121 185 /*recvcounts:*/ 122 MPI_Allgather(&pf_m,1,MPI_INT,recvcounts,1,MPI_INT,comm);186 ISSM_MPI_Allgather(&pf_m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,comm); 123 187 124 188 /*displs: */ 125 MPI_Allgather(&lower_row,1,MPI_INT,displs,1,MPI_INT,comm);189 ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,comm); 126 190 127 191 /*Gather:*/ 128 MPI_Gatherv(pf, pf_m, MPI_DOUBLE, rhs, recvcounts, displs, MPI_DOUBLE,0,comm); 129 id.rhs=rhs; 130 id.nrhs=1; 131 id.lrhs=1; 132 133 /*}}}*/ 134 /*Solve system: {{{*/ 135 id.job = JOB_SOLVE; 136 dmumps_c (&id); 137 /*}}}*/ 192 ISSM_MPI_Gatherv(pf, pf_m, ISSM_MPI_DOUBLE, rhs, recvcounts, displs, ISSM_MPI_DOUBLE,0,comm); 193 194 MumpsSolve(Kff_M, 195 nnz, 196 local_nnz, 197 irn_loc, 198 jcn_loc, 199 a_loc, 200 rhs, 201 parameters); 202 138 203 /*Now scatter from cpu 0 to all other cpus: {{{*/ 139 MPI_Scatterv( rhs, recvcounts, displs, MPI_DOUBLE, uf, uf_m,MPI_DOUBLE, 0, comm);204 ISSM_MPI_Scatterv( rhs, recvcounts, displs, ISSM_MPI_DOUBLE, uf, uf_m, ISSM_MPI_DOUBLE, 0, comm); 140 205 141 206 /*}}}*/ 142 207 /*Cleanup: {{{*/ 143 id.job = JOB_END;144 dmumps_c (&id);145 146 208 xDelete<int>(irn_loc); 147 209 xDelete<int>(jcn_loc); 148 xDelete<Issm PDouble>(a_loc);149 xDelete<Issm PDouble>(rhs);210 xDelete<IssmDouble>(a_loc); 211 xDelete<IssmDouble>(rhs); 150 212 xDelete<int>(recvcounts); 151 213 xDelete<int>(displs); 152 153 214 /*}}}*/ 154 215 } /*}}}*/ 155 216 156 217 #ifdef _HAVE_ADOLC_ 157 void MpiDenseMumpsSolve( /*output: */ IssmDouble* uf, int uf_M, int uf_m, /*matrix input: */ IssmDouble* Kff, int Kff_M, int Kff_N, int Kff_m, /*right hand side vector: */ IssmDouble* pf, int pf_M, int pf_m){ /*{{{*/ 158 _error_("not supported yet!"); 159 } /*}}}*/ 218 219 int mumpsSolveEDF(int iArrLength, int* iArr, int /* ignored */, IssmPDouble* dp_x, int /* ignored */, IssmPDouble* dp_y) { 220 // unpack parameters 221 int n=iArr[0]; 222 int nnz=iArr[1]; 223 int local_nnz=iArr[2]; 224 int *local_irn=xNew<int>(local_nnz); 225 int *local_jcn=xNew<int>(local_nnz); 226 IssmPDouble *A=xNew<IssmPDouble>(local_nnz); 227 for (int i=0;i<local_nnz;++i) { 228 local_irn[i]=iArr[3+i]; 229 local_jcn[i]=iArr[3+local_nnz+i]; 230 A[i]=dp_x[i]; 231 } 232 IssmPDouble *rhs_sol=xNew<IssmPDouble>(n); 233 for (int i=0;i<n;++i) { 234 rhs_sol[i]=dp_x[local_nnz+i]; 235 } 236 MumpsSolve(n,nnz,local_nnz,local_irn,local_jcn,A,rhs_sol); 237 for (int i=0;i<n;++i) { 238 dp_y[i]=rhs_sol[i]; 239 } 240 xDelete(rhs_sol); 241 xDelete(A); 242 xDelete(local_jcn); 243 xDelete(local_irn); 244 return 0; 245 } 246 247 void MumpsSolve(int n, 248 int nnz, 249 int local_nnz, 250 int* irn_loc, 251 int* jcn_loc, 252 IssmDouble *a_loc, 253 IssmDouble *rhs, 254 Parameters* parameters) { 255 int packedDimsSparseArrLength=1+1+1+local_nnz+local_nnz; 256 int *packedDimsSparseArr=xNew<int>(packedDimsSparseArrLength); 257 packedDimsSparseArr[0]=n; 258 packedDimsSparseArr[1]=nnz; 259 packedDimsSparseArr[2]=local_nnz; 260 for (int i=0;i<local_nnz;++i) { 261 packedDimsSparseArr[3+i]=irn_loc[i]; 262 packedDimsSparseArr[3+local_nnz+i]=jcn_loc[i]; 263 } 264 IssmDouble *pack_A_rhs=xNew<IssmDouble>(local_nnz+n); 265 for (int i=0;i<local_nnz;++i) { 266 pack_A_rhs[i]=a_loc[i]; 267 } 268 for (int i=0;i<n;++i) { 269 pack_A_rhs[local_nnz+i]=rhs[i]; 270 } 271 IssmPDouble *passivePack_A_rhs=xNew<IssmPDouble>(local_nnz+n); 272 IssmPDouble *passiveSol=xNew<IssmPDouble>(n); 273 IssmDouble *sol=xNew<IssmDouble>(n); 274 call_ext_fct(dynamic_cast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p, 275 packedDimsSparseArrLength, packedDimsSparseArr, 276 local_nnz+n, passivePack_A_rhs, pack_A_rhs, 277 n, passiveSol,sol); 278 for (int i=0;i<n;++i) { 279 rhs[i]=sol[i]; 280 } 281 xDelete(sol); 282 xDelete(passiveSol); 283 xDelete(passivePack_A_rhs); 284 xDelete(pack_A_rhs); 285 xDelete(packedDimsSparseArr); 286 } 287 288 int fos_reverse_mumpsSolveEDF(int iArrLength, int* iArr, 289 int m, IssmPDouble *dp_U, 290 int nPlusNz, IssmPDouble *dp_Z, 291 IssmPDouble *dp_x, IssmPDouble *dp_y) { 292 // unpack parameters 293 int n=iArr[0]; 294 int nnz=iArr[1]; 295 int local_nnz=iArr[2]; 296 int *local_irn=xNew<int>(local_nnz); 297 int *local_jcn=xNew<int>(local_nnz); 298 IssmPDouble *a_loc=xNew<IssmPDouble>(local_nnz); 299 for (int i=0;i<local_nnz;++i) { 300 local_irn[i]=iArr[3+i]; 301 local_jcn[i]=iArr[3+local_nnz+i]; 302 a_loc[i]=dp_x[i]; 303 } 304 IssmPDouble *rhs_sol=xNew<IssmPDouble>(n); 305 for (int i=0;i<n;++i) { 306 rhs_sol[i]=dp_U[i]; 307 } 308 DMUMPS_STRUC_C theMumpsStruc; 309 MumpsInit(theMumpsStruc); 310 MumpsSettings(theMumpsStruc); 311 theMumpsStruc.n=n; 312 theMumpsStruc.nz=nnz; 313 theMumpsStruc.nz_loc=local_nnz; 314 theMumpsStruc.irn_loc=local_irn; 315 theMumpsStruc.jcn_loc=local_jcn; 316 theMumpsStruc.a_loc=a_loc; 317 theMumpsStruc.rhs=rhs_sol; 318 theMumpsStruc.nrhs=1; 319 theMumpsStruc.lrhs=1; 320 theMumpsStruc.icntl[9-1] = 0; //solve for the transpose 321 MumpsAnalyze(theMumpsStruc); 322 MumpsFactorize(theMumpsStruc); 323 MumpsBacksubstitute(theMumpsStruc); 324 MumpsFinalize(theMumpsStruc); 325 // update the adjoint of the rhs: 326 for (int i=0;i<n;++i) { 327 dp_Z[local_nnz+i]+=rhs_sol[i]; 328 } 329 // bcast dp_y (the solution of the forward system) 330 ISSM_MPI_Bcast(dp_y,n,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 331 // bcast the adjoint of the right-hand-side, i.e. this solution 332 ISSM_MPI_Bcast(rhs_sol,n,ISSM_MPI_PDOUBLE,0,IssmComm::GetComm()); 333 // update the adjoint of the matrix with the outer product of right-hand-side adjoint and the original solution 334 for (int i=0;i<local_nnz;++i) { 335 dp_Z[i]-=rhs_sol[iArr[3+i]-1]*dp_y[iArr[3+local_nnz+i]-1]; 336 } 337 xDelete(rhs_sol); 338 xDelete(a_loc); 339 xDelete(local_jcn); 340 xDelete(local_irn); 341 return 3; 342 } 343 160 344 #endif
Note:
See TracChangeset
for help on using the changeset viewer.