source: proiecte/hpl/openmpi_compiled/share/man/man3/MPI_Op_create.3 @ 97

Last change on this file since 97 was 97, checked in by (none), 14 years ago

Adding compiled files

File size: 7.4 KB
Line 
1.\"Copyright 2006-2008 Sun Microsystems, Inc.
2.\" Copyright (c) 1996 Thinking Machines Corporation
3.TH MPI_Op_create 3 "Dec 08, 2009" "1.4" "Open MPI"
4.SH NAME
5\fBMPI_Op_create\fP \- Creates a user-defined combination function handle.
6
7.SH SYNTAX
8.ft R
9.SH C Syntax
10.nf
11#include <mpi.h>
12int MPI_Op_create(MPI_User_function *\fIfunction\fP, int\fI commute\fP,
13        MPI_Op *\fIop\fP)
14
15.SH Fortran Syntax
16.nf
17INCLUDE 'mpif.h'
18MPI_OP_CREATE(\fIFUNCTION, COMMUTE, OP, IERROR\fP)
19        EXTERNAL        \fIFUNCTION\fP
20        LOGICAL \fICOMMUTE\fP
21        INTEGER \fIOP, IERROR\fP
22
23.SH C++ Syntax
24.nf
25#include <mpi.h>
26void Op::Init(User function* \fIfunction\fP, bool \fIcommute\fP)
27
28.SH INPUT PARAMETERS
29.ft R
30.TP 1i
31function
32User-defined function (function).
33.TP 1i
34commute
35True if commutative; false otherwise.
36
37.SH OUTPUT PARAMETERS
38.ft R
39.TP 1i
40op
41Operation (handle).
42.ft R
43.TP 1i
44IERROR
45Fortran only: Error status (integer).
46
47.SH DESCRIPTION
48.ft R
49MPI_Op_create binds a user-defined global operation to an op handle that can subsequently be used in MPI_Reduce, MPI_Allreduce, MPI_Reduce_scatter, and  MPI_Scan. The user-defined operation is assumed to be associative. If commute = true, then the operation should be both commutative and associative. If commute = false, then the order of operands is fixed and is defined to be in ascending, process rank order, beginning with process zero. The order of evaluation can be changed, taking advantage of the associativity of the operation. If commute = true then the order of evaluation can be changed, taking advantage of commutativity and associativity.
50.sp
51\fIfunction\fP is the user-defined function, which must have the following four arguments: invec, inoutvec, len, and datatype.
52
53.sp
54The ANSI-C prototype for the function is the following:
55.sp
56.nf
57  typedef void MPI_User_function(void *invec, void *inoutvec,
58                                 int *len,
59                                 MPI_Datatype *datatype);
60.fi
61.sp
62The Fortran declaration of the user-defined function appears below.
63.sp
64.nf
65  FUNCTION USER_FUNCTION( INVEC(*), INOUTVEC(*), LEN, TYPE)
66  <type> INVEC(LEN), INOUTVEC(LEN)
67   INTEGER LEN, TYPE
68.fi
69.sp
70The datatype argument is a handle to the data type that was passed into the
71call to MPI_Reduce. The user reduce function should be written such that
72the following holds: Let u[0],\ ...,\ u[len-1] be the len elements in the communication buffer described by the arguments invec, len, and datatype when the function is invoked; let v[0],\ ...,\ v[len-1] be len elements in the communication buffer described by the arguments inoutvec, len, and datatype when the function is invoked; let w[0],\ ...,\ w[len-1] be len elements in the communication buffer described by the arguments inoutvec, len, and datatype when the function returns; then w[i] = u[i] o v[i], for i=0\ ,...,\ len-1, where o is the reduce operation that the function computes.
73.sp
74Informally, we can think of invec and inoutvec as arrays of len elements
75that function is combining. The result of the reduction over-writes values
76in inoutvec, hence the name. Each invocation of the function results in the
77pointwise evaluation of the reduce operator on len elements: i.e, the
78function returns in inoutvec[i] the value invec[i] o inoutvec[i], for i =
790\,...,\ count-1, where o is the combining operation computed by the function.
80.sp
81By internally comparing the value of the datatype argument to known, global handles, it is possible to overload the use of a single user-defined function for several different data types.
82.sp
83General datatypes may be passed to the user function. However, use of datatypes that are not contiguous is likely to lead to inefficiencies. 
84.sp
85No MPI communication function may be called inside the user function.
86MPI_Abort may be called inside the function in case of an error.
87
88.SH NOTES
89Suppose one defines a library of user-defined reduce
90functions that are overloaded: The datatype argument is used to select the right execution path at each invocation, according to the types of the operands. The user-defined reduce function cannot "decode" the datatype argument that it is passed, and cannot identify, by itself, the correspondence between the datatype handles and the datatype they represent. This correspondence was established when the datatypes were created. Before the library is used, a library initialization preamble must be executed. This preamble code will define the datatypes that are used by the library and store handles to these datatypes in global, static variables that are shared by the user code and the library code. 
91
92\fBExample:\fP Example of user-defined reduce:
93.sp
94Compute the product of an array of complex numbers, in C.
95.sp
96.nf
97    typedef struct {
98        double real,imag;
99    } Complex;
100 
101    /* the user-defined function
102     */
103    void myProd( Complex *in, Complex *inout, int *len,
104                 MPI_Datatype *dptr )
105    {
106        int i;
107        Complex c;
108 
109    for (i=0; i< *len; ++i) {
110            c.real = inout->real*in->real -
111                       inout->imag*in->imag;
112            c.imag = inout->real*in->imag +
113                       inout->imag*in->real;
114            *inout = c;
115            in++; inout++;
116        }
117    }
118 
119    /* and, to call it\&...
120     */
121    \&...
122
123    /* each process has an array of 100 Complexes
124         */
125        Complex a[100], answer[100];
126        MPI_Op myOp;
127        MPI_Datatype ctype;
128   
129    /* explain to MPI how type Complex is defined
130         */
131       MPI_Type_contiguous( 2, MPI_DOUBLE, &ctype );
132        MPI_Type_commit( &ctype );
133        /* create the complex-product user-op
134         */
135        MPI_Op_create( myProd, True, &myOp );
136     
137        MPI_Reduce( a, answer, 100, ctype, myOp, root, comm );
138     
139        /* At this point, the answer, which consists of 100 Complexes,
140         * resides on process root
141         */
142.fi
143.sp
144The Fortran version of MPI_Reduce will invoke a user-defined reduce function using the Fortran calling conventions and will pass a Fortran-type datatype argument; the C version will use C calling convention and the C representation of a datatype handle. Users who plan to mix languages should define their reduction functions accordingly.
145
146.SH NOTES ON COLLECTIVE OPERATIONS
147
148The reduction functions (
149.I MPI_Op
150) do not return an error value.  As a result,
151if the functions detect an error, all they can do is either call
152.I MPI_Abort
153or silently skip the problem.  Thus, if you change the error handler from
154.I MPI_ERRORS_ARE_FATAL
155to something else, for example,
156.I MPI_ERRORS_RETURN
157,
158then no error may be indicated.
159
160The reason for this is the performance problems in ensuring that
161all collective routines return the same error value.
162
163.SH ERRORS
164Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument. C++ functions do not return errors. If the default error handler is set to MPI::ERRORS_THROW_EXCEPTIONS, then on error the C++ exception mechanism will be used to throw an MPI:Exception object.
165.sp
166Before the error value is returned, the current MPI error handler is
167called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error. 
168
169.SH SEE ALSO
170.ft R
171.sp
172.nf
173MPI_Reduce
174MPI_Reduce_scatter
175MPI_Allreduce
176MPI_Scan
177MPI_Op_free
178
Note: See TracBrowser for help on using the repository browser.