Re: shared pointer as a return type

From: James Dinan (dinan_at_cse.ohio-state.edu)
Date: Sun Jan 03 2010 - 08:05:03 PST

  • Next message: Oystein Thorsen: "Re: shared pointer as a return type"
    Hi Orsten,
    
    I have started the habit of using typedefs whenever I have nested shared
    pointers in UPC and this has helped resolve warnings like this in the
    past.  That would look something like:
    
    typedef shared [] int *shared array_elem_t;
    
    and the function would return "shared array_elem_t *".  I'm not sure if
    it's significant, but that's one more shared than you've got in your
    example.  IIRC the compiler will give you an error if you write "shared
    shared" so that may have been another motivation for the typedef.
    
    Good luck,
     ~Jim.
    
    Oystein Thorsen wrote:
    > Hi,
    > 
    > I was looking at the code for allocating a shared 2D array (posted on
    > this email list early December 09) and tried to put it in a function
    > that returns the pointer to the array, but I get a warning from the
    > compiler that doesn't make much sense to me: (The program seems to work
    > fine if I ignore the error though)
    > 
    > $ upcc test.c
    > test.c: In function `allocate2DArray':
    > test.c:26: warning: return from incompatible pointer type
    > $
    > 
    > Here is a simplified version of the code (All in one file):
    > 
    > #include <upc_relaxed.h>
    > #include <stdio.h>
    > 
    > shared [] int *shared * allocate2DArray(int rows, int columns);
    > 
    > int main() {
    >    shared [] int *shared * data;
    > 
    >    data = allocate2DArray(5, 3);
    > 
    >    return 0;
    > }
    > 
    > // Allocate a 2D Array in shared space with a row-wise round-robin
    > distribution.
    > shared [] int *shared * allocate2DArray(int rows, int columns) {
    >    shared [] int *shared * array;
    >    int r, c;
    > 
    >    array = (shared [] int *shared *)upc_all_alloc(rows, sizeof(shared []
    > int *shared));
    >    upc_barrier;
    >    for (r = 0; r < rows; ++r) {
    >        if (upc_threadof(&array[r]) == MYTHREAD) {
    >            array[r] = (shared [] int *shared)upc_alloc(sizeof(shared
    > int) * columns);
    >        }
    >    }
    > 
    >    return array; //<===== Warning points to this line
    > }
    > 
    > end of code
    > 
    > I'm using the Berkeley upcc compiler version 2.10.0 with remote
    > translation.
    > 
    > The warning goes away if I move the declaration of allocate2DArray() to
    > where the prototype is (and remove the prototype). Or if I cast array to
    > remove the blocking factor on return:
    > 
    > return (shared int *shared *)array;
    > 
    > The warning comes back if I do both....
    > 
    > Regards,
    > 
    > Oystein
    

  • Next message: Oystein Thorsen: "Re: shared pointer as a return type"