does upc_alloc allocates memory with affinity to the calling thread

From: Venelin Mitov (vmitov_at_gmail_dot_com)
Date: Mon Jan 03 2005 - 11:31:44 PST

  • Next message: bugzilla-daemon_at_mantis_dot_lbl_dot_gov: "[Bug 931] does upc_alloc allocates memory with affinity to the calling thread"
    Hello again,
    By specification the upc_alloc function allocates memory with affinity
    to the calling thread, but the following example denies it:
    
    #include <upc_relaxed.h>
    #include <stdio.h>
    
    #define N (2*THREADS)
    #define MODE_ELLIPSE 0
    #define MODE_RECTANGLE 1
    
    typedef struct {
        int X, Y;
    } Point;
    
    typedef struct {
        shared[] Point * pts;
        int leftest;
        int end;
    } Hull;
    
    void hullcpy(shared Hull* dst, shared Hull* src){
        int i;
        dst->pts = (shared[] Point *)upc_alloc(src->end*sizeof(Point));
    
        printf("t%d:hullcpy thread of dst->pts=%d\n", MYTHREAD,
    upc_threadof(dst->pts));
        upc_memcpy(dst->pts, src->pts, src->end*sizeof(Point));
        dst->end = src->end;
        dst->leftest = src->leftest;
    }
    
    shared[N/THREADS] Hull hulls[N];
    
    
    /*********************************** MAIN ***********************************/
    int main(){
    
        hulls[MYTHREAD*2].pts = (shared[] Point *)upc_alloc(N*sizeof(Point));
    
        hulls[MYTHREAD*2].pts[0].X = 0;
        hulls[MYTHREAD*2].pts[0].Y = 1;
        hulls[MYTHREAD*2].pts[1].X = 2;
        hulls[MYTHREAD*2].pts[1].Y = 3;
        hulls[MYTHREAD*2].pts[2].X = 4;
        hulls[MYTHREAD*2].pts[2].Y = 5;
        hulls[MYTHREAD*2].pts[3].X = 6;
        hulls[MYTHREAD*2].pts[3].Y = 7;
    
        upc_barrier;
    
        printf("hulls[0].pts:%d\n", upc_threadof(hulls[0].pts));
        printf("hulls[2].pts:%d\n", upc_threadof(hulls[2].pts));
    
    
        if(MYTHREAD == 1)
            hullcpy((shared Hull*)(&hulls[1]), (shared Hull*)(&hulls[2]));
        else
            hullcpy((shared Hull*)(&hulls[3]), (shared Hull*)(&hulls[0]));
    
        upc_barrier;
    
        printf("hulls[1].pts:%d\n", upc_threadof(hulls[1].pts));
        printf("hulls[3].pts:%d\n", upc_threadof(hulls[3].pts));
    
        return 0;
    }
    
    The program was compiled with "upcc -T 2 -o point point.c" 
    Here is the output:
    
    UPCR: UPC thread 0 of 2 on hpc-n06 (process 0 of 2, pid=15887)
    UPCR: UPC thread 1 of 2 on hpc-n04 (process 1 of 2, pid=13776)
    hulls[0].pts:0
    hulls[2].pts:1
    t1:hullcpy thread of dst->pts=0    //!!!! I think it should be thread 1 here
    hulls[1].pts:0                              //!!!! 1
    hulls[0].pts:0
    hulls[2].pts:1
    t0:hullcpy thread of dst->pts=0
    hulls[1].pts:0                              //!!!! 1
    hulls[3].pts:0
    hulls[3].pts:0
    
    TID  HOST_NAME    COMMAND_LINE            STATUS            TERMINATION_TIME
    ==== ========== ================  =======================  ===================
    0001 hpc-n06    mpirun --gm-kill  Done                     01/03/2005 20:20:57
    0002 hpc-n04    mpirun --gm-kill  Done                     01/03/2005 20:20:57
    
    It seems that only the call to upc_alloc in the main function has
    allocated memory
    with the correct affinity.
    

  • Next message: bugzilla-daemon_at_mantis_dot_lbl_dot_gov: "[Bug 931] does upc_alloc allocates memory with affinity to the calling thread"