carrayspointersparallel-processingupc

Array of private pointers to shared array in UPC


I am programming in UPC and have an array shared between two threads. Each thread has private pointers to these shared areas:

#define SIZE 10000
#define HALFSIZE (SIZE/2)

shared [ HALFSIZE ] int table [ SIZE ]; /* all areas */
shared [ HALFSIZE ] int *first_area_pt; /* points to first thread area */
shared [ HALFSIZE ] int *second_area_pt; /* points to second thread area */

Now I want not 2, but N threads, N areas and N pointers. So I need an array of these pointers:

shared [ HALFSIZE ] int *first_area_pt;
shared [ HALFSIZE ] int *second_area_pt;

How should I define it?


Solution

  • Since the notation you're using is non-standard (although I gather it follows the UPC - Unified Parallel C - specification), we can only guess at what you might need. It would be helpful to highlight what you're using because (when) it is unusual.

    This looks superficially plausible, under one possible interpretation of the shared [ N ] notation.

    #define SIZE 10000
    #define NUMTHREADS 25
    #define FRACSIZE (SIZE/NUMTHREADS)
    
    shared [ FRACSIZE ] int table[SIZE];
    shared [ 1 ]        int *area_ptr[NUMTHREADS];