Git Product home page Git Product logo

h2lib's Introduction

H2Lib

H2Lib is a software library for hierarchical matrices and H2-matrices developed mainly by the Scientific Computing Group of Kiel University.

The library offers

  • functions for setting up cluster trees and block trees,

  • functions for converting dense matrices and partially compressed matrices into hierarchical and H2-matrices,

  • functions for creating hierarchical matrices and H2-matrices for boundary element methods using various compression techniques like Chebyshev interpolation, ACA, HCA, and Green quadrature,

  • functions for creating hierarchical matrices and H2-matrices for finite element methods,

  • functions for performing arithmetic operations on hierarchical matrices like truncated matrix multiplication, inversion, and factorization.

h2lib's People

Contributors

sboerm avatar sboerm2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

h2lib's Issues

Using H2Lib in C++

While settings.h looks like being prepared for use in a C++ program, including H2Lib headers in C++ fails for me. It seems that there are two main issues:

  • The definition of INLINE_PREFIX in the __cplusplus branch does not compile because static extern "C" seems to be not allowed. Since the purpose of extern "C" is to change linkage to C-style in C++ it's maybe OK to just drop extern "C" for static C functions because they should not be linked to from user code.
  • H2Lib defines bool, true, and false which is not compatible with C++ because these are reserved keywords in C++ and not just macros. Enclosing the definition with #ifdef __cplusplus fixes the error during compilation but may lead to linker errors because C++ assumes corresponding arguments are real C++ bools while they are unsigned short in the compiled H2Lib library.

A proper fix for the bool issue could be to use BOOL, TRUE, FALSE instead. But before preparing a patch I'd like to know if there is interest in such an invasive change.

memory usage for sparse matrices

Hi,

I'm using H2lib for preconditioning my FEM matrices, and I noticed that for a time the memory usage is very high, even though (after compressing) the matrix is quite small. The problem appears because in order to compress, I first have to allocate the uncompressed matrix which has too many dense entries.
In order to work around this issue, I have now added two small functions to my local copy of H2lib (mostly copied from the build_from_block and copy_sparsematrix functions already there), which may be of interest for others. The idea is to first initialize the matrix without allocating memory for the dense subblocks, and then do the copying of the sparse entires and the compression at the same step. That way only one of the uncompressed subblocks needs to fit into memory after the other. This reduces peak memory usage by large factor in my usecase.

Maybe you could add a similar functionality to the official project?

phmatrix
build_from_block_hmatrix_noinit(pcblock b, uint k)
{  
  phmatrix  h, h1;
  pcblock   b1;
  int       rsons, csons;
  int       i, j;

  h = NULL;

  if (b->son) {
    rsons = b->rsons;
    csons = b->csons;

    h = new_super_hmatrix(b->rc, b->cc, rsons, csons);

    for (j = 0; j < csons; j++) {
      for (i = 0; i < rsons; i++) {
	b1 = b->son[i + j * rsons];

	h1 = build_from_block_hmatrix_noinit(b1, k);

	ref_hmatrix(h->son + i + j * rsons, h1);
      }
    }
  }
  else if (b->a > 0)
    h = new_rk_hmatrix(b->rc, b->cc, k);
  else{
    //printf("initializing empty\n");
    h = new_hmatrix(b->rc, b->cc);    
    h->f = new_amatrix(0,0);
    h->desc = 1;
  }

  update_hmatrix(h);

  return h;
}




void
copy_sparsematrix_coarse_hmatrix(psparsematrix sp, phmatrix hm,  ptruncmode tm,double eps)
{
  uint      i, j, k, l, m, rsize, csize;
  uint     *ridx, *cidx, *row, *col;
  pfield    coeff;
  pamatrix  f;

  if (hm->son) {
    for (j = 0; j < hm->csons; j++) {
      for (i = 0; i < hm->rsons; i++) {
	copy_sparsematrix_coarse_hmatrix(sp, hm->son[i + j * (hm->rsons)],tm,eps);
      }
    }
  }
  else if (hm->r) {		/*hm->r is defined, but hm->r->A = hm->r->B = NulL => all entries are 0 */

  }
  else if (hm->f) {
    rsize = hm->rc->size;
    csize = hm->cc->size;
    ridx = hm->rc->idx;
    cidx = hm->cc->idx;
    row = sp->row;
    col = sp->col;
    coeff = sp->coeff;
    
    if(hm->f->rows==0 && hm->f->cols==0) {
      del_amatrix(hm->f);
      hm->f = new_amatrix(rsize, csize);
    }
    f = hm->f;


    for (j = 0; j < f->cols; j++)
      for (i = 0; i < f->rows; i++)
	f->a[i + j * f->rows] = 0.0;

    for (k = 0; k < rsize; k++) {
      i = ridx[k];
      for (m = row[i]; m < row[i + 1]; m++) {
	for (l = 0; l < csize; l++) {

	  if (col[m] == cidx[l]) {

	    setentry_amatrix(hm->f, k, l, coeff[m]);
	  }
	}
      }
    }
  }

  //printf("eps:%.6e",eps);
  coarsen_hmatrix(hm, tm, eps, false);
}

Feature request: 2D Helmholtz Module

H2lib team:

I am a researcher focused on acoustic scattering and would like to solve 2D Helmholtz BEM problems using this library. I see that the library contains a 3D Helmholtz model. Is it possible to create a 2D module as well?

Derek

Speicher Problem mit SIMD in bem3d.c und Problem mit Netgen in surface3d.c

Hallo Steffen und Sven,

mir ist aufgefallen, dass in den Routinen
assemble_cl_simd_near_bem3d
assemble_lc_simd_near_bem3d
die Zeilen
freemem(quad_r);
freemem(quad_i);
del_tri_list(tl);
am Ende fehlen, und demzufolge ein Speicherproblem beim Aufstellen auftritt.

Bei der Routine zum Einlesen von Netgen Dateien muss in Zeile 1090 in surface3d.c
e = (uint(*)[2]) allocuint(edges * 2);
stehen.
In der Routine prepare_edges in surface3d müssen noch weitere freemems der Liste gemacht werden:
struct edge_list *l,*kk;
for (j = 0; j < vertices; ++j) {
l = list[j];
kk=l->next;
freemem(list[j]);
l=kk;
while (l->next != NULL) {
kk=l->next;
freemem(l);
l=kk;
}
freemem(l);
}
freemem(list);

Macro variable "I"

H2Lib/Library/settings.h

Lines 196 to 201 in 920662c

#ifndef USE_COMPLEX
#ifdef I
#undef I
#endif
#define I 0.0
#endif

The name I for a global object is a bit unfavorable. For instance, I have (different) library code that of the (C++-)form

template<typename I>
void foo()

which does not compile because I is now parsed as 0.0.

If I understand correctly, the definition is introduced so if USE_COMPLEX is not activated, only the real part of a + b*I will be considered.
(One might argue that if a user explicitly writes a+b*I they might not want to have the imaginary part silently thrown away).

If this is not so easy to fix in the library, how big is the chance I'm shooting myself in the foot if I undef I and never use complex numbers anyway?

test_h2matrix failure

Hi, not sure if this is a false positive but I'm getting a test failure in test_h2matrix. The output from the test is as follows:

dmeiser@longspeak:/home/scratch/H2Lib/Tests (master)$ ./test_h2matrix 
----------------------------------------
Check 579 x 579 Cholesky factorization
Creating laplacebem2d SLP matrix
Creating random solution and right-hand side
Copying matrix
Computing Cholesky factorization
Solving
  Accuracy 2.07929e-12,     NOT okay
Checking factorization
  Accuracy 3.57875e-14, okay
----------------------------------------
Check 579 x 579 LR factorization
Creating laplacebem2d SLP matrix
Creating random solution and right-hand side
Copying matrix
Computing LR factorization
Solving
  Accuracy 1.61567e-12, okay
Checking factorization
  Accuracy 3.14747e-14, okay
Cleaning up
----------------------------------------
  0 matrices and
  0 vectors still active
  1 errors found

This is with the make.inc.unix_release configuration with gcc 4.4 on centos 6.3 with system blas and lapack on that system (pre-compiled atlas from centos repository).

How to use h2 as a library

Hi, I wonder how I can use h2lib as a library to do h2 matrix compression on kernel matrices generated from points and kernel function. If it is possible, could you share some example codes about how to do that.

Thanks

h2lib and useblas

Dear H2Lib team,
thank you for the wonderful work you have done during this years. This library is a huge thing!
I am using your library in an existing opensource Boundary Element code for acoustics, and recently I tried to enable the USE_BLAS option. This is giving me some problem in tems of accuracy of the solution.
Using a non-homogeneous boundary condition and the gmres solver for h-matrices, the solution is completely wrong if the number of rows and columns is bigger than a certain number.
Disabling the USE_BLAS option everything goes fine.
My blas are standard from ubuntu 16.04 repository.
Do you have any idea of what can be the problem?

Test failed

pkrysl@Firebolt:/mnt/c/Users/PetrKrysl/Documents/Work-in-progress/H2Lib$ Tests/test_h2matrix
----------------------------------------
Check 579 x 579 Cholesky factorization
Creating laplacebem2d SLP matrix
Creating random solution and right-hand side
Copying matrix
Computing Cholesky factorization
test_h2matrix: Library/amatrix.c:1038: addmul_amatrix: Assertion `a->cols == b->rows' failed.
Aborted (core dumped)

The code is from my fork of the library, the latest release (3.0.1).

H2Lib as a dynamic library?

Hi,

I have tried to build the library as a shared library (dynamic) on Linux. Unfortunately none of the tests or examples than work: they crash with a segmentation fault.

Has this been attempted before (i. e. linking the examples with a dynamic library instead of a static library)?
Did it work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.