You use the following suffixes to indicate the size in bytes. If you do not use the suffixes, the
size is specified by byte. For example, XLPGASOPTS=stacksize=200_000 specifies that the
space allocated to the stack used by a thread is at least 200,000 bytes:
kb (1 kb represents 1024 bytes)
mb (1 mb represents 1024 kb)
gb (1 gb represents 1024 mb)
tb (1 tb represents 1024 gb)
The suffixes are not case-sensitive. The letter b is optional and is omitted in the suffixes. For
example, XLPGASOPTS=STACKSIZE=10Mb is equivalent to
XLPGASOPTS=stacksize=10m.
You also use the suffixes percent and % to indicate a percentage. For example, the following
commands have the same effect:
XLPGASOPTS=stackcheck=20
XLPGASOPTS=stackcheck=20%
XLPGASOPTS=stackcheck=20percent
You specify stack size in hexadecimal format with the prefix 0x. For example,
XLPGASOPTS=stacksize=0x800kb is equivalent to XLPGASOPTS=stacksize=2mb.
Compiling and running an example program
This section provides a simple UPC program, the commands to compile and execute the
program, and the program output.
In Example 2-8 (hello.upc), each thread prints a message to standard output.
Example 2-8 hello.upc
# include <upc.h>
# include <stdio.h>
int main()
{
printf("Hello world! (THREAD %d of %d THREADS)\n", MYTHREAD, THREADS);
return 0;
}
Use the following command to compile the program in the static environment targeting four
threads:
xlupc -o hello -qupc=threads=4 hello.upc
The compiler compiles the code and generates an executable file, hello. To run the
executable program, you use the following command:
poe ./hello -hostfile hosts -procs 1 -msg_api 'pgas'
In this command, -procs specifies the number of processes to use. The program prints to
standard output a message on each thread, as shown in Example 2-9.
Example 2-9 Output of hello.upc
Hello world! (THREAD 3 of 4 THREADS)
Hello world! (THREAD 1 of 4 THREADS)
Hello world! (THREAD 0 of 4 THREADS)
Hello world! (THREAD 2 of 4 THREADS)
Chapter 2. Application integration
115