@@ -14,12 +14,12 @@ package.
1414----------------------------------------------------------------------------*/
1515#ifndef ADOLC_SPARSE_DRIVERS_H
1616#define ADOLC_SPARSE_DRIVERS_H
17-
1817#include < adolc/adalloc.h>
1918#include < adolc/adolcerror.h>
2019#include < adolc/interfaces.h>
2120#include < adolc/internal/common.h>
2221#include < adolc/tape_interface.h>
22+ #include < adolc/valuetape/sparseinfos.h>
2323#include < adolc/valuetape/valuetape.h>
2424#include < cstddef>
2525#include < span>
@@ -31,8 +31,6 @@ package.
3131// (block) variables at once
3232#define PQ_STRIPMINE_MAX 30
3333
34- #ifdef SPARSE
35- #include < ColPack/ColPackHeaders.h>
3634namespace ADOLC ::Sparse {
3735
3836enum class SparseMethod {
@@ -613,17 +611,12 @@ ADOLC_API int jac_pat(short tag, int depen, int indep, const double *basepoint,
613611 * according to ColPack's unmanaged API semantics.
614612 */
615613template <CompressionMode CM>
616- ADOLC_API void generate_seed_jac (int m, int n, const std::span<uint *> & JP,
614+ ADOLC_API void generate_seed_jac (int m, int n, const std::span<uint *> JP,
617615 double ***Seed, int *p) {
618- int dummy = 0 ;
619- auto g = std::make_unique<ColPack::BipartiteGraphPartialColoringInterface>(
620- SRC_MEM_ADOLC, JP.data (), m, n);
621616 if constexpr (CM == CompressionMode::Row)
622- g->GenerateSeedJacobian_unmanaged (Seed, p, &dummy, " SMALLEST_LAST" ,
623- " ROW_PARTIAL_DISTANCE_TWO" );
617+ generateSeedJac (m, n, JP, Seed, p, " ROW_PARTIAL_DISTANCE_TWO" );
624618 else if (CM == CompressionMode::Column)
625- g->GenerateSeedJacobian_unmanaged (Seed, &dummy, p, " SMALLEST_LAST" ,
626- " COLUMN_PARTIAL_DISTANCE_TWO" );
619+ generateSeedJac (m, n, JP, Seed, p, " COLUMN_PARTIAL_DISTANCE_TWO" );
627620}
628621
629622namespace detail {
@@ -700,24 +693,14 @@ int buildJacPatternAndSeed(short tag, int depen, int indep,
700693 }
701694
702695 *nnz = tape.sJInfos ().nnzIn_ ;
703-
704- tape.sJInfos ().g_ =
705- std::make_unique<ColPack::BipartiteGraphPartialColoringInterface>(
706- SRC_MEM_ADOLC, tape.sJInfos ().getJP ().data (), depen, indep);
707- tape.sJInfos ().jr1d_ = std::make_unique<ColPack::JacobianRecovery1D>();
696+ tape.sJInfos ().initColoring (depen, indep);
708697
709698 if constexpr (CM == CompressionMode::Row) {
710- tape.sJInfos ().g_ ->GenerateSeedJacobian (
711- &(tape.sJInfos ().Seed_ ), &(tape.sJInfos ().seedRows_ ),
712- &(tape.sJInfos ().seedClms_ ), " SMALLEST_LAST" ,
713- " ROW_PARTIAL_DISTANCE_TWO" );
699+ tape.sJInfos ().generateSeedJac (" ROW_PARTIAL_DISTANCE_TWO" );
714700 tape.sJInfos ().seedClms_ = indep;
715701 ret_val = tape.sJInfos ().seedRows_ ;
716702 } else if (CM == CompressionMode::Column) {
717- tape.sJInfos ().g_ ->GenerateSeedJacobian (
718- &(tape.sJInfos ().Seed_ ), &(tape.sJInfos ().seedRows_ ),
719- &(tape.sJInfos ().seedClms_ ), " SMALLEST_LAST" ,
720- " COLUMN_PARTIAL_DISTANCE_TWO" );
703+ tape.sJInfos ().generateSeedJac (" COLUMN_PARTIAL_DISTANCE_TWO" );
721704 tape.sJInfos ().seedRows_ = depen;
722705 ret_val = tape.sJInfos ().seedClms_ ;
723706 }
@@ -816,13 +799,9 @@ int computeSparseJac(short tag, int depen, int indep, const double *basepoint,
816799 // everything is preallocated, we assume correctly
817800 // call usermem versions
818801 if (CM == CompressionMode::Row)
819- tape.sJInfos ().jr1d_ ->RecoverD2Row_CoordinateFormat_usermem (
820- tape.sJInfos ().g_ .get (), tape.sJInfos ().B_ , tape.sJInfos ().JP_ .data (),
821- rind, cind, values);
802+ tape.sJInfos ().recoverRowFormat (rind, cind, values);
822803 else if (CM == CompressionMode::Column)
823- tape.sJInfos ().jr1d_ ->RecoverD2Cln_CoordinateFormat_usermem (
824- tape.sJInfos ().g_ .get (), tape.sJInfos ().B_ , tape.sJInfos ().JP_ .data (),
825- rind, cind, values);
804+ tape.sJInfos ().recoverColFormat (rind, cind, values);
826805 } else {
827806 // at least one of rind cind values is not allocated, deallocate others
828807 // and call unmanaged versions
@@ -833,13 +812,9 @@ int computeSparseJac(short tag, int depen, int indep, const double *basepoint,
833812 if (cind != nullptr && *cind != nullptr )
834813 free (*cind);
835814 if (CM == CompressionMode::Row) {
836- tape.sJInfos ().jr1d_ ->RecoverD2Row_CoordinateFormat_unmanaged (
837- tape.sJInfos ().g_ .get (), tape.sJInfos ().B_ , tape.sJInfos ().JP_ .data (),
838- rind, cind, values);
815+ tape.sJInfos ().recoverRowFormat (rind, cind, values);
839816 } else if (CM == CompressionMode::Column) {
840- tape.sJInfos ().jr1d_ ->RecoverD2Cln_CoordinateFormat_unmanaged (
841- tape.sJInfos ().g_ .get (), tape.sJInfos ().B_ , tape.sJInfos ().JP_ .data (),
842- rind, cind, values);
817+ tape.sJInfos ().recoverColFormat (rind, cind, values);
843818 }
844819 }
845820 return ret_val;
@@ -1012,17 +987,12 @@ ADOLC_API int hess_pat(short tag, int indep, const double *basepoint,
1012987 * returned Seed.
1013988 */
1014989template <RecoveryMethod RCM>
1015- ADOLC_API void generate_seed_hess (int n, std::span<uint *> & HP, double ***Seed,
990+ ADOLC_API void generate_seed_hess (int n, std::span<uint *> HP, double ***Seed,
1016991 int *p) {
1017- int seed_rows;
1018- auto g = std::make_unique<ColPack::GraphColoringInterface>(SRC_MEM_ADOLC,
1019- HP.data (), n);
1020992 if constexpr (RCM == RecoveryMethod::Indirect)
1021- g->GenerateSeedHessian_unmanaged (Seed, &seed_rows, p, " SMALLEST_LAST" ,
1022- " ACYCLIC_FOR_INDIRECT_RECOVERY" );
993+ generateSeedHess (n, HP, Seed, p, " ACYCLIC_FOR_INDIRECT_RECOVERY" );
1023994 else if (RCM == RecoveryMethod::Direct)
1024- g->GenerateSeedHessian_unmanaged (Seed, &seed_rows, p, " SMALLEST_LAST" ,
1025- " STAR" );
995+ generateSeedHess (n, HP, Seed, p, " STAR" );
1026996}
1027997
1028998namespace detail {
@@ -1066,8 +1036,6 @@ template <ControlFlowMode CFM, RecoveryMethod RCM>
10661036int buildHessPatternAndSeed (short tag, int indep, const double *basepoint,
10671037 int *nnz) {
10681038 ValueTape &tape = findTape (tag);
1069- double **Seed;
1070- int dummy;
10711039 int ret_val = -1 ;
10721040 // Generate sparsity pattern, determine nnz, allocate memory
10731041 tape.sHInfos ().setHP (indep, std::vector<uint *>(indep));
@@ -1093,19 +1061,12 @@ int buildHessPatternAndSeed(short tag, int indep, const double *basepoint,
10931061
10941062 // compute seed matrix => ColPack library
10951063
1096- Seed = nullptr ;
1097-
1098- tape.sHInfos ().g_ = std::make_unique<ColPack::GraphColoringInterface>(
1099- SRC_MEM_ADOLC, tape.sHInfos ().getHP ().data (), indep);
1100- tape.sHInfos ().hr_ = std::make_unique<ColPack::HessianRecovery>();
1101-
1064+ double **Seed = nullptr ;
1065+ tape.sHInfos ().initColoring (indep);
11021066 if constexpr (RCM == RecoveryMethod::Indirect)
1103- tape.sHInfos ().g_ ->GenerateSeedHessian (&Seed, &dummy, &tape.sHInfos ().p_ ,
1104- " SMALLEST_LAST" ,
1105- " ACYCLIC_FOR_INDIRECT_RECOVERY" );
1067+ tape.sHInfos ().generateSeedHess (&Seed, " ACYCLIC_FOR_INDIRECT_RECOVERY" );
11061068 else if (RCM == RecoveryMethod::Direct)
1107- tape.sHInfos ().g_ ->GenerateSeedHessian (&Seed, &dummy, &tape.sHInfos ().p_ ,
1108- " SMALLEST_LAST" , " STAR" );
1069+ tape.sHInfos ().generateSeedHess (&Seed, " STAR" );
11091070
11101071 tape.sHInfos ().Hcomp_ = myalloc2 (indep, tape.sHInfos ().p_ );
11111072 tape.sHInfos ().Xppp_ = myalloc3 (indep, tape.sHInfos ().p_ , 1 );
@@ -1195,13 +1156,9 @@ int computeSparseHess(short tag, int indep, const double *basepoint, int *nnz,
11951156 // everything is preallocated, we assume correctly
11961157 // call usermem versions
11971158 if constexpr (RCM == RecoveryMethod::Indirect)
1198- tape.sHInfos ().hr_ ->IndirectRecover_CoordinateFormat_usermem (
1199- tape.sHInfos ().g_ .get (), tape.sHInfos ().Hcomp_ ,
1200- tape.sHInfos ().HP_ .data (), rind, cind, values);
1159+ tape.sHInfos ().indirectRecoverUserMem (rind, cind, values);
12011160 else if (RCM == RecoveryMethod::Direct)
1202- tape.sHInfos ().hr_ ->DirectRecover_CoordinateFormat_usermem (
1203- tape.sHInfos ().g_ .get (), tape.sHInfos ().Hcomp_ ,
1204- tape.sHInfos ().HP_ .data (), rind, cind, values);
1161+ tape.sHInfos ().directRecoverUserMem (rind, cind, values);
12051162 } else {
12061163 // at least one of rind cind values is not allocated, deallocate others
12071164 // and call unmanaged versions
@@ -1212,13 +1169,9 @@ int computeSparseHess(short tag, int indep, const double *basepoint, int *nnz,
12121169 if (*cind != nullptr )
12131170 free (*cind);
12141171 if constexpr (RCM == RecoveryMethod::Indirect)
1215- tape.sHInfos ().hr_ ->IndirectRecover_CoordinateFormat_unmanaged (
1216- tape.sHInfos ().g_ .get (), tape.sHInfos ().Hcomp_ ,
1217- tape.sHInfos ().HP_ .data (), rind, cind, values);
1172+ tape.sHInfos ().indirectRecover (rind, cind, values);
12181173 else if (RCM == RecoveryMethod::Direct)
1219- tape.sHInfos ().hr_ ->DirectRecover_CoordinateFormat_unmanaged (
1220- tape.sHInfos ().g_ .get (), tape.sHInfos ().Hcomp_ ,
1221- tape.sHInfos ().HP_ .data (), rind, cind, values);
1174+ tape.sHInfos ().directRecover (rind, cind, values);
12221175 }
12231176 return ret_val;
12241177}
@@ -1277,6 +1230,4 @@ sparse_hess(short tag, int indep, int repeat, const double *basepoint, int *nnz,
12771230/* ***************************************************************************/
12781231
12791232} // namespace ADOLC::Sparse
1280-
1281- #endif // SPARSE
12821233#endif // ADOLC_SPARSE_DRIVERS_H
0 commit comments