Re: Defining a table dynamically ...

From: Dan Bonachea (bonachea_at_cs_dot_berkeley_dot_edu)
Date: Tue Jun 13 2006 - 15:44:47 PDT

  • Next message: Brent Webster: "UPC licensing"
    At 10:43 AM 6/13/2006, Konstantin Kleisouris wrote:
    >Hi,
    >
    >    I am interested in defining a table dynamically in UPC.
    >This table should have affinity to Thread 0. I would like
    >to define an array like data1 below.
    >shared [] int data1[10][2];
    >
    >    The way I did it is as follows:
    >shared [] int * shared [] * shared data2;
    >
    >if (MYTHREAD == 0) {
    >       data2 = (shared [] int * shared [] *) upc_alloc(10 *
    >sizeof(int *));
    
    the line above has a bug - it should be sizeof(shared [] int *), which is 
    often different from sizeof(int *).
    BTW - for such complicated ptr-to-shared expressions, it often makes it easier 
    to read if you define some typedefs, eg:
    
    typedef shared [] int *tablerow;
    tablerow shared [] * shared data2;
    
    However, this table is a discontiguous pointer-based table, so it will be less 
    efficient than the fully contiguous data1 defined above, and also will not be 
    compatible with library calls like upc_all_gather.
    
    You can get a contiguous layout with something like:
    
    shared [] int (* shared a)[10][2];
    
    ...
       if (MYTHREAD == 0) {
         shared [] int * p  = upc_alloc(sizeof(int)*10*2);
         a = (shared [] int(*)[10][2])p;
       }
       ...(*a)[i][j]...
    
    Dan
    
    >
    >       for(i = 0; i < 10; i++) {
    >         data2[i] = (shared [] int *) upc_alloc(2 * sizeof(int));
    >       }
    >}
    >
    >
    >Howevever when I use data1 in a gather it works fine
    >  upc_all_gather(data1, data, sizeof(int)*4,
    >UPC_IN_ALLSYNC|UPC_OUT_ALLSYNC);
    >
    >Imagine that data in the gather above is defined as
    >shared [2] int data[10][2];
    >
    >
    >But when I use data2 in the same gather as bellow
    >  upc_all_gather(data2, data, sizeof(int)*4,
    >UPC_IN_ALLSYNC|UPC_OUT_ALLSYNC);
    >
    >I get the following message:
    >UPC Runtime error: Attempt to use a bogus
    >upcr_pshared_ptr_t: addrfield out of range
    >   <pshared_ptr: addr=0xe2fed004 (offset=0x4), thread=0,
    >phase=0>
    >   at /UPC_DEBUG//include/upcr_sptr.h:1245
    >
    >Any idea?
    >
    >Kosta
    

  • Next message: Brent Webster: "UPC licensing"