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

📄 p4.txt

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 TXT
📖 第 1 页 / 共 5 页
字号:
  VOID p4_cluster_shmem_sync(cluster_shmem) VOID **cluster_shmem; This routine is used to synchronize the processes in a cluster before theybegin to use shared memory.   VOID p4_get_cluster_masters(numids, ids) int *numids, ids[]; This procedure fills in the values of numids and ids. It obtains thep4-id's of all ``cluster masters'' for the program, placing them in the ids array and placing the number of id's in numids. Functions for Message Passing*****************************P4 supports a set of send/receive procedures. These procedures are``generic'' in the sense that they do not know whether a message musttravel across a network or through shared memory, or via some othermechanism. They depend on a lower-level set of procedures that handlelocal or network (remote) communications. By default, the messages areassumed to be typed. If the user wishes to use untyped messages, he canhide the typing by coding some very simple C macros that always use asingle message type. Explicit Sending and Receiving of Messages==========================================p4_send(type,to,msg,len) p4_sendr(type,to,msg,len) p4_sendx(type,to,msg,len,datatype) p4_sendrx(type,to,msg,len,datatype) p4_sendb(type,to,msg,len) p4_sendbr(type,to,msg,len) p4_sendbx(type,to,msg,len,datatype) p4_sendbrx(type,to,msg,len,datatype) int type, to, len, datatype; char *msg; Each of these procedures sends a message. The type argument is aninteger value chosen by the user to represent a message type. The toargument is an integer value that specifies the p4-id of the process thatshould receive the message. The len argument contains the length inbytes of the message to be passed. Note that some of the procedures havea ``b'' in their name, e.g. p4_sendb. These procedures assume that themsg is in a buffer that the user obtained earlier via a p4_msg_alloc;otherwise, the buffer is assumed to be in the user's local space, and maycause the message to be copied internally. The procedures with an ``r'' inthe name do not return until an acknowledgement is received from the toprocess (the ``r'' stands for rendezvous). Those procedures with an ``x'' inthe name take an extra argument (datatype) that specifies the type of datain the message; these procedures will use that information to call XDRfor data conversion if the message is being passed to a machine of adifferent architecture, i.e. where the internal representation may bedifferent. The valid values for the datatype parameter are P4INT, P4DBL, P4FLT, P4LNG, and P4NOX. The last of these means ``notranslation''.   BOOL p4_messages_available(req_type,req_from) int *req_type,*req_from; returns a BOOL value indicating whether the process has any messagesavailable or not. The parameters req_type and req_from are bothpointers to integers; they are used as both input and output arguments. Oninput, req_type has a value that indicates the type of message that theuser wishes to check for availability (-1 indicates any type). The variable req_from is used similarly to indicate who a message is desired from.   int p4_recv(req_type,req_from,msg,len_rcvd) int *req_type,*req_from,*len_rcvd; char **msg; takes four arguments. The msg argument is a pointer to a pointer to a char. If this value is NULL, then p4 will allocate the buffer for themessage according to its length. That is, one need not know ahead of timethe length of a message being received. If this value is not NULL, then itpoints to a p4 message buffer that the user has obtained via p4_msg_alloc. The len_rcvd argument is a pointer to an integerthat is assigned the length of the received message. Req_type and req_from are both pointers to integers; they are used as both input andarguments. On input, req_type has a value that indicates the type ofmessage that the user wishes to receive (-1 indicates any type). It willblock until a message of that type is available. Req_from is usedsimilarly to indicate who a message is desired from. One important noteabout this procedure is that it obtains the area in which to place amessage, and the user must explicitly free that area when finished with it(see p4_msg_free). There is an option available with p4_recv inwhich the user can provide his own buffer rather than having p4 allocateit. To do this, the user points msg to a buffer that he must obtain via acall to p4_msg_alloc (see below). No p4_msg_free should beperformed if the same buffer is going to be re-used multiple times.   char *p4_msg_alloc(len) int len;   VOID p4_msg_free(m) char *m; obtain and free a buffer area that can be used to receive a message. Thisprocedure should be used for this task because a message has hiddeninformation which the user is unaware of and therefore should not use malloc to obtain the area. Global Operations=================P4 supports a number of operations for dealing with all processes at once.  p4_broadcast(type, data, data_len) int type; char *data; int data_len;   p4_broadcastx(type, data, data_len, data_type) int type; char *data; int data_len, data_type; provide the ability to broadcast messages like p4_send and p4_sendx.These are semantically equivalent to a loop which uses p4_send or p4_sendx to individually send a message to each other process (thesender is not included.) Messages sent by one of these broadcasts arereceived by normal p4_recv's. The implementation of p4_broadcast is more efficient than such a loop, since it uses a``broadcast tree''. One situation to look out for is a normal p4_broadcast followed by a p4_send. It is possible for the firstmessage to arrive at its destination after the second one. The order ofmessages in this situation can be enforced with the use of the typeargument.   p4_global_op(type,x,nelem,size,op,data_type)  int type; char *x; int size, nelem; int (*op)(); int data_type; where op is one of:   p4_int_absmax_op() p4_int_absmin_op() p4_int_max_op() p4_int_min_op() p4_int_mult_op() p4_int_sum_op() p4_dbl_absmax_op() p4_dbl_absmin_op() p4_dbl_max_op() p4_dbl_min_op() p4_dbl_mult_op() p4_dbl_sum_op() p4_flt_absmax_op() p4_flt_absmin_op() p4_flt_max_op() p4_flt_min_op() p4_flt_mult_op() p4_flt_sum_op() and data_type is one of P4INT, P4LNG, P4FLT, or P4DBL. This collection of routines provide the ability to do a variety of globaloperations. See the example program p4/messages/systest.c. They applythe commutative and associative operation op globally to x on anelement-by-element basis and broadcast the result to all nodes. That is,each process ends up with      for (i=0; i<n; i++)          x[i] = x[node 0][i] op x[node 1][i] op x[node 2][i] op ... op should be of the form        VOID op(char *x, char *y, int nelem)      {          data_type *a = (data_type *) x;          data_type *b = (data_type *) y; while (nelem--)              *a++ operation= *b++;      } where data_type and operation are chosen appropriately. The order in which nodes apply the operation is undefined (hence opmust be commutative and associative). The communication may beinternally sub-blocked so the function op should not be hardwired tospecific vector lengths. This is still a relatively primitive version, which gathers the necessarydata up a balanced binary tree and then uses p4_broadcast to send theresults back. The type argument specifies the message type to be used inthe communication associated with this global operation. Strictly speaking, the size parameter, which is size in bytes of oneelement, is unnecessary. It is retained for backward compatibility.   VOID p4_global_barrier(type) int type; This procedure takes one argument which is the message type to be usedfor internal message-passing. It causes the invoking process to hang untilall processes specified in the procgroup file have invoked the procedure. Functions for Shared Memory***************************Here is a simple example of a shared-memory program using monitors.In this program, each process retrieves values from a shared loop index. Amonitor is used to ensure that all values are retrieved exactly once.   #include "p4.h" struct globmem {     p4_getsub_monitor_t getsub; } *glob; main(argc,argv) int  argc; char **argv; {     p4_initenv(&argc,argv); glob = (struct globmem *) p4_shmalloc(sizeof(struct globmem));     p4_getsub_init(&(glob->getsub)); p4_create_procgroup();     worker();     p4_wait_for_end(); } worker() {     int i, nprocs; nprocs = p4_num_total_ids();     i = 0;     while (i >= 0)     {         p4_getsub(&(glob->getsub),&i,10,nprocs);         p4_dprintf("I got %d\n",i);     } } Managing Shared and Local Memory================================The following functions are just basic memory management routines.   char *p4_malloc(n) int n; typically acts like the standard malloc, but may be rewritten for usersystems that require different operation.   VOID p4_free(p) char *p; typically acts like the standard free, but may be rewritten for usersystems that require different operation.   char *p4_shmalloc(n) int n; acts like the standard malloc except will obtain shared memory onmachines that support sharing memory among processes. Compare with p4_malloc.   VOID p4_shfree(p) char *p; frees memory obtained with p4_shmalloc. Compare with p4_free. Shared Memory Data Types========================The abstraction provided by p4 for managing data in shared memory is monitors. Good places to learn about the monitor concept in general are[(ref pbh:architecture)] and [(ref hoare:monitors)]. The specific approachtaken by p4 is described in [(ref lusk-overbeek:p4-book)]. P4 providesseveral useful monitors (p4_barrier_t, p4_getsub_monitor_t,p4_askfor_monitor_t) as well as a general monitor type to helpthe user in constructing his own monitors (p4_monitor_t). Monitor-Building Primitives===========================The following functions can be used to construct monitors. A monitor soconstructed has the type p4_monitor_t.   int p4_moninit(m,i) p4_monitor_t *m; int i; initializes the monitor pointed to by m and gives it i queues for processesto wait on while they are blocked (see p4_mdelay). One queue issufficient for most purposes. The queues are numbered beginning with 0.   VOID p4_menter(m) p4_monitor_t *m; enter the monitor pointed to by m. By the definition of a monitor, accessis restricted to a single process in the monitor at a time (if everybodyplays by the rules).   VOID p4_mexit(m) p4_monitor_t *m; exits the monitor pointed to by m. You are of course assumed to havepreviously entered that monitor.   VOID p4_mcontinue(m,i) p4_monitor_t *m; int i; checks to see if there are any processes blocked on the i-th queue of themonitor m and causes one of them to be released for entry to the monitorif so. If there are no such processes, the invoking process simply exits.Note that a process could have been blocked previously by invoking theprocedure p4_mdelay. The queues are numbered beginning with 0.   VOID p4_mdelay(m,i) p4_monitor_t *m; int i; permits a process to delay itself on the i-th queue of monitor m if theprocess wishes to release the monitor, but wants to be waked up byanother process later (via the procedure p4_mcontinue). The queuesare numbered beginning with 0. 

⌨️ 快捷键说明

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