public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Gerard Jungman <jungman@lanl.gov>
To: gsl-discuss@sourceware.org
Subject: Re: switched sparse format to binary trees
Date: Thu, 01 May 2014 23:21:00 -0000	[thread overview]
Message-ID: <5362D6E1.5080605@lanl.gov> (raw)
In-Reply-To: <53629696.7070907@colorado.edu>

On 05/01/2014 12:46 PM, Patrick Alken wrote:
> I was thinking a little more about your suggestion and just wanted to 
> clarify something. As I understand it, what you are proposing is to 
> define a new "allocator" structure such as:
>
> typedef struct
> {
>   void *malloc(size_t size, void *param);
>   void free(void *block, void *param);
> } gsl_allocator;

That's the idea. Just like the avl allocator mechanism.

> And then for every gsl_xxx_alloc function, we should make a new 
> function gsl_xxx_alloc_m() which would be:
>
> gsl_xxx_alloc_m(normal_args, gsl_allocator *allocator, void 
> *allocator_param)

We need to think about the allocator parameter. There is
probably a design issue here. It is hard to insure that
the client uses the correct parameter if there are
several "pools" or "heaps" in existence. So the
state data represented by the parameter is
somewhat dangerous.

There may even be deeper semantic issues in keeping track
of state data like that, even though it seems attractive
to encapsulate the state in some explicit way. It has to
do with the fact that an an allocator resource is sort
of a singleton. Even if you have different ones floating
around, each one is probably doing a unique job, just
like the unique malloc/free heap.

Notice that the avl library allocator abstraction
avoids any notion of allocator state.

A client can always hide their state data behind a functional
interface. So they could easily create a "heap" for vectors,
and a "heap" for matrices, or whatever, each with their
own malloc. So it may be best to avoid any explicit
notion of state and let the client do what they want
behind the functions.

> and all malloc/free calls would then be replaced by calls to 
> allocator->malloc and allocator->free

Yup.

> In this scenario, all gsl data structures would need an additional 
> pointer to store the gsl_allocator desired by the user.

This seems correct, in order to match the allocation call with the
correct free call.

But there may be more to it as well. Basically, any function
which currently does a malloc or free needs to be thought
about, probably requiring an additional interface also
taking an allocator parameter. It is clearly possible
and probably not too difficult to do the operations
in the right order, swap the allocator pointers,
and move on, so that the container is always in
a consistent state with regard to its allocator.

> The default gsl_xxx_alloc() functions would use a stub allocator which 
> are just malloc()/free() wrappers.

Yup.

> For this implementation, every gsl module would use the same 
> gsl_allocator framework. I wanted to confirm with you that this is 
> what you intended? Or are you thinking of module-specific allocators 
> since you were focusing a lot on the spmatrix design?

Most of the containers have a homogeneous structure, basically
using one layer of heap allocation, for their data blocks.
When we get to something like spmatrix, there are really
at least two distinct allocation needs, for the data
and for the tree nodes. So it may well be correct to
design a more semantically rich allocation framework
for those containers.

It may be as simple as providng two allocators,
one for the nodes, one for the data. But maybe
more is needed, to allow control of the relative
locality of the nodes and data, as I wondered
earlier.

Other places in GSL may need some custom tailoring
as well. Basically, I will just grep for all the malloc
and free calls currently, and estimate what needs to
be done. Anybody interested in this should do the
same. Then we can discuss.

> It seems like a reasonable idea to me, and if we are going to do it, 
> it should be done before the 2.0 release, since every gsl_workspace 
> will need to be modified.

Exactly.

> I'm not certain how much demand there will be for something like this, 
> since I suspect most users won't want to write their own malloc/free 
> implementations, but who knows :)

It is hard to say. But let's think about what it might entail
and weigh the costs and benefits when we know more.

--
G. Jungman

  reply	other threads:[~2014-05-01 23:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-28  1:32 Patrick Alken
2014-04-28 22:35 ` Gerard Jungman
2014-04-29  1:13   ` Patrick Alken
2014-04-29  8:40     ` Frank Reininghaus
2014-04-29 19:15       ` Gerard Jungman
2014-04-29 19:52         ` Patrick Alken
2014-04-29 22:07           ` Gerard Jungman
2014-05-01 18:46             ` Patrick Alken
2014-05-01 23:21               ` Gerard Jungman [this message]
2014-05-02  1:48                 ` GSL containers (switched sparse format to binary trees) Gerard Jungman
2014-05-02  1:56                   ` Gerard Jungman
2014-05-02  8:29                     ` Rhys Ulerich
2014-05-02  8:33                       ` Rhys Ulerich
2014-05-02  8:52                         ` Rhys Ulerich
2014-05-02 15:02                     ` Patrick Alken
2014-05-13 21:59                       ` Gerard Jungman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5362D6E1.5080605@lanl.gov \
    --to=jungman@lanl.gov \
    --cc=gsl-discuss@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).