Published on intrepid.com (http://www.intrepid.com)

UPC Frequently Asked Questions

  1. How do I specify the value of THREADS (statically)at compile time? [0]
  2. How do I specify the value of THREADS (dynamically) at runtime? [0]
  3. 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?
    [0]

How do I specify the value of THREADS (statically) at compile time?

The -fupc-threads-n switch specifies the number of threads to be created. For example, the following command tells the UPC compiler to use a value of 32 for the value of THREADS, when compiling the source file src.upc,

% upc -fupc-threads-32 src.upc

NOTE: The same value of n must be specified for all UPC source files compiled into a given application.

How do I specify the value of THREADS (dynamically) at runtime?

First do not compile any of the UPC source files in your application with a compile-time specified value. Then, at runtime, provide the -fupc-threads-n option on the command line, just after the executable program's file name. The UPC runtime strips off all of the initial command line arguments that begin with the prefix -fupc-, and passes the remaining arguments to your application's main program. The following example, shows how this is done:

% cat dynamic.upc
#include <upc.h>
#include <stdio.h>

int
main ()
{
if (MYTHREAD == 0)
printf ("There are %d UPC threads.\n", THREADS);
}
SGI/x86
% upc dynamic.upc -o dynamic
% dynamic -fupc-threads-7
There are 7 UPC threads.
CRAY
% upc dynamic.upc -o dynamic
% mpprun -n 2 ./dynamic
There are 2 UPC threads.

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 <upc.h>
#include <stdio.h>

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 <upc.h>
#include <stdio.h>

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


Source URL:
http://www.intrepid.com/upc/faq.html