[97] | 1 | .\"Copyright 2006-2008 Sun Microsystems, Inc. |
---|
| 2 | .\" Copyright (c) 1996 Thinking Machines Corporation |
---|
| 3 | .TH MPI_Scan 3 "Dec 08, 2009" "1.4" "Open MPI" |
---|
| 4 | |
---|
| 5 | .SH NAME |
---|
| 6 | \fBMPI_Scan\fP \- Computes an inclusive scan (partial reduction) |
---|
| 7 | |
---|
| 8 | .SH SYNTAX |
---|
| 9 | .ft R |
---|
| 10 | |
---|
| 11 | .SH C Syntax |
---|
| 12 | .nf |
---|
| 13 | #include <mpi.h> |
---|
| 14 | int MPI_Scan(void *\fIsendbuf\fP, void *\fIrecvbuf\fP, int \fIcount\fP, |
---|
| 15 | MPI_Datatype \fIdatatype\fP, MPI_Op \fIop\fP, MPI_Comm \fIcomm\fP) |
---|
| 16 | |
---|
| 17 | .SH Fortran Syntax |
---|
| 18 | .nf |
---|
| 19 | INCLUDE 'mpif.h' |
---|
| 20 | MPI_SCAN(\fISENDBUF, RECVBUF, COUNT, DATATYPE, OP, COMM, IERROR\fP) |
---|
| 21 | <type> \fISENDBUF(*), RECVBUF(*)\fP |
---|
| 22 | INTEGER \fICOUNT, DATATYPE, OP, COMM, IERROR\fP |
---|
| 23 | |
---|
| 24 | .SH C++ Syntax |
---|
| 25 | .nf |
---|
| 26 | #include <mpi.h> |
---|
| 27 | void MPI::Intracomm::Scan(const void* \fIsendbuf\fP, void* \fIrecvbuf\fP, |
---|
| 28 | int \fIcount\fP, const MPI::Datatype& \fIdatatype\fP, |
---|
| 29 | const MPI::Op& \fIop\fP) const |
---|
| 30 | |
---|
| 31 | .SH INPUT PARAMETERS |
---|
| 32 | .ft R |
---|
| 33 | .TP 1i |
---|
| 34 | sendbuf |
---|
| 35 | Send buffer (choice). |
---|
| 36 | .TP 1i |
---|
| 37 | count |
---|
| 38 | Number of elements in input buffer (integer). |
---|
| 39 | .TP 1i |
---|
| 40 | datatype |
---|
| 41 | Data type of elements of input buffer (handle). |
---|
| 42 | .TP 1i |
---|
| 43 | op |
---|
| 44 | Operation (handle). |
---|
| 45 | .TP 1i |
---|
| 46 | comm |
---|
| 47 | Communicator (handle). |
---|
| 48 | |
---|
| 49 | .SH OUTPUT PARAMETERS |
---|
| 50 | .ft R |
---|
| 51 | .TP 1i |
---|
| 52 | recvbuf |
---|
| 53 | Receive buffer (choice). |
---|
| 54 | .ft R |
---|
| 55 | .TP 1i |
---|
| 56 | IERROR |
---|
| 57 | Fortran only: Error status (integer). |
---|
| 58 | |
---|
| 59 | .SH DESCRIPTION |
---|
| 60 | .ft R |
---|
| 61 | MPI_Scan is used to perform an inclusive prefix reduction on data |
---|
| 62 | distributed across the calling processes. The operation returns, in |
---|
| 63 | the \fIrecvbuf\fP of the process with rank i, the reduction |
---|
| 64 | (calculated according to the function \fIop\fP) of the values in the |
---|
| 65 | \fIsendbuf\fPs of processes with ranks 0, ..., i (inclusive). The type |
---|
| 66 | of operations supported, their semantics, and the constraints on send |
---|
| 67 | and receive buffers are as for MPI_Reduce. |
---|
| 68 | |
---|
| 69 | .SH EXAMPLE |
---|
| 70 | .ft R |
---|
| 71 | This example uses a user-defined operation to produce a segmented |
---|
| 72 | scan. A segmented scan takes, as input, a set of values and a set of |
---|
| 73 | logicals, where the logicals delineate the various segments of the |
---|
| 74 | scan. For example, |
---|
| 75 | .sp |
---|
| 76 | .nf |
---|
| 77 | values v1 v2 v3 v4 v5 v6 v7 v8 |
---|
| 78 | logicals 0 0 1 1 1 0 0 1 |
---|
| 79 | result v1 v1+v2 v3 v3+v4 v3+v4+v5 v6 v6+v7 v8 |
---|
| 80 | .fi |
---|
| 81 | .sp |
---|
| 82 | The result for rank j is thus the sum v(i) + ... + v(j), where i is |
---|
| 83 | the lowest rank such that for all ranks n, i <= n <= j, logical(n) = |
---|
| 84 | logical(j). The operator that produces this effect is |
---|
| 85 | .sp |
---|
| 86 | .nf |
---|
| 87 | [ u ] [ v ] [ w ] |
---|
| 88 | [ ] o [ ] = [ ] |
---|
| 89 | [ i ] [ j ] [ j ] |
---|
| 90 | .sp |
---|
| 91 | where |
---|
| 92 | .sp |
---|
| 93 | ( u + v if i = j |
---|
| 94 | w = ( |
---|
| 95 | ( v if i != j |
---|
| 96 | .fi |
---|
| 97 | .sp |
---|
| 98 | Note that this is a noncommutative operator. C code that implements it is |
---|
| 99 | given below. |
---|
| 100 | .sp |
---|
| 101 | .nf |
---|
| 102 | typedef struct { |
---|
| 103 | double val; |
---|
| 104 | int log; |
---|
| 105 | } SegScanPair; |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * the user-defined function |
---|
| 109 | */ |
---|
| 110 | void segScan(SegScanPair *in, SegScanPair *inout, int *len, |
---|
| 111 | MPI_Datatype *dptr) |
---|
| 112 | { |
---|
| 113 | int i; |
---|
| 114 | SegScanPair c; |
---|
| 115 | |
---|
| 116 | for (i = 0; i < *len; ++i) { |
---|
| 117 | if (in->log == inout->log) |
---|
| 118 | c.val = in->val + inout->val; |
---|
| 119 | else |
---|
| 120 | c.val = inout->val; |
---|
| 121 | |
---|
| 122 | c.log = inout->log; |
---|
| 123 | *inout = c; |
---|
| 124 | in++; |
---|
| 125 | inout++; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | .fi |
---|
| 129 | .sp |
---|
| 130 | Note that the inout argument to the user-defined function corresponds |
---|
| 131 | to the right-hand operand of the operator. When using this operator, |
---|
| 132 | we must be careful to specify that it is noncommutative, as in the |
---|
| 133 | following: |
---|
| 134 | .sp |
---|
| 135 | .nf |
---|
| 136 | int i, base; |
---|
| 137 | SeqScanPair a, answer; |
---|
| 138 | MPI_Op myOp; |
---|
| 139 | MPI_Datatype type[2] = {MPI_DOUBLE, MPI_INT}; |
---|
| 140 | MPI_Aint disp[2]; |
---|
| 141 | int blocklen[2] = {1, 1}; |
---|
| 142 | MPI_Datatype sspair; |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * explain to MPI how type SegScanPair is defined |
---|
| 146 | */ |
---|
| 147 | MPI_Get_address(a, disp); |
---|
| 148 | MPI_Get_address(a.log, disp + 1); |
---|
| 149 | base = disp[0]; |
---|
| 150 | for (i = 0; i < 2; ++i) |
---|
| 151 | disp[i] -= base; |
---|
| 152 | MPI_Type_struct(2, blocklen, disp, type, &sspair); |
---|
| 153 | MPI_Type_commit(&sspair); |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * create the segmented-scan user-op |
---|
| 157 | * noncommutative - set commute (arg 2) to 0 |
---|
| 158 | */ |
---|
| 159 | MPI_Op_create((MPI_User_function *)segScan, 0, &myOp); |
---|
| 160 | \&... |
---|
| 161 | MPI_Scan(a, answer, 1, sspair, myOp, comm); |
---|
| 162 | .fi |
---|
| 163 | |
---|
| 164 | .SH USE OF IN-PLACE OPTION |
---|
| 165 | WHen the communicator is an intracommunicator, you can perform a scanning operation in place (the output buffer is used as the input buffer). Use the variable MPI_IN_PLACE as the value of the \fIsendbuf\fR argument. The input data is taken from the receive buffer and replaced by the output data. |
---|
| 166 | |
---|
| 167 | .SH NOTES ON COLLECTIVE OPERATIONS |
---|
| 168 | .ft R |
---|
| 169 | The reduction functions of type MPI_Op do not return an error value. |
---|
| 170 | As a result, if the functions detect an error, all they can do is |
---|
| 171 | either call MPI_Abort or silently skip the problem. Thus, if the |
---|
| 172 | error handler is changed from MPI_ERRORS_ARE_FATAL to something else |
---|
| 173 | (e.g., MPI_ERRORS_RETURN), then no error may be indicated. |
---|
| 174 | .sp |
---|
| 175 | The reason for this is the performance problems in ensuring that |
---|
| 176 | all collective routines return the same error value. |
---|
| 177 | |
---|
| 178 | .SH ERRORS |
---|
| 179 | .ft R |
---|
| 180 | Almost all MPI routines return an error value; C routines as |
---|
| 181 | the value of the function and Fortran routines in the last argument. C++ |
---|
| 182 | functions do not return errors. If the default error handler is set to |
---|
| 183 | MPI::ERRORS_THROW_EXCEPTIONS, then on error the C++ exception mechanism |
---|
| 184 | will be used to throw an MPI:Exception object. |
---|
| 185 | .sp |
---|
| 186 | Before the error value is returned, the current MPI error handler is |
---|
| 187 | called. By default, this error handler aborts the MPI job, except for |
---|
| 188 | I/O function errors. The error handler may be changed with |
---|
| 189 | MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN |
---|
| 190 | may be used to cause error values to be returned. Note that MPI does not |
---|
| 191 | guarantee that an MPI program can continue past an error. |
---|
| 192 | .sp |
---|
| 193 | See the MPI man page for a full list of MPI error codes. |
---|
| 194 | |
---|
| 195 | .SH SEE ALSO |
---|
| 196 | .ft R |
---|
| 197 | .nf |
---|
| 198 | MPI_Exscan |
---|
| 199 | MPI_Op_create |
---|
| 200 | MPI_Reduce |
---|
| 201 | |
---|