Package Scientific :: Package MPI :: Class MPICommunicator

[frames] | no frames]

# Class MPICommunicator

MPI Communicator

There is no constructor for MPI Communicator objects. The default communicator is given by Scientific.MPI.world, and other communicators can only be created by methods on an existing communicator object.

A communicator object has two read-only attributes: 'rank' is an integer which indicates the rank of the current process in the communicator, and 'size' is an integer equal to the number of processes that participate in the communicator.

Instance Methods

abort(self, error_code) Abort all processes associated with the communicator. |

allreduce(self, sendbuffer, receivebuffer, operation) Combine data from all processes and send result to all |

barrier(self) Wait until all processes in the communicator have called the same method, then all processes continue. |

broadcast(self, array, root) Send data to all processes |

MPICommunicator

duplicate(self) Returns: a new communicator with the same properties as the original one |

`NoneType` or `tuple`

nonblockingProbe(self, source=None, tag=None) Check for incoming messages |

MPIRequest

nonblockingReceive(self, data, source=None, tag=None) Receive data from another process (non-blocking) |

MPIRequest

nonblockingSend(self, data, destination, tag) Send data to another process (non-blocking) |

`tuple`

receive(self, data, source=None, tag=None) Receive data from another process (blocking) |

`tuple`

receiveString(self, source=None, tag=None) Receive string data from another process (blocking) |

reduce(self, sendbuffer, receivebuffer, operation, root) Combine data from all processes and send result to one |

send(self, data, destination, tag) Send data to another process (blocking) |

share(self, send, receive) Distribute data from each processpr to all other processesors |

subset(self, ranks) Create a communicator for a subset of the processes |

Method Details

### abort(self, error_code)

Abort all processes associated with the communicator. For emergency use only.

Parameters:
  - `error_code` (`int`) - error code passed back to the calling program (usually a shell) under most Unix implementations of MPI

### allreduce(self, sendbuffer, receivebuffer, operation)

Combine data from all processes and send result to all

Parameters:
  - `sendbuffer` (`Numeric.array`) - an array holding the data that each process contributes
  - `receivebuffer` (`Numeric.array`) - an array acting as a buffer for the result of the reduction
  - `operation` (MPIOperationObject) - one of the operation objects: max, min, prod, sum, land, lor, lxor, band, bor, bxor, maxloc and minloc

### broadcast(self, array, root)

Send data to all processes

Parameters:
  - `array` (Numeric.array) - an array containing the data to be sent on the sending process and serving as a buffer for the incoming data on all processes. The shape and type of the array must be the same on all processes.
  - `root` (`int`) - the rank of the sending process

Note: The data is sent to all processes, including the sending one.

### duplicate(self)

Returns: MPICommunicator
  a new communicator with the same properties as the original one

### nonblockingProbe(self, source=None, tag=None)

Check for incoming messages

Parameters:
  - `source` (`int` or `NoneType`) - the rank of the process from which messages are accepted. `None` means data is accepted from any process.
  - `tag` (`int` or `NoneType`) - Identifier that acts as a filter; only messages with a matching tag are considered. A value of `None` means that any tag will match.
Returns: `NoneType` or `tuple`
  `None` if no messages are available, otherwise a tuple containing the source rank and the tag

### nonblockingReceive(self, data, source=None, tag=None)

Receive data from another process (non-blocking)

Parameters:
  - `data` (`Numeric.array`) - a contiguous array object to which the incoming data is copied. It must have the right shape.
  - `source` (`int` or `NoneType`) - the rank of the process from which data is accepted. `None` means data is accepted from any process.
  - `tag` (`int` or `NoneType`) - Identifier that acts as a filter; only messages with a matching tag are received. A value of `None` means that any tag will match.
Returns: MPIRequest
  MPI request object (used to wait for completion and obtain the received data)

### nonblockingSend(self, data, destination, tag)

Send data to another process (non-blocking)

Parameters:
  - `data` (`str` or `Numeric.array`. Array arguments must have contiguous storage. General object arrays are not allowed.) - the data to be sent
  - `destination` (`int`) - the rank of the destination process
  - `tag` (`int`) - Identifier
Returns: MPIRequest
  MPI request object (used to wait for completion)

### receive(self, data, source=None, tag=None)

Receive data from another process (blocking)

Parameters:
  - `data` (`Numeric.array` or `str`) - either a contiguous array object, or a one-letter typecode (in practice, one would use Numeric.Int, Numeric.Float, etc.). If an array, the data is copied to the array, whic must have the right shape. If a typecode, an array of that type is created and used as the buffer for incoming data.
  - `source` (`int` or `NoneType`) - the rank of the process from which data is accepted. `None` means data is accepted from any process.
  - `tag` (`int` or `NoneType`) - Identifier that acts as a filter; only messages with a matching tag are received. A value of `None` means that any tag will match.
Returns: `tuple`
  a tuple containing four elements: the array containing the data, the source process rank (an `int`), the message tag (an `int`), and the number of elements that were received (an `int`).

### receiveString(self, source=None, tag=None)

Receive string data from another process (blocking)

Parameters:
  - `source` (`int` or `NoneType`) - the rank of the process from which data is accepted. `None` means data is accepted from any process.
  - `tag` (`int` or `NoneType`) - Identifier that acts as a filter; only messages with a matching tag are received. A value of `None` means that any tag will match.
Returns: `tuple`
  a tuple containing three elements: the string containing the data, the source process rank (an `int`), the message tag (an `int`).

### reduce(self, sendbuffer, receivebuffer, operation, root)

Combine data from all processes and send result to one

Parameters:
  - `sendbuffer` (`Numeric.array`) - an array holding the data that each process contributes
  - `receivebuffer` (`Numeric.array`) - an array acting as a buffer for the result of the reduction. Used only by the process whose rank is root
  - `operation` (MPIOperationObject) - one of the operation objects: max, min, prod, sum, land, lor, lxor, band, bor, bxor, maxloc and minloc
  - `root` (`int`) - the rank of the process that received the result

### send(self, data, destination, tag)

Send data to another process (blocking)

Parameters:
  - `data` (`str` or `Numeric.array`. Array arguments must have contiguous storage. General object arrays are not allowed.) - the data to be sent
  - `destination` (`int`) - the rank of the destination process
  - `tag` (`int`) - Identifier

### share(self, send, receive)

Distribute data from each processpr to all other processesors

Parameters:
  - `send` (`Numeric.array`) - an array of identical shape and type on all processes. It contains on each process the data that is sent.
  - `receive` (`Numeric.array`) - an array whose type is the same as for the send array and which has an additional dimension (the first one) whose length is the number of processes. After the call, the value of receive[i] is equal to the contents of the array send in process i.

### subset(self, ranks)

Create a communicator for a subset of the processes

The method should be called by all processes simultaneously. The return value will be the new communicator on those processes listed in `ranks` and `None` for the rest.

Parameters:
  - `ranks` (`list` of `int`) - a list of ranks, one for each process that should belong to the new communicator
Returns:
  a new communicator containing a subset of the processes participating in the original one