Re: Storing Pointers to Shared in Non-UPC Environment

From: Paul H. Hargrove (PHHargrove_at_lbl_dot_gov)
Date: Fri Apr 24 2009 - 11:55:37 PDT

  • Next message: James Dinan: "UDP Conduit Environment Issue"
    Ben,
      Thanks for your interest UPC.  I can only answer your question with 
    any certainly with respect the Berkeley UPC compiler, since what you are 
    trying to do is not guaranteed to be portable.
      First, if you are not already aware of them please have a look at our 
    interoperability documentation at 
    http://upc.lbl.gov/docs/user/interoperability.html and also look in the 
    Berkeley UPC source distribution at header bupc_extern.h and the 
    directory upc-examples/interoperability.  While these don't address your 
    specific question, they do show some examples of inter-language 
    interoperability and provide info on things like linking.
      Your idea of storing a UPC poiner-to-shared in an opaque C++ datatype 
    is, in my opinion, an acceptable one.  The concern I have is that the 
    size of such an object is not necessarily 64-bits as you have assumed.  
    For some configurations we will use a struct that might have 128 bits.  
    There is no type in C++ for which you can call sizeof().  So, I would 
    recommend that your UPC/C++ interface code pass a (void *) that 
    references the UPC shared pointer stored by the UPC code.  In other 
    words, the UPC code would provide to the C++ code both the address and 
    length of the UPC pointer-to-shared, and when the C++ called UPC it 
    could pass just the address of the UPC pointer-to-shared (the length is 
    known to the UPC side).
      Here is a crude example (error checking is missing):
    
    UPC code:
        void *produce_pointer(unsigned int *len, ....) {
            void *result = malloc(sizeof(shared void *));
            memcpy(result, &some_UPC_pointer, sizeof(shared void *));
            *len = sizeof(shared void *);
            return result;
        }
        int consume_pointer(void *ptr_ptr) {
            shared void *sptr;
            memcpy(&sptr, ptr_ptr, sizeof(shared void *));
            free(ptr_ptr);
            return do_UPC_work(sptr);
        }
        
    Then C++ (or C) code would call produce_pointer() and 
    consume_pointer().  Without details of the control-flow in your app I 
    can't be more specific with the example, but hopefully you follow the 
    key idea here: UPC code moves the pointer in and out of malloc()ed 
    memory and C++ (or C or FORTRAN) code just moves around the opaque bytes 
    of the indicated length.
    
    -Paul
    
    Benjamin Byington wrote:
    > Hello:
    >
    > First, I'm new to both UPC and this mailing list, so please forgive me if my ignorance is showing:)
    >
    > I'm currently writing a mixed language program with UPC to handle the communication between processors.  (The rest being in C++)  Throughout program execution, I have various packets of data that are sitting around for later use, but it is not known in advance how long they will sit or even which processor will eventually need it.  As a result one of the processors maintains a data structure to orchestrate everything and keep track of all the little packets.  I would greatly prefer the data structure and the code manipulating it to be written in C++, but this structure would need to record pointers to the data packets.  I understand that C++ of course cannot use anything that uses the shared keyword anywhere, but I was hoping that somehow I could store the pointers to shared as 64 bytes of anonymous data.  Then my C++ code would be able to store and copy and eventually deliver it to an arbitrary thread, where some UPC could could then treat it like a shared pointer again a!
     nd!
    >   access the data.  Unfortunately I've not been able to do this, does anyone know of a way?
    >
    > Much thanks
    >
    > Ben Byington
    >
    >   
    
    
    -- 
    Paul H. Hargrove                          PHHargrove_at_lbl_dot_gov
    Future Technologies Group                 Tel: +1-510-495-2352
    HPC Research Department                   Fax: +1-510-486-6900
    Lawrence Berkeley National Laboratory     
    

  • Next message: James Dinan: "UDP Conduit Environment Issue"