pcxx_ug (1158314), страница 2
Текст из файла (страница 2)
Agood choice is /usr/local/src (if you are root) or your home directory (if you are auser).2. execute gzip -d -c <distribution>-*.tar.gz | tar xvf 3. From within the distribution directory, run the ./configure script. This will automatically modify the Makeles to include the correct libraries and/or compile agsfor your architecture. You can override the defaults with ./configure -cfront, or./configure -gnu. You may also choose compilers with ./configure -cc=cc -c++=CC.You may specify the architecture as the last parameter if ./configure cannot automatically determine it.3Please inform us if there are other modications required for your system. Running\./configure unknown" will return les to their original form.4.
make install At this point, simply running \make" will NOT work; \make install"is required. This will invoke a recursive make for each of the source subdirectories.If you are using a supported parallel machine, the machine specic runtime module willalso be compiled. ./TestSuite will also be compiled for uniprocessor simulation. See./TestSuite/README. If all went well, you should be ready to test the uniprocessorversion with \cd TestSuite; make test".5. Reprint this user manuals in ./doc (See the ./doc/README) because it may havechanged.6. You may \make clean" after you have installed the system to remove all the .o les,and really save on disk space. The libraries (*.a) and binaries will be preserved untilyou \make cleaninstall", which gets rid of everything but the source code.43 The pC++ Programming Language.3.1 Threads, Processors and Runtime Models Ver.
1.0+.We dene a thread of execution to mean an abstract \program counter", i.e. a mechanism toevaluate expressions and follow the control ow of a program, together with a name spaceof variables and code segments in an application. Without getting too technical, a threadrepresents the activity of one processor (or process) in a typical MP system. For example, ina conventional uniprocessor environment each program executes with only one thread i.e. theone that starts with the invocation of the main() function and sequentially steps throughthe code.
That thread can see and modify the global variables declared outside of main()and the variables on the procedure call stack as it executes.There are many dierent ways in which multiple threads can be used to speed the execution of a program. In a master/worker \multi-threaded" execution model, we use onecontrol thread, called the main, master, or scheduler, which starts with main() and a set of\worker" threads which help out on the parallel part of the program. It is the job of themaster to signal the workers where to begin execution and where to nd the data they shouldwork on.
This is accomplished by identifying loops in the program that can be executed inparallel and then distributing iterations to the worker threads as tasks. The rules for hownames spaces of variables and data interact between dierent threads vary from model tomodel. In some systems, there is a shared name space of variables and all threads can seeand modify these variables and, of course, suer the consequences when two threads try tomodify the same variable without proper synchronization.Another model is the Single Program Multiple Data, or SPMD mode of execution. Inthis case, a set of threads each start executing the program from the beginning and followit all the way through.
The only thing dierent in the execution from one thread to anotheris that dierent threads operate on dierent data sets and dierent subsets of the parallelloop iterations space. In the SPMD model it is assumed that the name spaces of variablesare all distinct. That is, if X is a name in a program then each thread sees a dierent X.Consequently, sequential work is duplicated but parallel work is shared and some sort ofcommunication protocol is used share information.In a pC++ program, there is a distinguished sequential main thread, invoked from afunction called Processor Main() (as it is called in Version 1.0. It will be known as main()in future versions).
This thread is the main control thread and it is the scheduler of paralleloperations. To dene additional computational resources beyond the main thread the pC++programmer creates processor objects, which dene a set of threads.Parallel tasks are dened in terms of threads that are associated with a processor objectwhich denes a set of threads and their bindings to processors, i.e. physical computingresources.One declares an array of processor objects with a statement of the formProcessors P(m,n)5This denes P to be a 2 dimensional array of \virtual processor objects", i.e.
executionthreads, of size m by n. In general, processor objects can be of any dimension of any size.However, there is a very serious and disappointing limit on what is possible for Version 1.0 ofpC++. As mentioned above, current compiler, operating system and hardware technologyonly allows one virtual processor object per physical object and this set of threads is declaredasProcessors P;The reason for this limitation is that on current distributed memory machines, there isno support for communication mechanisms that operate on anything other than a physicalprocess level.
In general, software multitasking or special hardware can allow more than onethread of execution per physical processor and future versions of pC++ will support thisextension.To make a thread operate in a C/C++ world, one also needs a way to dene programvariables that are visible to the threads as well as variable that may be modied by thatthread. Note that we make a distinction between variables that are visible and those thatcan be modied. Just as a const variable in C++ may be initialized and not modied, aglobal (le static) variable in a pC++ program can be seen and modied by the main thread,but only be seen by the processor objects.
In other words, if a variable is a global static orexternal variable for the main thread, it is a const variable for the processor object threads.The reasons for this limitation will be described later.In addition to rules for variable visibility for virtual processor objects, we need a way forthe main thread to identify and invoke sections of code for the worker threads to execute.This is accomplished through Thread Environment Classes.3.2 Thread Environment Classes. Ver. 2.0Thread Environment Classes are not directly supported at the user level in Version 1.0,Because they will be supported in 2.0 and because they are an important part of the runtimemodel, we discuss them here.Once one denes a set of processor threads, it is necessary to dene an execution environment for each thread.
In addition, one needs a mechanism to assign work to threads. Thisis accomplished with a Thread Environment Class which is a basic extension that pC++makes to C++.In its most basic form a Thread Environment Class denes a set of local variables for aprocessor object and a mechanism in which the main thread can start each thread executinga well dened unit of work.A thread environment class looks like an ordinary C++ class.
The syntax is identical toa standard C++ class, but with a dierent keyword.TEClass class_name: super_classes {member_data_definitions;6member_function_definitions;};A regular C++ class denes a data type that consists of a structure of data eld membersand member/method functions that have special privilege to read and modify these dataelds.
A TEClass is identical except that it denes a structure of data elds that are privateto each thread represented by a given Processor object. The invocation of member functionsof a TEClass object by the main control thread transfers control to the individual threadsfor the duration of the execution of that function.A TEClass is declared the same as any other class with the exception that When dened within the global name space of a program or allocated within the maincontrol thread, the constructor of a TEClass object must contain a processor objectas the last parameter. Upon invocation of this constructor, one copy of the membereld object is allocated to each processor object thread dened by the argument.
Thelifetime of these objects is determined by their life time in the control thread. If a TEClass object constructor is invoked by a thread of a processor object, it is invokedas a regular class constructor for that thread. In this case, one does not supply theProcessor parameter.
A call to a TEClass member function by the main program control thread representsa transfer of control to a parallel action on each of the threads associated with theobject. The main control thread is suspended until all the processor threads completethe execution of the member function. If the member function returns a value to themain control thread, it must return the same value from each PO thread or the resultis undened.