intrepid.com



UPC Frequently Asked Questions

Posted on Tue, 2006-02-28 00:34
  1. How do I specify the value of THREADS (statically) at compile time?
  2. How do I specify the value of THREADS (dynamically) at runtime?
  3. GCC UPC reports parse errors in upc.h file?
  4. How do I compile UPC source files that end with a .c extension?
  5. I tried to link my UPC program, and the link failed with some unusual error messages, including "unterminated string or character constant".
  6. My program runs fine but terminates with the message "conflicting exit status ...". What happened?
  7. My program printed the message, "UPC Warning: There are no UPC source files compiled into this program, or <upc.h> was not included?�
  8. My program terminates with the message "UPC error: Invalid conversion of shared address to local pointer. Thread does not have affinity to shared address.�

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 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-threads, and passes the remaining arguments to your application's main program. The following example, shows how this is done:



% cat > dynamic.upc << EOF
? #include
? #include
? main ()
? {
? if (MYTHREAD == 0)
? printf ("There are %d UPC threads\n", THREADS);
? return 0;
? }
? EOF
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

GCC UPC reports parse errors in upc.h file

You must have the source file with extension .c. GNU GCC has many languages supported (e.g. C,C++,OBJC,..) and all of them can be built from the same source tree. UPC follows the GCC standard where compiler specific features are invoked based on the source file extension. Compiling a file with .c extension invokes regular C compiler that does not understand UPC specific language extensions.

How do I compile UPC source files that end with a .c extension?

By default, source files ending with a .upc extension are recognized as UPC source files. To compile files that end with some other extension use the -x upc switch. For example,



% upc -x upc src.c -o pgm

I tried to link my UPC program, and the link failed with some unusual error messages, including "unterminated string or character constant". What happened?

It is likely the case that you inadvertently supplied the -x upc switch on the command line. The -x upc switch tells the UPC compiler to treat all filenames on the command line as if they are UPC source files; the compiler does not attempt to determine a file's type based on its file's extension. Thus, the following sequence of commands will fail on the final step where the user intended to link the application's object files.



% upc -x upc -c main.c f1.c f2.c
% upc -x upc main.o f1.o f2.o -o pgm
main.o:1: unterminated string or character constant
main.o:1: possible real start of unterminated constant
f1.o:1: unterminated string or character constant
f1.o:1: possible real start of unterminated constant
f2.o:1: unterminated string or character constant
f2.o:1: possible real start of unterminated constant

The problem is easily corrected by omitting the -x upc switch from the command line when linking the program



% upc main.o f1.o f2.o -o pgm

My program runs fine but terminates with the message "conflicting exit status ...". What happened?

It is likely that your UPC main() program does not terminate with either an explicit return statement or a call to exit(). The UPC runtime library makes a special check when each thread terminates to ensure that all threads terminate with the same exit value. If all threads do not exit with the same value, then the runtime library will print one or more "conflicting exit status" messages. The following example illustrates a situation where each main program terminates with whatever value happens to be in the register used for the function return value. Each thread will terminate with a different value. The runtime notices that the return values are different and prints an error diagnostic.



% cat > retcode.upc << EOF
? #include <upc.h>
? f() { return MYTHREAD; }
? main()
? {
? int i;
? i = f ();
? }
? EOF
% upc -O0 retcode.upc -o retcode
% retcode -fupc-threads-3
conflicting exit status (0) for thread 0
conflicting exit status (1) for thread 1

The fix is to make sure that all threads terminate with the same value by adding an explicit call to exit():



% cat retcode.upc
#clude
f() { return MHREAD; }
main()
{
int i;
i = f ();
exit (0);
}
% upc -O0 retcode.upc -o retcode
% retcode -fupc-threads-3
% echo $status

My program printed the message, "UPC Warning: There are no UPC source files compiled into this program, or <upc.h> was not included?� What do I do to get rid of this warning?

It is likely that you have either (1) asked the UPC compiler to compile and link only pure C language source files, or (2) you have forgotten to include either <upc.h>, <upc_strict.h>, or <upc_relaxed.h> in your UPC source files. Often, this omission will be discovered at compile-time, when your program attempts to make references to THREADS or MYTHREAD, however very simple programs might slip through the compilation step, and the omission is not detected until the program is executed. Here is an example,



% cat > empty.upc << EOF
? main()
? {
? return 0;
? }
? EOF
% upc empty.upc -o empty
% empty -fupc-threads-4
empty: UPC Warning: There are no UPC source files compiled into this
program, or was not included?

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 does this mean?

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>
shared int v[THREADS];
main ()
{
int *vp;
v[MYTHREAD] = MYTHREAD;
upc_barrier;
vp = (int *)&v[0];
if (MYTHREAD == 0)
printf ("v[0] = %d\n", *vp);
return 0;
}
% 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 1 terminated with 'Abort' signal
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>
shared int v[THREADS];
main ()
{
v[MYTHREAD] = MYTHREAD;
upc_barrier;
if (MYTHREAD == 0)
{
int *vp = (int *)&v[0];
printf ("v[0] = %d\n", *vp);
}
return 0;
}
% upc -fupc-threads-4 goodptr.upc -o goodptr
% goodptr
v[0] = 0

 

login to post comments