Changeset 18523


Ignore:
Timestamp:
09/16/14 09:14:24 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: significant gain in performance by using static allocation for GetInputValue and GetInputDerivativeValue

Location:
issm/trunk-jpl/src/c/classes/Elements
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Elements/PentaRef.cpp

    r18521 r18523  
    1 /*!\file PentaRef.c
     1/*!\file PentaRef.cpp
    22 * \brief: implementation of the PentaRef object
    33 */
     
    2626#define NUMNODESP2b   19
    2727#define NUMNODESP2xP4 30
     28#define NUMNODESMAX   30
    2829
    2930/*Object constructors and destructor*/
     
    886887/*}}}*/
    887888void PentaRef::GetInputValue(IssmDouble* pvalue,IssmDouble* plist,Gauss* gauss,int finiteelement){/*{{{*/
    888 
    889         /*Output*/
    890         IssmDouble value =0.;
     889        /* WARNING: For a significant gain in performance, it is better to use
     890         * static memory allocation instead of dynamic.*/
     891
     892        /*Allocate basis functions*/
     893        IssmDouble  basis[NUMNODESMAX];
    891894
    892895        /*Fetch number of nodes for this finite element*/
    893896        int numnodes = this->NumberofNodes(finiteelement);
    894 
    895         /*Get nodal functions*/
    896         IssmDouble* basis=xNew<IssmDouble>(numnodes);
    897         GetNodalFunctions(basis, gauss,finiteelement);
     897        _assert_(numnodes<=NUMNODESMAX);
     898
     899        /*Get basis functions at this point*/
     900        GetNodalFunctions(&basis[0],gauss,finiteelement);
    898901
    899902        /*Calculate parameter for this Gauss point*/
     903        IssmDouble value =0.;
    900904        for(int i=0;i<numnodes;i++) value += basis[i]*plist[i];
    901905
    902906        /*Assign output pointer*/
    903         xDelete<IssmDouble>(basis);
    904907        *pvalue = value;
    905 
    906908}
    907909/*}}}*/
     
    915917         *
    916918         *   p is a vector of size 3x1 already allocated.
     919         *
     920         * WARNING: For a significant gain in performance, it is better to use
     921         * static memory allocation instead of dynamic.
    917922         */
    918923
    919         /*Output*/
     924        /*Allocate derivatives of basis functions*/
     925        IssmDouble  dbasis[3*NUMNODESMAX];
     926
     927        /*Fetch number of nodes for this finite element*/
     928        int numnodes = this->NumberofNodes(finiteelement);
     929        _assert_(numnodes<=NUMNODESMAX);
     930
     931        /*Get basis functions derivatives at this point*/
     932        GetNodalFunctionsDerivatives(&dbasis[0],xyz_list,gauss,finiteelement);
     933
     934        /*Calculate parameter for this Gauss point*/
    920935        IssmDouble dpx=0.;
    921936        IssmDouble dpy=0.;
    922937        IssmDouble dpz=0.;
    923 
    924         /*Fetch number of nodes for this finite element*/
    925         int numnodes = this->NumberofNodes(finiteelement);
    926 
    927         /*Get nodal functions derivatives*/
    928         IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
    929         GetNodalFunctionsDerivatives(dbasis,xyz_list,gauss,finiteelement);
    930 
    931         /*Calculate parameter for this Gauss point*/
    932938        for(int i=0;i<numnodes;i++) dpx += dbasis[0*numnodes+i]*plist[i];
    933939        for(int i=0;i<numnodes;i++) dpy += dbasis[1*numnodes+i]*plist[i];
     
    935941
    936942        /*Assign values*/
    937         xDelete<IssmDouble>(dbasis);
    938943        p[0]=dpx;
    939944        p[1]=dpy;
    940945        p[2]=dpz;
    941 
    942946}
    943947/*}}}*/
  • issm/trunk-jpl/src/c/classes/Elements/SegRef.cpp

    r18078 r18523  
    1818#define NUMNODESP0  1
    1919#define NUMNODESP1  2
     20#define NUMNODESMAX 2
    2021
    2122/*Object constructors and destructor*/
     
    115116         *
    116117         * p is a vector already allocated.
     118         *
     119         * WARNING: For a significant gain in performance, it is better to use
     120         * static memory allocation instead of dynamic.
    117121         */
    118122
    119         /*Output*/
    120         IssmDouble dpx = 0.;
     123        /*Allocate derivatives of basis functions*/
     124        IssmDouble  dbasis[1*NUMNODESMAX];
    121125
    122126        /*Fetch number of nodes for this finite element*/
    123127        int numnodes = this->NumberofNodes(finiteelement);
    124 
    125         /*Get nodal functions derivatives*/
    126         IssmDouble* dbasis=xNew<IssmDouble>(1*numnodes);
    127         GetNodalFunctionsDerivatives(dbasis,xyz_list,gauss,finiteelement);
     128        _assert_(numnodes<=NUMNODESMAX);
     129
     130        /*Get basis functions derivatives at this point*/
     131        GetNodalFunctionsDerivatives(&dbasis[0],xyz_list,gauss,finiteelement);
    128132
    129133        /*Calculate parameter for this Gauss point*/
    130         for(int i=0;i<numnodes;i++) dpx += dbasis[i]*plist[i];
     134        IssmDouble dpx=0.;
     135        for(int i=0;i<numnodes;i++) dpx += dbasis[0*numnodes+i]*plist[i];
    131136
    132137        /*Assign values*/
    133         xDelete<IssmDouble>(dbasis);
    134         *p=dpx;
    135 
     138        p[0]=dpx;
    136139}
    137140/*}}}*/
    138141void SegRef::GetInputValue(IssmDouble* p, IssmDouble* plist, GaussSeg* gauss,int finiteelement){/*{{{*/
    139 
    140         /*Output*/
    141         IssmDouble value =0.;
     142        /* WARNING: For a significant gain in performance, it is better to use
     143         * static memory allocation instead of dynamic.*/
     144
     145        /*Allocate basis functions*/
     146        IssmDouble  basis[NUMNODESMAX];
    142147
    143148        /*Fetch number of nodes for this finite element*/
    144149        int numnodes = this->NumberofNodes(finiteelement);
    145 
    146         /*Get nodal functions*/
    147         IssmDouble* basis=xNew<IssmDouble>(numnodes);
    148         GetNodalFunctions(basis, gauss,finiteelement);
     150        _assert_(numnodes<=NUMNODESMAX);
     151
     152        /*Get basis functions at this point*/
     153        GetNodalFunctions(&basis[0],gauss,finiteelement);
    149154
    150155        /*Calculate parameter for this Gauss point*/
     156        IssmDouble value =0.;
    151157        for(int i=0;i<numnodes;i++) value += basis[i]*plist[i];
    152158
    153159        /*Assign output pointer*/
    154         xDelete<IssmDouble>(basis);
    155160        *p = value;
    156161}
  • issm/trunk-jpl/src/c/classes/Elements/TetraRef.cpp

    r18521 r18523  
    2020#define NUMNODESP1b 5
    2121#define NUMNODESP2  10
     22#define NUMNODESMAX 10
    2223
    2324/*Object constructors and destructor*/
     
    217218         *
    218219         *   p is a vector of size 3x1 already allocated.
     220         *
     221         * WARNING: For a significant gain in performance, it is better to use
     222         * static memory allocation instead of dynamic.
    219223         */
    220224
    221         /*Output*/
     225        /*Allocate derivatives of basis functions*/
     226        IssmDouble  dbasis[3*NUMNODESMAX];
     227
     228        /*Fetch number of nodes for this finite element*/
     229        int numnodes = this->NumberofNodes(finiteelement);
     230        _assert_(numnodes<=NUMNODESMAX);
     231
     232        /*Get basis functions derivatives at this point*/
     233        GetNodalFunctionsDerivatives(&dbasis[0],xyz_list,gauss,finiteelement);
     234
     235        /*Calculate parameter for this Gauss point*/
    222236        IssmDouble dpx=0.;
    223237        IssmDouble dpy=0.;
    224238        IssmDouble dpz=0.;
    225 
    226         /*Fetch number of nodes for this finite element*/
    227         int numnodes = this->NumberofNodes(finiteelement);
    228 
    229         /*Get nodal functions derivatives*/
    230         IssmDouble* dbasis=xNew<IssmDouble>(3*numnodes);
    231         GetNodalFunctionsDerivatives(dbasis,xyz_list,gauss,finiteelement);
    232 
    233         /*Calculate parameter for this Gauss point*/
    234239        for(int i=0;i<numnodes;i++) dpx += dbasis[0*numnodes+i]*plist[i];
    235240        for(int i=0;i<numnodes;i++) dpy += dbasis[1*numnodes+i]*plist[i];
     
    237242
    238243        /*Assign values*/
    239         xDelete<IssmDouble>(dbasis);
    240244        p[0]=dpx;
    241245        p[1]=dpy;
     
    244248/*}}}*/
    245249void TetraRef::GetInputValue(IssmDouble* p, IssmDouble* plist, Gauss* gauss,int finiteelement){/*{{{*/
    246 
    247         /*Output*/
    248         IssmDouble value =0.;
     250        /* WARNING: For a significant gain in performance, it is better to use
     251         * static memory allocation instead of dynamic.*/
     252
     253        /*Allocate basis functions*/
     254        IssmDouble  basis[NUMNODESMAX];
    249255
    250256        /*Fetch number of nodes for this finite element*/
    251257        int numnodes = this->NumberofNodes(finiteelement);
    252 
    253         /*Get nodal functions*/
    254         IssmDouble* basis=xNew<IssmDouble>(numnodes);
    255         GetNodalFunctions(basis, gauss,finiteelement);
     258        _assert_(numnodes<=NUMNODESMAX);
     259
     260        /*Get basis functions at this point*/
     261        GetNodalFunctions(&basis[0],gauss,finiteelement);
    256262
    257263        /*Calculate parameter for this Gauss point*/
     264        IssmDouble value =0.;
    258265        for(int i=0;i<numnodes;i++) value += basis[i]*plist[i];
    259266
    260267        /*Assign output pointer*/
    261         xDelete<IssmDouble>(basis);
    262268        *p = value;
    263269}
  • issm/trunk-jpl/src/c/classes/Elements/TriaRef.cpp

    r18521 r18523  
    2121#define NUMNODESP2  6
    2222#define NUMNODESP2b 7
     23#define NUMNODESMAX 7
    2324
    2425/*Object constructors and destructor*/
     
    354355/*}}}*/
    355356void TriaRef::GetInputDerivativeValue(IssmDouble* p, IssmDouble* plist,IssmDouble* xyz_list, Gauss* gauss,int finiteelement){/*{{{*/
    356 
    357357        /*From node values of parameter p (plist[0],plist[1],plist[2]), return parameter derivative value at gaussian
    358358         * point specified by gauss_basis:
     
    361361         *
    362362         * p is a vector already allocated.
     363         *
     364         * WARNING: For a significant gain in performance, it is better to use
     365         * static memory allocation instead of dynamic.
    363366         */
    364367
    365         /*Output*/
     368        /*Allocate derivatives of basis functions*/
     369        IssmDouble  dbasis[2*NUMNODESMAX];
     370
     371        /*Fetch number of nodes for this finite element*/
     372        int numnodes = this->NumberofNodes(finiteelement);
     373        _assert_(numnodes<=NUMNODESMAX);
     374
     375        /*Get basis functions derivatives at this point*/
     376        GetNodalFunctionsDerivatives(&dbasis[0],xyz_list,gauss,finiteelement);
     377
     378        /*Calculate parameter for this Gauss point*/
    366379        IssmDouble dpx=0.;
    367380        IssmDouble dpy=0.;
     381        for(int i=0;i<numnodes;i++) dpx += dbasis[0*numnodes+i]*plist[i];
     382        for(int i=0;i<numnodes;i++) dpy += dbasis[1*numnodes+i]*plist[i];
     383
     384        /*Assign values*/
     385        p[0]=dpx;
     386        p[1]=dpy;
     387
     388}
     389/*}}}*/
     390void TriaRef::GetInputValue(IssmDouble* p, IssmDouble* plist, Gauss* gauss,int finiteelement){/*{{{*/
     391        /* WARNING: For a significant gain in performance, it is better to use
     392         * static memory allocation instead of dynamic.*/
     393
     394        /*Allocate basis functions*/
     395        IssmDouble  basis[NUMNODESMAX];
    368396
    369397        /*Fetch number of nodes for this finite element*/
    370398        int numnodes = this->NumberofNodes(finiteelement);
    371 
    372         /*Get nodal functions derivatives*/
    373         IssmDouble* dbasis=xNew<IssmDouble>(2*numnodes);
    374         GetNodalFunctionsDerivatives(dbasis,xyz_list,gauss,finiteelement);
     399        _assert_(numnodes<=NUMNODESMAX);
     400
     401        /*Get basis functions at this point*/
     402        GetNodalFunctions(&basis[0],gauss,finiteelement);
    375403
    376404        /*Calculate parameter for this Gauss point*/
    377         for(int i=0;i<numnodes;i++) dpx += dbasis[0*numnodes+i]*plist[i];
    378         for(int i=0;i<numnodes;i++) dpy += dbasis[1*numnodes+i]*plist[i];
    379 
    380         /*Assign values*/
    381         xDelete<IssmDouble>(dbasis);
    382         p[0]=dpx;
    383         p[1]=dpy;
    384 
    385 }
    386 /*}}}*/
    387 void TriaRef::GetInputValue(IssmDouble* p, IssmDouble* plist, Gauss* gauss,int finiteelement){/*{{{*/
    388 
    389         /*Output*/
    390405        IssmDouble value =0.;
    391 
    392         /*Fetch number of nodes for this finite element*/
    393         int numnodes = this->NumberofNodes(finiteelement);
    394 
    395         /*Get nodal functions*/
    396         IssmDouble* basis=xNew<IssmDouble>(numnodes);
    397         GetNodalFunctions(basis, gauss,finiteelement);
    398 
    399         /*Calculate parameter for this Gauss point*/
    400406        for(int i=0;i<numnodes;i++) value += basis[i]*plist[i];
    401407
    402408        /*Assign output pointer*/
    403         xDelete<IssmDouble>(basis);
    404409        *p = value;
    405410}
Note: See TracChangeset for help on using the changeset viewer.