|
|
<!-- --- title: OpenFOAM C++ Coding Patterns (HashTable) -->
|
|
|
<!-- --- title: OpenFOAM C++ Coding Patterns (MPI) -->
|
|
|
|
|
|
[](/home)
|
|
|
[][code-patterns]
|
... | ... | @@ -13,9 +13,58 @@ This is a very broad ranging topic, but here are some general ideas... |
|
|
|
|
|
### General Considerations
|
|
|
|
|
|
- When using point-to-point communication, optimize for contiguous data.
|
|
|
- When using point-to-point communication, optimize for contiguous
|
|
|
data and use the `UIPstream::read` and `UOPstream::write` methods.
|
|
|
```
|
|
|
UIPstream::read
|
|
|
(
|
|
|
Pstream::commsTypes::scheduled,
|
|
|
fromProci,
|
|
|
fld1.data_bytes(),
|
|
|
fld1.size_bytes(),
|
|
|
tag,
|
|
|
comm
|
|
|
);
|
|
|
```
|
|
|
and
|
|
|
```
|
|
|
UOPstream::write
|
|
|
(
|
|
|
Pstream::commsTypes::scheduled,
|
|
|
toProci,
|
|
|
fld2.cdata_bytes(),
|
|
|
fld2.size_bytes(),
|
|
|
tag,
|
|
|
comm
|
|
|
);
|
|
|
```
|
|
|
This will use `MPI_Recv` and `MPI_Send` directly, without the
|
|
|
expense of a `MPI_Probe` call.
|
|
|
|
|
|
|
|
|
### One-sided Gather
|
|
|
|
|
|
- In cases where _flattened_ information is required on the **master**
|
|
|
process only, using `globalIndex` will frequently provide the most
|
|
|
efficient method. Quite frequently, the overall size/offset
|
|
|
information is only needed on the master and not on the
|
|
|
sub-processes:
|
|
|
```
|
|
|
globalIndex globIdx(send.size(), globalIndex::gatherOnly{});
|
|
|
```
|
|
|
Using the `globalIndex::gatherOnly{}` tag will trigger an MPI gather
|
|
|
without the expense of needless broadcast to all nodes.
|
|
|
|
|
|
In many cases, it can be convenient to use the static `gather()`
|
|
|
method:
|
|
|
```
|
|
|
const scalarField mergedWeights(globalIndex::gather(weights));
|
|
|
```
|
|
|
but can also reuse existing size/offset information:
|
|
|
```
|
|
|
const scalarField mergedWeights(globalFaces().gather(weights));
|
|
|
```
|
|
|
|
|
|
----
|
|
|
|
|
|
Copyright (C) 2022 OpenCFD Ltd.
|
... | ... | |