![]() |
![]()
| ![]() |
![]()
NAMEpvm_reduce - Performs a reduction operation over members of the specified group. SYNOPSISC int info = pvm_reduce( void (*func)(),
Fortran call pvmfreduce(func, data, count, datatype,
PARAMETERS
DESCRIPTIONpvm_reduce() performs global operations such as max, min, sum, or a user provided operation on the data provided by the members of a group. All group members call pvm_reduce with the same size local data array which may contain one or more entries. The root task is identified by its instance number in the group. The inner workings of the pvm_reduce call are implementation dependent; however, when the pvm_reduce call completes, the root's data array will be equal to the specified operation applied element-wise to the data arrays of all the group members. A broadcast by the root can be used if the other members of the group need the resultant value(s). PVM supplies the following predefined functions that can be specified in func.
PvmMax and PvmMin are implemented for all the datatypes listed below. For complex values the minimum [maximum] is that complex pair with the minimum [maximum] modulus. PvmSum and PvmProduct are implemented for all the datatypes listed below with the exception of PVM_BYTE and BYTE1. C and Fortran defined datatypes are:
A user defined function may be used in func. The argument func is a function with four arguments. It is the base function used for the reduction operation. Both x and y are arrays of type specified by datatype with num entries. The arguments datatype and info are as specified above. The arguments x and num correspond to data and count above. The argument y contains received values. Caveat: pvm_reduce() does not block, a call to pvm_barrier may be necessary. For example, an error may occur if a task calls pvm_reduce and then leaves the group before the root has completed its call to pvm_reduce. Similarly, an error may occur if a task joins the group after the root has issued its call to pvm_reduce. Synchronization of the tasks (such as a call to pvm_barrier) was not included within the pvm_reduce implementation since this overhead is unnecessary in many user codes (which may already synchronize the tasks for other purposes). The current algorithm is very simple and robust. A future implementation may make more efficient use of the architecture to allow greater parallelism. ILLUSTRATIONThe following example illustrates a call to pvm_reduce. Suppose you have three group members (instance numbers 0, 1, 2) with an array called Idata with 5 values as specified:
And, suppose that a call to reduce (such as the ones following) are issued where the root is the group member with instance value of 1:
Then, upon completion of the reduce call, the following will result:
EXAMPLESC: ERRORSThese error conditions can be returned by pvm_reduce
SEE ALSOpvm_bcast(3PVM), pvm_barrier(3PVM), pvm_psend(3PVM)
|