GNU UPC

... Unified Parallel C

  • Full Screen
  • Wide Screen
  • Narrow Screen
  • Increase font size
  • Default font size
  • Decrease font size

My program terminates with the message  My program terminates with the message "UPC error: Invalid conversion of shared address to local pointer. Thread does not have affinity to shared address." What caused this error?


Any attempt to cast a shared pointer to a local per-thread pointer is considered erroneous if the thread component of the shared pointer does not equal the thread number of the referencing thread. This error can arise, even though the program doesn't try to dereference the invalid local pointer. The following example illustrates this situation.

% cat badptr.upc
#include
#include

shared int v[THREADS];

int
main ()
{
int *vp;
v[MYTHREAD] = MYTHREAD;
upc_barrier;
vp = (int *) &v[0];
if (MYTHREAD == 0)
printf ("v[0] = %d\n", *vp);
}
% upc -fupc-threads-4 badptr.upc -o badptr
% badptr
badptr: UPC error: Invalid conversion of shared address to local pointer.
Thread does not have affinity to shared address.
v[0] = 0
thread 3 terminated with signal: 'Aborted' Terminated

The error can be corrected by ensuring that the pointer conversion is made only in a valid context.

% cat goodptr.upc
#include
#include

shared int v[THREADS];

int
main ()
{
v[MYTHREAD] = MYTHREAD;
upc_barrier;
if (MYTHREAD == 0)
{
int *vp = (int *) &v[0];
printf ("v[0] = %d\n", *vp);
}
}
% upc -fupc-threads-4 goodptr.upc -o goodptr
% goodptr
v[0] = 0
Article is in the following categories:
KB » Usage of GNU UPC



Email This Article

or close

You are here: