Re: dynamically allocating memory for two dimensional array

From: sainath l (ls.sainath_at_gmail_dot_com)
Date: Fri Jul 17 2009 - 08:56:21 PDT

  • Next message: Benjamin Byington: "Re: dynamically allocating memory for two dimensional array"
    Thank you for the reply.
    Actually I am not worried about the performance here. I am interested in
    finding out how much time  the allocation routine in itself takes.
    
    I would need an array of pointers like
    
    shared int *shared a[N]
    
    so that I can allocate to each of these pointers memory using some
    allocation routine. The problem is that N is not a constant . I need to
    adjust it depending on the time taken by the allocation routine. So my
    question is how can I get this shared array of pointers dynamically. It
    doesn't matter how I get this shared array of pointers but it is necessary
    that I get this.
    
    Thank you very much.
    
    Sainath
    
    On Fri, Jul 17, 2009 at 4:07 PM, Benjamin Byington <bbyingto_at_soe_dot_ucsc_dot_edu>wrote:
    
    > Sainath,
    >
    > In addition to what James said, are you *sure* that you want to use
    > pointers to pointers?  In the regular C land that is already a non-optimal
    > way to do 2D arrays since not only does accessing a single element require
    > two pointer preferences in stead of one, you also lose any benefits from
    > having things in contiguous memory.  This only get compounded in UPC since
    > shared pointer accesses are even slower and can require remote
    > communication.  Maybe the performance of this section doesn't really matter,
    > but you still might be better off allocating it as a single nxm array in
    > shared memory, and then doing something like handling indexing yourself.
    >
    > Ben
    >
    >
    > ----- Original Message -----
    > From: "James Dinan" <[email protected]>
    > To: "sainath l" <ls.sainath_at_gmail_dot_com>
    > Cc: upc-users_at_lbl_dot_gov
    > Sent: Friday, July 17, 2009 10:50:42 AM GMT -05:00 US/Canada Eastern
    > Subject: Re: dynamically allocating memory for two dimensional array
    >
    > sainath l wrote:
    > > Hi again,
    > >
    > > I still haven't worked out how to do this, and it is very important for
    > me.
    > >
    > > I am trying to find out the overhead associated with  allocation
    > routines.
    > > For this I need to run the allocation routines N times. I do not know at
    > > compilation the value of N.
    > >
    > > I therefore need to allocate memory to the pointer
    > >
    > > shared int  *shared *shared a;
    > >
    > > to obtain an array of shared pointers each of which points to shared
    > > integers.
    > >
    > > Once again, I would be very grateful if someone could suggest how I
    > > might achieve this.
    >
    > Hi Sainath,
    >
    > "*shared" is specifying storage for a so I think you only need to give
    > the shared once.  I would suggest something like:
    >
    > typedef shared int * shr_int_p;
    > shr_int_p *shared a;
    >
    > Good luck,
    >  ~Jim.
    >
    

  • Next message: Benjamin Byington: "Re: dynamically allocating memory for two dimensional array"