⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p4.txt

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 TXT
📖 第 1 页 / 共 5 页
字号:
   unix man page for the Fortran interface to p4 fiber   status of the work on direct fiber channel The Postscript version of this manual is available by anonymous ftpfrom info.mcs.anl.gov, in the directory pub/p4. The file to get (inbinary mode) is p4-manual.ps.Z. There is also a paper there giving anoverview of p4, in p4-paper.ps.Z. This manual is also available throughthe World Wide Web at http://www.mcs.anl.gov/home/lusk/p4/p4-manual/p4.html.Examples included with the Distribution=======================================A good way to see how various p4 functions are used is to look at theexample programs included in the distribution. The p4/monitors directorycontains shared-memory examples written in C that use monitors,including one instrumented with ALOG. The p4/messages subdirectorycontains message-passing examples written in C. The programs in p4/messages_f are Fortran message-passing examples, and the p4/contriband p4/contrib_f directories contain a number of miscellaneous examplescontributed by users. In each directory there is a README that describesthe individual examples. Getting Started***************The easiest way to get started with p4 is to play with some of the sampleprograms provided with the system. A Message-Passing Example=========================We will begin with a message-passing example in the sub-directorynamed p4/messages. The code for the program is in the files sr_test.c and sr_user.h. Program Description===================As the name implies, this program is an example of p4's send/receivefunctionality. Briefly, it is a simple program that runs a master processand some slave processes. The master and the set of slaves form a ring ofprocesses in which the master reads a message from stdin and sends acopy of the message to the first slave, which passes it on; the last slavepasses the message back to the master. If the master receives anundamaged copy of the message, it assumes that all went well, and readsanother message. Note that the ring of processes is a logical structure inwhich each process assumes that its predecessor in the ring is the processwith the next lower id, and its successor is the process with the nexthigher id. The master has id 0 (zero) and has the process with the largestid as its predecessor. Analysis of the Program=======================The first executable p4 statement in a program should be:   p4_initenv(&argc,argv);  This initializes the p4 system and allows p4 to extract any command linearguments passed to it, e.g. debugging parameters. Similarly, the last executable p4 statement in a program should be:   p4_wait_for_end();  This waits for termination of p4 processes and performs some cleanupoperations. The procedure p4_get_my_id returns the unique integer id assigned tothe calling process by p4. The statement:   p4_create_procgroup(); reads a procgroup file that the user builds and creates the set of slavesdescribed in that file. Obviously this statement must be executed beforeany slaves can be assumed to exist. This procedure is the method you mustuse to create processes that do message-passing. The procedure p4_clock returns an integer that represents wall-clocktime in milliseconds. It is typically used to retrieve the time before andafter some work, the difference representing the time to do that work.Note that there is also a p4_ustimer that is useful on those machinesthat support a microsecond timer. The procedures p4_send and p4_sendr are two of several p4procedures that are available for sending messages to other processes.They take as arguments the message type, the id of the "to" process, theaddress of the message, and the message length. The procedure p4_recv receives a message from another process andsets the values of all four parameters. P4_recv will automaticallyretrieve a buffer in which to place a received message, thus p4_msg_free may be called to free that buffer when it is no longerneeded. The procedure p4_num_total_slaves is one of several proceduresthat the user can invoke to determine information about the currentexecution. To run this program, you need to create a procgroup file that describeswhere all slave processes are to be executed (See section SpecifyingProcesses in the Procgroup File). We will assume that you have anexample procgroup file (named sr_test.pg) in the p4/messages directory,and can run sr_test by merely typing:   sr_test If the procgroup file is elsewhere, then you must type:   sr_test -pg   pathname_of_procgroup_file Another example that is made by default is the program systest. Ittests a number of the message-passing features of p4. Specifying Processes in the Procgroup File******************************************The procgroup file is the only portion of the interface that is very likelyto change through multiple versions of p4. As new architectures aresupported, it is hoped that we can merely alter the procgroup file formatto reflect any new features. (Of course new procedure calls may also berequired, but existing procedure calls will remain unchanged whenpossible). See See section Running p4 on Specific Machines for adiscussion of machine dependencies in starting p4 programs. The current format of a procgroup file is as follows:   local_machine  n [full_path_name] [loginname] remote_machine n full_path_name [loginname]   .   .   . In some situations, the program is started via some special commandexecuted from the host machine. In such cases, the procgroup file namecan be specified to the special command line along with the programname (see for example the runcube and rundelta shell scripts in the p4/messages subdirectory). In those cases where no special command isrequired, no special handling is required for the procgroup filename. The first line of a procgroup file may be ``local n'' where n is the numberof slave processes that share memory with the master. The full path nameon the ``local'' line is ignored on machines other than cube and meshmachines, and the IBM SP-1. The word ``local'' may be replaced by analias for the local machine if needed, to specify an alternative transportlayer. The subsequent lines contain either three or four fields:    1. the name of a remote machine on which slave processes are to   be created.    2. the number of slaves that are to be created on that machine, i.e.   be in the same cluster (note that on machines that support it, the   processes in a cluster will share memory)    3. the full path name of the executable slave program    4. optionally, the user login name on the remote machine, if   different from that on the host machine. As an example, let's assume that you have a network of three Sunworkstations named sun1, sun2, and sun3. We will also assume that youare working on sun1 and plan to run a master process there. If you wouldlike to run one process on each of the other Suns, then you might code aprocgroup file that looks like:       # start one slave on each of sun2 and sun3     local 0      sun2  1  /home/mylogin/p4pgms/sr_test     sun3  1  /home/mylogin/p4pgms/sr_test Lines beginning with # are comments. It is also possible to have different executables on different machines.This is required, of course, when the machines don't share files or are ofdifferent architectures. An example of such a procgroup file would be:       local   0     sun2    1  /home/user/p4pgms/sun/prog1     sun3    1  /home/user/p4pgms/sun/prog2     rs6000  1  /home/user/p4pgms/rs6000/prog1 On a shared memory machine such as a KSR, in which you want all theprocesses to communicate through shared memory using monitors, theprocgroup file can be as simple as:       local 50 On the CM-5, your procgroup file would look like:       local 32 /home/joe/p4progs/cm5/multiply Next, let's assume that you have a Sequent Symmetry (named symm) andan Encore Multimax (named mmax). We will also assume that you areworking on symm, and plan to run the master there. If you would like torun two processes on symm (in addition to the master) and two on mmax,then you might code a procgroup file that looks like:       local 2      mmax  2  /mmaxfs/mylogin/p4pgms/sr_test P4 also permits you to treat the symmetry as a remote machine even whenyou are running the master there. Thus, you might code a procgroup fileas follows:       local 2      symm  2  /symmfs/mylogin/p4pgms/sr_test     mmax  2  /mmaxfs/mylogin/p4pgms/sr_test In this example, there are seven processes running. Five of the processesare on symm, including the master. Two of the processes on symm are inthe master's procgroup and two are running in a separate procgroup as ifthey were on a separate machine. Of course, the last two are running onmmax. Finally, suppose that you have a fiber-channel network that parallels yourEthernet, connecting the same machines, and that connections fro runningTCP/IP over the fiber-channel network are obtained by connecting to sun1-fc, sun2-fc, etc. Then even if sun1 is the local machine thatyou are logged into, you will want your procgroup file to look like:       sun1-fc    0     sun2-fc    1  /home/user/p4pgms/sun/prog1     sun3-fc    1  /home/user/p4pgms/sun/prog2 Some notes about the contents of the procgroup file should be made atthis point. First, the value of n on the local line can be zero, i.e. themaster may have no local slaves. Second, the local machine may betreated as if it is a remote machine by merely entering it in some line as aremote machine. Third, a single machine may be treated as multipleremote machines by having the same remote machine name entered onmultiple lines in the procgroup file. Fourth, if a single machine is listedmultiple times, those processes specified on each line form a singlecluster (share memory). Fifth, the cluster size specified for a uniprocessorshould be 1, because all slaves in a cluster are assumed to run in paralleland to share memory. We refer to the original (master) process as the ``big master''. The firstprocess created in each cluster is the ``remote master'' or the ``clustermaster'' for that cluster. All p4-managed processes (see the procedure p4_create_procgroup) have unique integer id's beginning with 0.The processes within a cluster are numbered consecutively. Developing a Simple p4 Program******************************The real fun associated with any computing environment arrives whenyou actually type in a program and run it yourself. We will assume thatyou have successfully installed p4 on your own system and are ready towrite a small program, compile it, and run it. A Minimal Example=================We will start with a tiny program in which the worker processes do nowork, and then expand its capabilities. Edit a file called p4simple.c andtype:   #include "p4.h" main(argc,argv)     int argc;     char **argv;     {         p4_initenv(&argc,argv);         p4_create_procgroup();         worker();         p4_wait_for_end();     } worker()     {         printf("Hello from %d\n",p4_get_my_id());     } This is one of the simplest p4 programs that you can write. Let's examineit. The #include "p4.h" statement must appear in all programs thatuse any p4 features. The procedure p4_initenv must be invokedbefore any other p4 procedures, and p4_wait_for_end must beinvoked after all p4 processing is completed. The p4_get_my_idreturns a unique integer id for each process, beginning with 0. Theprocedure p4_create_procgroup is responsible for creating allprocesses other than 0. It has no effect if called by any other processesthan process 0. The way in which p4_create_procgroupdetermines how many other processes there should be, and where theyshould run, will be discussed shortly. All processes that this program executes invoke the worker procedure,including process 0. Thus, in this program, the master process acts justlike all other processes once it gets the environment established. To understand how things get started, let's consider two separatesituations. In the first situation, all processes are running on a singlemachine. Then, when process 0 starts, it executes the p4_create_procgroup procedure to start all other slaves. The otherslaves are started on the same machine by means of a UNIX fork. In the second situation, there may be slaves running both on the samemachine as process 0, and slaves running on other machines as well. Inthis situation, the first slave running on a remote machine will need toexecute the main procedure. It will discover that it is not process 0.However, as part of initialization, process 0 will direct it to fork anyadditional slaves required on the same machine. In some ways, the above example can be used as a prototype for all p4programs, just by varying the content of the worker routine. A Minimal Example in Fortran============================Here is a Fortrran version of the program we just discussed.         program p4simple       include 'p4f.h' call p4init()       call p4crpg()       call fworker()       call p4cleanup()       stop       end subroutine fworker()       include 'p4f.h'       integer*4 procid procid = p4myid()       print *,'Hello from ',procid end A More Complicated Example==========================Now, let's make the worker process a little bit more interesting. Let'sassume that we have nprocs slaves with ids 0, 1, 2, ... nprocs -1.And, we want to write a program in which every process sends a singlemessage to every other slave, and then receives a message from everyother slave. We might alter the code for the worker procedure to be thefollowing:       worker()     {         char *incoming, *msg = "hello"; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -