Re: dynamically allocating memory for two dimensional array

From: Benjamin Byington (bbyingto_at_soe_dot_ucsc_dot_edu)
Date: Fri Jul 17 2009 - 08:07:19 PDT

  • Next message: sainath l: "Re: dynamically allocating memory for two dimensional array"
    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: sainath l: "Re: dynamically allocating memory for two dimensional array"