Actual source code: htool.hpp

  1: #pragma once

  3: #include <petsc/private/matimpl.h>
  4: #include <petscmathtool.h>

  6: PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN("-Wsign-compare")
  7: #include <htool/clustering/clustering.hpp>
  8: #include <htool/hmatrix/lrmat/SVD.hpp>
  9: #include <htool/hmatrix/lrmat/fullACA.hpp>
 10: #include <htool/hmatrix/hmatrix_distributed_output.hpp>
 11: #include <htool/hmatrix/linalg/factorization.hpp>
 12: #include <htool/distributed_operator/utility.hpp>
 13: PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END()

 15: class WrapperHtool : public htool::VirtualGenerator<PetscScalar> {
 16:   MatHtoolKernelFn *&kernel;
 17:   PetscInt           sdim;
 18:   void              *ctx;

 20: public:
 21:   WrapperHtool(PetscInt dim, MatHtoolKernelFn *&g, void *kernelctx) : VirtualGenerator<PetscScalar>(), kernel(g), sdim(dim), ctx(kernelctx) { }
 22:   void copy_submatrix(PetscInt M, PetscInt N, const PetscInt *rows, const PetscInt *cols, PetscScalar *ptr) const
 23:   {
 24: #if !PetscDefined(HAVE_OPENMP)
 25:     PetscFunctionBegin;
 26: #endif
 27:     PetscCallAbort(PETSC_COMM_SELF, kernel(sdim, M, N, rows, cols, ptr, ctx));
 28: #if !PetscDefined(HAVE_OPENMP)
 29:     PetscFunctionReturnVoid();
 30: #endif
 31:   }
 32: };

 34: struct Mat_Htool {
 35:   PetscInt                                                            dim;
 36:   PetscReal                                                          *gcoords_target;
 37:   PetscReal                                                          *gcoords_source;
 38:   PetscScalar                                                        *work_target;
 39:   PetscScalar                                                        *work_source;
 40:   PetscInt                                                            min_cluster_size;
 41:   PetscReal                                                           epsilon;
 42:   PetscReal                                                           eta;
 43:   PetscInt                                                            depth[2];
 44:   PetscBool                                                           block_tree_consistency;
 45:   MatHtoolCompressorType                                              compressor;
 46:   MatHtoolClusteringType                                              clustering;
 47:   MatHtoolKernelFn                                                   *kernel;
 48:   void                                                               *kernelctx;
 49:   WrapperHtool                                                       *wrapper;
 50:   std::unique_ptr<htool::Cluster<PetscReal>>                          target_cluster;
 51:   std::unique_ptr<htool::Cluster<PetscReal>>                          source_cluster;
 52:   std::unique_ptr<htool::DistributedOperatorFromHMatrix<PetscScalar>> distributed_operator_holder;
 53: };

 55: struct MatHtoolKernelTranspose {
 56:   Mat               A;
 57:   MatHtoolKernelFn *kernel;
 58:   void             *kernelctx;
 59: };