Changeset 16450


Ignore:
Timestamp:
10/17/13 21:56:32 (11 years ago)
Author:
Eric.Larour
Message:

CHG: huge speed-up in the SetValues routine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/toolkits/issm/SparseRow.h

    r16438 r16450  
    7272                        if(!numvalues)return;
    7373
    74                         /*Figure out number of non-zero values ncols: */
    75                         for(i=0;i<numvalues;i++)buffer[i]=0;
    76                        
    77                         ncols=0;
     74                        /*Go through cols and resolve duplicates: */
    7875                        for(i=0;i<numvalues;i++){
    79                                 if(!buffer[cols[i]])ncols++;
    80                                 if(mods[i]==ADD_VAL){
    81                                         if(buffer[cols[i]]!=2)buffer[cols[i]]=1;
     76                                for(j=i+1;j<numvalues;j++){
     77                                        if (cols[j]==cols[i]){
     78                                                if (mods[j]==ADD_VAL){
     79                                                        vals[i]+=vals[j];
     80                                                }
     81                                                else vals[i]=vals[j];
     82                                                cols[j]=-1;
     83                                        }
     84                                        /*Ensure that this value will not be used anymore: */
    8285                                }
    83                                 else buffer[cols[i]]=2;
    8486                        }
    8587
    86                         /*Allocate:*/
     88                        /*Now go through cols once more, and retrieve only what we need: */
     89                        ncols=0;
     90                        for(i=0;i<numvalues;i++)if(cols[i]>=0)ncols++;
     91
     92                        /*Allocate and fill: */
    8793                        indices=xNew<int>(ncols); _assert_(indices);
    8894                        values=xNewZeroInit<doubletype>(ncols);  _assert_(values);
    89 
    90                         /*Go through buffer and add values: */
     95                       
    9196                        count=0;
    92                         for(i=0;i<M;i++){
    93                                 if(buffer[i]==1){
    94                                         indices[count]=i;
    95                                        
    96                                         /*ADD_VALUE: chase all values with row index i*/
    97                                         for(j=0;j<numvalues;j++){
    98                                                 if (cols[j]==i)values[count]+=vals[j];
    99                                         }
    100                                         count++;
    101                                 }
    102                                 else if(buffer[i]==2){
    103                                         indices[count]=i;
    104                                        
    105                                         /*INS_VALUE: chase first value with row index i*/
    106                                         for(j=0;j<numvalues;j++){
    107                                                 if (cols[j]==i){
    108                                                         values[count]=vals[j];
    109                                                         break;
    110                                                 }
    111                                         }
     97                        for(i=0;i<numvalues;i++){
     98                                if(cols[i]>=0){
     99                                        indices[count]=cols[i];
     100                                        values[count]=vals[i];
    112101                                        count++;
    113102                                }
    114103                        }
     104               
    115105                        if(count!=ncols)_error_("counter problem during set values operations");
    116106                } /*}}}*/
Note: See TracChangeset for help on using the changeset viewer.