Changeset 16083


Ignore:
Timestamp:
09/04/13 22:09:10 (12 years ago)
Author:
utke
Message:

CHG compilable with ampi/adolc now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/toolkits/mumps/MpiDenseMumpsSolve.cpp

    r16071 r16083  
    1414#include "../../shared/Exceptions/exceptions.h"
    1515#include "../../shared/io/Comm/IssmComm.h"
     16#include "../../classes/Params/GenericParam.h"
     17#include "../../classes/Params/Parameters.h"
    1618#include "../mpi/issmmpi.h"
     19#include "../adolc/adolcincludes.h"
    1720#include "./mumpsincludes.h"
    1821
     
    7578                IssmPDouble *a_loc,
    7679                IssmPDouble *rhs,
    77                 Parameters* /*unused here*/) {
     80                Parameters* parameters=0 /*unused here*/) {
    7881        /*Initialize mumps: {{{*/
    7982        DMUMPS_STRUC_C theMumpsStruc;
     
    214217#ifdef _HAVE_ADOLC_
    215218
    216 int mumpsSolveEDF(int iArrLength, int* iArr, int nPlusNz /* we can ignore it*/, double* dp_x, int m, double* dp_y) {
     219int mumpsSolveEDF(int iArrLength, int* iArr, int /* ignored */, IssmPDouble* dp_x, int /* ignored */, IssmPDouble* dp_y) {
    217220  // unpack parameters
    218221  int n=iArr[0];
    219   int nz=iArr[1];
    220   int *irn=new int[nz];
    221   int *jcn=new int[nz];
    222   double *A=new double[nz];
    223   for (int i=0;i<nz;++i) {
    224     irn[i]=iArr[2+i];
    225     jcn[i]=iArr[2+nz+i];
     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];
    226230    A[i]=dp_x[i];
    227231  }
    228   double *rhs_sol=new double[n];
     232  IssmPDouble *rhs_sol=xNew<IssmPDouble>(n);
    229233  for (int i=0;i<n;++i) {
    230     rhs_sol[i]=dp_x[nz+i];
    231   }
    232   mumpsSolve(n,nz,irn,jcn,A,rhs_sol);
    233   for (int i=0;i<m;++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) {
    234238    dp_y[i]=rhs_sol[i];
    235239  }
     240  xDelete(rhs_sol);
     241  xDelete(A);
     242  xDelete(local_jcn);
     243  xDelete(local_irn);
    236244  return 0;
    237245}
     
    255263  }
    256264  ensureContiguousLocations(local_nnz+n);
    257   adouble *pack_A_rhs=xNew<IssmDouble>(local_nnz+n);
     265  IssmDouble *pack_A_rhs=xNew<IssmDouble>(local_nnz+n);
    258266  for (int i=0;i<local_nnz;++i) {
    259267    pack_A_rhs[i]=a_loc[i];
     
    262270    pack_A_rhs[local_nnz+i]=rhs[i];
    263271  }
    264   double *passivePack_A_rhs=xNew<IssmPDouble>(local_nnz+n);
    265   double *passiveSol=xNew<IssmPDouble>(n);
     272  IssmPDouble *passivePack_A_rhs=xNew<IssmPDouble>(local_nnz+n);
     273  IssmPDouble *passiveSol=xNew<IssmPDouble>(n);
    266274  ensureContiguousLocations(n);
    267   adouble *sol=xNew<IssmDouble>(n);
    268   call_ext_fct(ourEDF_p,
     275  IssmDouble *sol=xNew<IssmDouble>(n);
     276  call_ext_fct(dynamic_cast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
    269277               packedDimsSparseArrLength, packedDimsSparseArr,
    270278               local_nnz+n, passivePack_A_rhs, pack_A_rhs,
     
    280288}
    281289
    282 int fos_forward_mumpsSolveEDF(int iArrLength, int* iArr, int nPlusNz /* we can ignore it*/,
    283                               double *dp_x, double *dp_X, int m, double *dp_y, double *dp_Y) {
     290int fos_reverse_mumpsSolveEDF(int iArrLength, int* iArr,
     291                              int m, IssmPDouble *dp_U,
     292                              int nPlusNz, IssmPDouble *dp_Z,
     293                              IssmPDouble *dp_x, IssmPDouble *dp_y) {
    284294  // unpack parameters
    285295  int n=iArr[0];
    286   int nz=iArr[1];
    287   int *irn=new int[nz];
    288   int *jcn=new int[nz];
    289   double *A=new double[nz];
    290   for (int i=0;i<nz;++i) {
    291     irn[i]=iArr[2+i];
    292     jcn[i]=iArr[2+nz+i];
    293     A[i]=dp_x[i];
    294   }
    295   double *rhs_sol=new double[n];
    296   for (int i=0;i<n;++i) {
    297     rhs_sol[i]=dp_x[nz+i];
    298   }
    299   DMUMPS_STRUC_C id;
    300   id.par = 1; // one processor=sequential code
    301   id.sym = 0; // asymmetric
    302   id.job = JOB_INIT;
    303   dmumps_c(&id);
    304 
    305   id.icntl[1-1] = 6; //error verbose
    306   id.icntl[2-1] = 0; //std verbose
    307   id.icntl[3-1] = 0; //
    308   id.icntl[4-1] = 0; //
    309   id.icntl[5-1] = 0; // matrix is assembled
    310   id.icntl[18-1] = 0; // centralized
    311   id.icntl[20-1] = 0; // rhs is dense and centralized
    312   id.icntl[21-1] = 0; // solution is centralized
    313   id.n=n;
    314   id.nz=nz;
    315   id.irn=irn;
    316   id.jcn=jcn;
    317   id.a=A;
    318   id.job = JOB_ANALYSIS;
    319   dmumps_c(&id);
    320   id.job = JOB_FACTORIZATION;
    321   dmumps_c (&id);
    322   // solve the orifginal system
    323   id.rhs=rhs_sol;
    324   id.nrhs=1;
    325   id.lrhs=1;
    326   id.job = JOB_BACKSUBST;
    327   dmumps_c (&id);
    328   for (int i=0;i<m;++i) {
    329     dp_y[i]=rhs_sol[i];
    330   }
    331   // solve for the derivative
    332   for (int i=0;i<n;++i) {
    333     rhs_sol[i]=dp_X[nz+i];
    334   }
    335   for (int i=0;i<nz;++i) {
    336     rhs_sol[irn[i]-1]-=dp_X[i]*dp_y[jcn[i]-1];
    337   }
    338   dmumps_c (&id);
    339   for (int i=0;i<m;++i) {
    340     dp_Y[i]=rhs_sol[i];
    341   }
    342   id.job = JOB_END;
    343   dmumps_c (&id);
    344   return 3;
    345 }
    346 
    347 int fos_reverse_mumpsSolveEDF(int iArrLength, int* iArr,
    348                               int m, double *dp_U,
    349                               int nPlusNz, double *dp_Z,
    350                               double *dp_x, double *dp_y) {
    351   // unpack parameters
    352   int n=iArr[0];
    353   int nz=iArr[1];
    354   int *irn=new int[nz];
    355   int *jcn=new int[nz];
    356   double *A=new double[nz];
    357   for (int i=0;i<nz;++i) {
    358     irn[i]=iArr[2+i];
    359     jcn[i]=iArr[2+nz+i];
    360     A[i]=dp_x[i];
    361   }
    362   DMUMPS_STRUC_C id;
    363   id.par = 1; // one processor=sequential code
    364   id.sym = 0; // asymmetric
    365   id.job = JOB_INIT;
    366   dmumps_c(&id);
    367 
    368   id.icntl[1-1] = 6; //error verbose
    369   id.icntl[2-1] = 0; //std verbose
    370   id.icntl[3-1] = 0; //
    371   id.icntl[4-1] = 0; //
    372   id.icntl[5-1] = 0; // matrix is assembled
    373   id.icntl[9-1] = 0; //solve for the transpose
    374   id.icntl[18-1] = 0; // centralized
    375   id.icntl[20-1] = 0; // rhs is dense and centralized
    376   id.icntl[21-1] = 0; // solution is centralized
    377   id.n=n;
    378   id.nz=nz;
    379   id.irn=irn;
    380   id.jcn=jcn;
    381   id.a=A;
    382   id.job = JOB_ANALYSIS;
    383   dmumps_c(&id);
    384   id.job = JOB_FACTORIZATION;
    385   dmumps_c (&id);
    386   double *rhs_sol=new double[n];
     296  int nnz=iArr[1];
     297  int local_nnz=iArr[2];
     298  int *local_irn=xNew<int>(local_nnz);
     299  int *local_jcn=xNew<int>(local_nnz);
     300  IssmPDouble *a_loc=xNew<IssmPDouble>(local_nnz);
     301  for (int i=0;i<local_nnz;++i) {
     302          local_irn[i]=iArr[3+i];
     303          local_jcn[i]=iArr[3+local_nnz+i];
     304    a_loc[i]=dp_x[i];
     305  }
     306  IssmPDouble *rhs_sol=xNew<IssmPDouble>(n);
    387307  for (int i=0;i<n;++i) {
    388308    rhs_sol[i]=dp_U[i];
    389309  }
    390   id.rhs=rhs_sol;
    391   id.nrhs=1;
    392   id.lrhs=1;
    393   id.job = JOB_BACKSUBST;
    394   dmumps_c (&id);
    395   // update the adhoint of the rhs:
     310  DMUMPS_STRUC_C theMumpsStruc;
     311  MumpsInit(theMumpsStruc);
     312  MumpsSettings(theMumpsStruc);
     313  theMumpsStruc.n=n;
     314  theMumpsStruc.nz=nnz;
     315  theMumpsStruc.nz_loc=local_nnz;
     316  theMumpsStruc.irn_loc=local_irn;
     317  theMumpsStruc.jcn_loc=local_jcn;
     318  theMumpsStruc.a_loc=a_loc;
     319  theMumpsStruc.rhs=rhs_sol;
     320  theMumpsStruc.nrhs=1;
     321  theMumpsStruc.lrhs=1;
     322  theMumpsStruc.icntl[9-1] = 0; //solve for the transpose
     323  MumpsAnalyze(theMumpsStruc);
     324  MumpsFactorize(theMumpsStruc);
     325  MumpsBacksubstitute(theMumpsStruc);
     326  MumpsFinalize(theMumpsStruc);
     327  // update the adjoint of the rhs:
    396328  for (int i=0;i<m;++i) {
    397     dp_Z[nz+i]+=rhs_sol[i];
     329    dp_Z[local_nnz+i]+=rhs_sol[i];
    398330  }
    399331  // update the adjoint of the matrix:
    400   for (int i=0;i<nz;++i) {
    401     dp_Z[i]+=-dp_U[irn[i]-1]*dp_y[jcn[i]-1];
    402   }
     332  for (int i=0;i<local_nnz;++i) {
     333    dp_Z[i]+=-dp_U[local_irn[i]-1]*dp_y[local_jcn[i]-1];
     334  }
     335  xDelete(rhs_sol);
     336  xDelete(a_loc);
     337  xDelete(local_jcn);
     338  xDelete(local_irn);
    403339  return 3;
    404340}
    405341
    406 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){ /*{{{*/
    407         _error_("not supported yet!");
    408 } /*}}}*/
    409 
    410342#endif
Note: See TracChangeset for help on using the changeset viewer.