Changeset 21615


Ignore:
Timestamp:
03/16/17 13:02:24 (8 years ago)
Author:
glperez
Message:

CHG: limiting use of ensurecontiguous calls in the context of AD builds.

xNew has a second parameter only in AD builds that will determine whether ensurecontiguous is called or not. A default value is used so that only when ensurecontiguous is needed do we have to provide a second argument.

Location:
issm/trunk-jpl
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/m4/issm_options.m4

    r21525 r21615  
    770770                ADOLCLIB="-L$ADOLC_ROOT/lib -ladolc"
    771771                AC_DEFINE([_HAVE_ADOLC_],[1],[with adolc in ISSM src])
     772                AC_DEFINE([_HAVE_AD_],[1],[with AD in ISSM src])
    772773                AC_SUBST([ADOLCINCL])
    773774                AC_SUBST([ADOLCLIB])
  • issm/trunk-jpl/src/c/classes/IoModel.cpp

    r21542 r21615  
    17191719        if(M*N){
    17201720                buffer=xNew<IssmPDouble>(M*N);
     1721// AD performance is sensitive to calls to ensurecontiguous.
     1722// Providing "t" will cause ensurecontiguous to be called.
     1723#ifdef _HAVE_AD_
     1724                matrix=xNew<IssmDouble>(M*N,"t");
     1725#else
    17211726                matrix=xNew<IssmDouble>(M*N);
     1727#endif
    17221728
    17231729                /*Read matrix on node 0, then broadcast: */
  • issm/trunk-jpl/src/c/shared/MemOps/MemOps.cpp

    r18125 r21615  
    1515
    1616#if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)
    17 template <> adouble*  xNew(unsigned int size) {
    18         ensureContiguousLocations(size);
     17template <> adouble*  xNew(unsigned int size, const char* const contig) {
     18        if (*contig == 't')
     19                ensureContiguousLocations(size);
     20
    1921        adouble* aT_p=new adouble[size];
    2022        assert(aT_p);
  • issm/trunk-jpl/src/c/shared/MemOps/MemOps.h

    r18125 r21615  
    1616#endif
    1717
     18static char const DEFCONTIG = 'f';
     19
     20// AD (mostly ADOLC) is sensitive to calls to ensurecontiguous. These changes limit its use.
     21#ifdef _HAVE_AD_
     22template <class T> T* xNew(unsigned int size, const char* const contig = &DEFCONTIG) { /*{{{*/
     23#else
    1824template <class T> T* xNew(unsigned int size) { /*{{{*/
     25#endif
    1926#ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES
    2027  T* aT_p=new T[size];
     
    4956#endif
    5057}/*}}}*/
     58// AD (mostly ADOLC) is sensitive to calls to ensurecontiguous. These changes limit its use.
     59#ifdef _HAVE_AD_
     60template <class T> T* xNewZeroInit(unsigned int size,const char* const contig = &DEFCONTIG) {/*{{{*/
     61#else
    5162template <class T> T* xNewZeroInit(unsigned int size) {/*{{{*/
     63#endif
    5264#ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES
     65#ifdef _HAVE_AD_
     66  T* aT_p=xNew<T>(size,contig);
     67#else
    5368  T* aT_p=xNew<T>(size);
     69#endif
    5470  for (unsigned int i=0; i<size;++i)
    5571    aT_p[i]=(T)0;
     
    144160#if defined(_HAVE_ADOLC_) && !defined(_WRAPPERS_)
    145161#include "../Numerics/types.h"
    146 template <> adouble*  xNew(unsigned int size);
     162template <> adouble*  xNew(unsigned int size, const char* const contig);
    147163#endif
    148164
  • issm/trunk-jpl/src/c/toolkits/gsl/DenseGslSolve.cpp

    r19490 r21615  
    216216        if(Kff_M!=Kff_N)_error_("Stiffness matrix should be square!");
    217217
    218         ensureContiguousLocations(Kff_N);
     218// AD performance is sensitive to calls to ensurecontiguous.
     219// Providing "t" will cause ensurecontiguous to be called.
     220#ifdef _HAVE_AD_
     221        IssmDouble *x  = xNew<IssmDouble>(Kff_N,"t");
     222#else
    219223        IssmDouble *x  = xNew<IssmDouble>(Kff_N);
     224#endif
    220225
    221226        SolverxSeq(x,Kff,pf,Kff_N,parameters);
     
    227232void SolverxSeq(IssmDouble *X,IssmDouble *A,IssmDouble *B,int n, Parameters* parameters){/*{{{*/
    228233        // pack inputs to conform to the EDF-prescribed interface
    229         // ensure a contiguous block of locations:
    230         ensureContiguousLocations(n*(n+1));
    231         IssmDouble*  adoubleEDFin=xNew<IssmDouble>(n*(n+1));  // packed inputs, i.e. matrix and right hand side
     234// AD performance is sensitive to calls to ensurecontiguous.
     235// Providing "t" will cause ensurecontiguous to be called.
     236#ifdef _HAVE_AD_
     237        IssmDouble*  adoubleEDFin=xNew<IssmDouble>(n*(n+1),"t");
     238#else
     239        IssmDouble*  adoubleEDFin=xNew<IssmDouble>(n*(n+1));
     240#endif 
     241        // packed inputs, i.e. matrix and right hand side
    232242        for(int i=0; i<n*n;i++)adoubleEDFin[i]    =A[i];      // pack matrix
    233243        for(int i=0; i<n;  i++)adoubleEDFin[i+n*n]=B[i];      // pack the right hand side
  • issm/trunk-jpl/src/c/toolkits/issm/IssmMpiSparseMat.h

    r18063 r21615  
    232232                                        row_indices_fromcpu[i]=xNew<int>(size);
    233233                                        col_indices_fromcpu[i]=xNew<int>(size);
     234// AD performance is sensitive to calls to ensurecontiguous.
     235// Providing "t" will cause ensurecontiguous to be called.
     236#ifdef _HAVE_AD_
     237                                        values_fromcpu[i]=xNew<doubletype>(size,"t");
     238#else
    234239                                        values_fromcpu[i]=xNew<doubletype>(size);
     240#endif
     241
    235242                                        modes_fromcpu[i]=xNew<int>(size);
    236243                                }
     
    492499                        row_indices_forcpu = xNew<int>(total_size);
    493500                        col_indices_forcpu = xNew<int>(total_size);
     501// AD performance is sensitive to calls to ensurecontiguous.
     502// Providing "t" will cause ensurecontiguous to be called.
     503#ifdef _HAVE_AD_
     504                        values_forcpu = xNew<doubletype>(total_size,"t");
     505#else
    494506                        values_forcpu = xNew<doubletype>(total_size);
     507#endif
     508
    495509                        modes_forcpu = xNew<int>(total_size);
    496510
  • issm/trunk-jpl/src/c/toolkits/issm/IssmMpiVec.h

    r20040 r21615  
    6767
    6868                        if(this->M){
     69// AD performance is sensitive to calls to ensurecontiguous.
     70// Providing "t" will cause ensurecontiguous to be called.
     71#ifdef _HAVE_AD_
     72                                this->vector=xNew<doubletype>(this->m,"t");
     73#else
    6974                                this->vector=xNew<doubletype>(this->m);
     75#endif
     76
    7077                                xMemCpy<doubletype>(this->vector,buffer,this->m);
    7178                        }
     
    8087
    8188                        if(this->m){
     89// AD performance is sensitive to calls to ensurecontiguous.
     90// Providing "t" will cause ensurecontiguous to be called.
     91#ifdef _HAVE_AD_
     92                                this->vector=xNew<doubletype>(this->m,"t");
     93#else
    8294                                this->vector=xNew<doubletype>(this->m);
     95#endif
     96
    8397                                xMemCpy<doubletype>(this->vector,buffer,this->m);
    8498                        }
     
    102116
    103117                        /*Allocate: */
     118// AD performance is sensitive to calls to ensurecontiguous.
     119// Providing "t" will cause ensurecontiguous to be called.
     120#ifdef _HAVE_AD_
     121                        if (m)this->vector=xNewZeroInit<doubletype>(this->m,"t");
     122#else
    104123                        if (m)this->vector=xNewZeroInit<doubletype>(this->m);
     124#endif
     125
    105126                }
    106127                /*}}}*/
     
    196217                                if(size){
    197218                                        row_indices_fromcpu[i]=xNew<int>(size);
     219// AD performance is sensitive to calls to ensurecontiguous.
     220// Providing "t" will cause ensurecontiguous to be called.
     221#ifdef _HAVE_AD_
     222                                        values_fromcpu[i]=xNew<doubletype>(size,"t");
     223#else
    198224                                        values_fromcpu[i]=xNew<doubletype>(size);
     225#endif
     226
    199227                                        modes_fromcpu[i]=xNew<int>(size);
    200228                                }
     
    375403
    376404                        /*Allocate: */
     405// AD performance is sensitive to calls to ensurecontiguous.
     406// Providing "t" will cause ensurecontiguous to be called.
     407#ifdef _HAVE_AD_
     408                        buffer=xNew<doubletype>(M,"t");
     409#else
    377410                        buffer=xNew<doubletype>(M);
     411#endif
     412
    378413                        recvcounts=xNew<int>(num_procs);
    379414                        displs=xNew<int>(num_procs);
     
    527562                        /*Allocate buffers: */
    528563                        row_indices_forcpu = xNew<int>(total_size);
     564// AD performance is sensitive to calls to ensurecontiguous.
     565// Providing "t" will cause ensurecontiguous to be called.
     566#ifdef _HAVE_AD_
     567                        values_forcpu = xNew<doubletype>(total_size,"t");
     568#else
    529569                        values_forcpu = xNew<doubletype>(total_size);
     570#endif
     571
    530572                        modes_forcpu = xNew<int>(total_size);
    531573
  • issm/trunk-jpl/src/c/toolkits/mumps/MumpsSolve.cpp

    r19491 r21615  
    167167        }
    168168        /*Deal with right hand side. We need to ISSM_MPI_Gather it onto cpu 0: */
     169// AD performance is sensitive to calls to ensurecontiguous.
     170// Providing "t" will cause ensurecontiguous to be called.
     171#ifdef _HAVE_AD_
     172        rhs=xNew<IssmDouble>(pf_M,"t");
     173#else
    169174        rhs=xNew<IssmDouble>(pf_M);
     175#endif
     176
    170177
    171178        recvcounts=xNew<int>(num_procs);
     
    246253        }
    247254        /*Deal with right hand side. We need to ISSM_MPI_Gather it onto cpu 0: */
     255// AD performance is sensitive to calls to ensurecontiguous.
     256// Providing "t" will cause ensurecontiguous to be called.
     257#ifdef _HAVE_AD_
     258        rhs=xNew<IssmDouble>(pf_M,"t");
     259#else
    248260        rhs=xNew<IssmDouble>(pf_M);
     261#endif
     262
    249263
    250264        recvcounts=xNew<int>(num_procs);
     
    314328    packedDimsSparseArr[3+local_nnz+i]=jcn_loc[i];
    315329  }
     330// AD performance is sensitive to calls to ensurecontiguous.
     331// Providing "t" will cause ensurecontiguous to be called.
     332#ifdef _HAVE_AD_
     333  IssmDouble *pack_A_rhs=xNew<IssmDouble>(local_nnz+n,"t");
     334#else
    316335  IssmDouble *pack_A_rhs=xNew<IssmDouble>(local_nnz+n);
     336#endif
     337
    317338  for (int i=0;i<local_nnz;++i) {
    318339    pack_A_rhs[i]=a_loc[i];
     
    321342    pack_A_rhs[local_nnz+i]=rhs[i];
    322343  }
     344// AD performance is sensitive to calls to ensurecontiguous.
     345// Providing "t" will cause ensurecontiguous to be called.
     346#ifdef _HAVE_AD_
     347  IssmDouble *sol=xNew<IssmDouble>(n,"t");
     348#else
    323349  IssmDouble *sol=xNew<IssmDouble>(n);
     350#endif
     351
    324352  call_ext_fct(xDynamicCast<GenericParam<Adolc_edf> * >(parameters->FindParamObject(AdolcParamEnum))->GetParameterValue().myEDF_for_solverx_p,
    325353               packedDimsSparseArrLength, packedDimsSparseArr,
Note: See TracChangeset for help on using the changeset viewer.