Changeset 193 for trunk/ADOL-C


Ignore:
Timestamp:
Jan 18, 2011 6:26:40 AM (9 years ago)
Author:
kulshres
Message:

Allow repeated use of the same memory for sparse_hess and sparse_jac

This is in conjunction with the new ColPack? functions from version 1.0.2
If the pointers rind, cind and values passed to sparse_hess and spase_jac
not NULL they will be assumed to be allocated properly by the user.
Any segmentation-violation due to incorrect allocation is the responsibility
of the user. If any one of rind, cind or values is NULL then the other
non-NULL pointers will be freed and all three will be reallocated

Older Colpack than 1.0.2 cannot be used with this.

Feature-request-by: Andrey Romanenko <andrey.romanenko@…>
Cc: Assefaw Gebremedhin <agebreme@…>

Andrea Walther <andrea.walther@…>

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/src/sparse/sparsedrivers.cpp

    r192 r193  
    378378    /* recover compressed Jacobian => ColPack library */
    379379 
     380    if (values != NULL && rind != NULL && cind != NULL) {
     381      // everything is preallocated, we assume correctly
     382      // call usermem versions
     383      if (options[3] == 1)
     384       jr1d->RecoverD2Row_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, rind, cind, values);
     385     else
     386       jr1d->RecoverD2Cln_CoordinateFormat_usermem(g, sJinfos.B, sJinfos.JP, rind, cind, values);
     387    } else {
     388      // at least one of rind cind values is not allocated, deallocate others
     389      // and call unmanaged versions
     390      if (values != NULL)
     391          free(values);
     392      if (rind != NULL)
     393          free(rind);
     394      if (cind != NULL)
     395          free(cind);
    380396      if (options[3] == 1)
    381397       jr1d->RecoverD2Row_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, cind, values);
    382398     else
    383399       jr1d->RecoverD2Cln_CoordinateFormat_unmanaged(g, sJinfos.B, sJinfos.JP, rind, cind, values);
     400    }
    384401
    385402    return ret_val;
     
    588605//        HessianRecovery::DirectRecover_CoordinateFormat(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values);
    589606 
     607    if (values != NULL && rind != NULL && cind != NULL) {
     608     // everything is preallocated, we assume correctly
     609     // call usermem versions
     610     if (options[1] == 0)
     611       hr->IndirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values);
     612     else
     613       hr->DirectRecover_CoordinateFormat_usermem(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values);
     614    } else {
     615      // at least one of rind cind values is not allocated, deallocate others
     616      // and call unmanaged versions
     617      if (values != NULL)
     618          free(values);
     619      if (rind != NULL)
     620          free(rind);
     621      if (cind != NULL)
     622          free(cind);
    590623     if (options[1] == 0)
    591624       hr->IndirectRecover_CoordinateFormat_unmanaged(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values);
    592625     else
    593626       hr->DirectRecover_CoordinateFormat_unmanaged(g, sHinfos.Hcomp, sHinfos.HP, rind, cind, values);
    594  
     627    }
    595628    return ret_val;
    596629
Note: See TracChangeset for help on using the changeset viewer.