Introduction

A global pointer is a generalization of the C pointer type to support pointers to object that exist in other address spaces. It is closely linked to the idea of a global reference which is an object that is a proxy for a remote object.

In most ways, a global pointer can be treated exactly as a pointer to a local object. One major difference is that global pointers can only point to objects allocated from a special "global data area". In other words to allocate a global pointer object of type T from the global area one can write :

HPCxx_GlobalPtr<T> p(args);
    
or, for a global pointer to an array of 100 objects,
HPCxx_GlobalPtr<T> p[100]; 
    

For objects of simple type, a global pointer can be dereferenced like any other pointer. For example, assignment and copy through a global pointer is given by

HPCxx_GlobalPtr<float> p;
*p = 3.14;
float y = 2 - *p;
    

Integer arithmetic and the [] operator can be applied to global pointers in the same way as ordinary pointers. Because global pointer operations are far more expensive than regular pointer dereferencing, there are special operators for reading and writing blocks of data.

void HPCxx_GlobalPtr<T>::read(T *buffer, int size);
void HPCxx_GlobalPtr<T>::write(T *buffer, int size);
    

The most common way to obtain a global pointer to an object on a remote context is to invoke a global function which returns a global pointer as a result.

Objects of a user-defined type may be copied through a global pointer only if there are pack and unpack friend functions defined as follows. Suppose you have a class of the form shown below. You must also supply a special function that knows how to pack an array of such objects.

class C{
   int x;
   float y[100];
   public:
      friend void hpcxx_pack(HPCxx_Buffer *b, C *buffer, int size);
      friend void hpcxx_unpack(HPCxx_Buffer *b, C *buffer, int &size);
};

void hpcxx_pack(HPCxx_Buffer *b, C *buffer, int size){
   hpcxx_pack(b, size, 1);
   for(int i = 0; i < size; i++){
      hpcxx_pack(b, C[i].x, 1);
      hpcxx_pack(b, C[i].y, 100);
      }
}
void hpcxx_unpack(HPCxx_Buffer *b, C *buffer, int &size){
   hpcxx_unpack(b, size, 1);
   for(int i = 0; i < size; i++){
      hpcxx_unpack(b, C[i].x, 1);
      hpcxx_unpack(b, C[i].y, 100);
      }
}

    

These pack and unpack functions can be considered a type of remote constructor. For example, suppose a class object contains a pointer to a buffer in the local heap. It is possible to write the unpack function so that it allocates the appropriate storage on the remote context and initializes it with the appropriate data.

Unfortunately, it is not possible to access data members directly through global pointers without substantial compiler support. The following is an illegal operation

class D{
   public: 
   int x;
};
  ...
HPCxx_GlobalPtr<D> p;
  ...
p->x;   // illegal member reference
    

To solve this problem, we must create a data access function that returns this value. Then we can make a remote member call.


hpc++@extreme.indiana.edu

Last modified: Wed Apr 21 17:40:05 EST 1999