Changeset 1124


Ignore:
Timestamp:
05/05/17 08:58:37 (4 years ago)
Author:
rlacroix
Message:

Temporal filters: Avoid intermediate copies whenever possible for once and instant operations.

Location:
XIOS/trunk/src/filter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/temporal_filter.cpp

    r1123 r1124  
    1212    : CFilter(gc, 1, this) 
    1313    , functor(createFunctor(opId, ignoreMissingValue, missingValue, tmpData)) 
     14    , isOnceOperation(functor->timeType() == func::CFunctor::once) 
     15    , isInstantOperation(functor->timeType() == func::CFunctor::instant) 
    1416    // If we can optimize the sampling when dealing with an instant functor we do it 
    15     , samplingFreq((functor->timeType() == func::CFunctor::instant && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq : samplingFreq) 
    16     , samplingOffset((functor->timeType() == func::CFunctor::instant && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq - initDate.getRelCalendar().getTimeStep() : samplingOffset) 
     17    , samplingFreq((isInstantOperation && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq : samplingFreq) 
     18    , samplingOffset((isInstantOperation && samplingFreq == TimeStep && samplingOffset == NoneDu) ? opFreq - initDate.getRelCalendar().getTimeStep() : samplingOffset) 
    1719    , opFreq(opFreq) 
    1820    , nextSamplingDate(initDate + this->samplingOffset + initDate.getRelCalendar().getTimeStep()) 
    1921    , nextOperationDate(initDate + this->samplingOffset + opFreq) 
    2022    , isFirstOperation(true) 
    21     , isOnceOperation(functor->timeType() == func::CFunctor::once) 
    2223  { 
    2324  } 
     
    2930    if (data[0]->status != CDataPacket::END_OF_STREAM) 
    3031    { 
    31       const bool usePacket = isOnceOperation ? isFirstOperation : (data[0]->date >= nextSamplingDate); 
     32      bool usePacket, outputResult, copyLess; 
     33      if (isOnceOperation) 
     34        usePacket = outputResult = copyLess = isFirstOperation; 
     35      else 
     36      { 
     37        usePacket = (data[0]->date >= nextSamplingDate); 
     38        outputResult = (data[0]->date + samplingFreq > nextOperationDate); 
     39        copyLess = (isInstantOperation && usePacket && outputResult); 
     40      } 
     41 
    3242      if (usePacket) 
    3343      { 
    34         if (!tmpData.numElements()) 
    35           tmpData.resize(data[0]->data.numElements()); 
     44        if (!copyLess) 
     45        { 
     46          if (!tmpData.numElements()) 
     47            tmpData.resize(data[0]->data.numElements()); 
    3648 
    37         (*functor)(data[0]->data); 
     49          (*functor)(data[0]->data); 
     50        } 
    3851 
    3952        nextSamplingDate = nextSamplingDate + samplingFreq; 
    4053      } 
    4154 
    42       const bool outputResult = isOnceOperation ? isFirstOperation : (data[0]->date + samplingFreq > nextOperationDate); 
    4355      if (outputResult) 
    4456      { 
    45         functor->final(); 
     57        if (!copyLess) 
     58        { 
     59          functor->final(); 
    4660 
    47         packet = CDataPacketPtr(new CDataPacket); 
    48         packet->date = data[0]->date; 
    49         packet->timestamp = data[0]->timestamp; 
    50         packet->status = data[0]->status; 
    51         packet->data.resize(tmpData.numElements()); 
    52         packet->data = tmpData; 
     61          packet = CDataPacketPtr(new CDataPacket); 
     62          packet->date = data[0]->date; 
     63          packet->timestamp = data[0]->timestamp; 
     64          packet->status = data[0]->status; 
     65          packet->data.resize(tmpData.numElements()); 
     66          packet->data = tmpData; 
     67        } 
     68        else 
     69          packet = data[0]; 
    5370 
    5471        isFirstOperation = false; 
  • XIOS/trunk/src/filter/temporal_filter.hpp

    r1123 r1124  
    5757      bool isFirstOperation; //!< True before the first operation was been computed 
    5858      const bool isOnceOperation; //!< True if the operation should be computed just once 
     59      const bool isInstantOperation; //!< True if the operation is instant 
    5960  }; // class CTemporalFilter 
    6061} // namespace xios 
Note: See TracChangeset for help on using the changeset viewer.