| United States-English |
|
|
|
![]() |
Parallel Programming Guide for HP-UX Systems > Chapter 5 UPCRunning |
|
You can run UPC programs in one of three ways:
If a UPC program has been compiled with -fthreads set to 1, or without having specified a value for -fthreads , then it may be run in single thread mode by simply executing the program image directly, as with any normal UNIX program. Single thread mode is useful for basic testing and debugging of UPC programs. Single thread mode can be used on HP-UX or on Tru64 Unix Version 5.1 or later systems; the AlphaServer SC software is not needed. The prun (parallel run) command is included as part of the the software provided with the AlphaServer SC system, and provides access to the Resource Management Services (RMS) databases and system management services. For detailed information on the prun command, refer to the reference page for prun and the RMS User Manual, provided with the AlphaServer SC software documentation. This command runs the executable program upc_loadtest3 in the default parallel partition, using four threads, on four CPUs. All prun options can be used to run UPC programs on whatever configuration of CPUs and Nodes are desired. Output from each thread's stdout is buffered and displayed at the terminal where the prun is executed. Diagnostics output to stderr is not buffered---it is sent immediately and displayed at the same terminal. If any inconsistencies are found, the UPCRTS issues a diagnostic message describing the problem and exits before running the main function. (Inconsistencies are found in such areas as: the declaration of a shared array in different modules; the value specified for -fthreads in different modules; the value specified for -fthreads and the value used for the -n option to the prun command.) If this happens, you need to modify one or more modules to correct the consistency problem, recompile one or more modules with a consistent value for -fthreads , and reissue the prun command with -n value consistent with the value used for -fthreads . If all modules compile successfully without specifying -fthreads , then any value for the -n option of prun may be used. HP UPC provides its own job control mechanism for SMP machines that do not have Quadrics RMS software, or as an alternative to Quadrics RMS software for jobs that can run on a single SMP node. This job control mechanism is called the UPC Run-Time Environment (RTE) and comprises the UPC job control daemon (upcrund) and the upcrun command. For a program to run on an SMP system (where all processors share the same physical memory), the shared data must be made visible to all threads. To do this, use the -smp_local or the -smp compiler option. The -smp option provides better performance. Note that you can include the desired option in the comp.config file (see Section 3.6). On HP-UX, the default is to run in SMP mode. It is not necessary to specify the -smp option Each UPC thread is a separate process. Input/output operations on files are exactly the same as the case where multiple programs access the same files, and should be programmed accordingly. Regarding stdin and stdout , unless program file input and output is confined to a single thread (for example, using an if (MYTHREAD == 0) test), then some means of partitioning the file activity into separate streams, one for each thread, is needed to produce coherent program behavior. Example 5-2 “Partitioning I/O from stdin and stdout” below illustrates a method of partitioning input from stdin from several specially-named files, one for each thread. It does this by running the UPC program as a command to the shell (the Bourne shell in the example) and making use of the environment variable RMS_PROCID . This environment variable is set for each thread to its thread number, and is the equivalent to MYTHREAD inside the UPC program. (When using the UPC Run Time Environment, the equivalent environment variable is UPC_PEER_PID.) The same technique is then used to redirect output. The shell -c option indicates that what follows is a command string; single quotes then delimit the command. Example 5-2 Partitioning I/O from stdin and stdout prun -n 4 sh -c ‘myprogram < inputfile.$RMS_PROCID’ Example 5-3 “Partitioning Output Streams” below illustrates a method to partition output files into separate streams, one for each thread, under program control. A given file name is appended with the thread number, and a separate output file is opened for each thread. A similar approach could also be used for input files. Note that the fopen function calls occur in parallel, one on each thread. Example 5-3 Partitioning Output Streams #include <stdio.h> The -t option to the prun command causes the output lines from each thread to be prefixed with the thread number when the output lines are sent to the terminal. Note that this will not happen when the output lines from each thread are redirected to separate files. |
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||