|
| 1 | +# Migration Guide |
| 2 | + |
| 3 | +## Migrating from v0.2 to v0.3 |
| 4 | + |
| 5 | +### Initialization and teardown |
| 6 | + |
| 7 | +The package-level `Start`, `Stop`, `WorldRank`, `WorldSize`, and `WorldTime` |
| 8 | +functions have been replaced by a session object. |
| 9 | + |
| 10 | +```go |
| 11 | +// v0.2 |
| 12 | +mpi.Start(false) |
| 13 | +defer mpi.Stop() |
| 14 | +rank := mpi.WorldRank() |
| 15 | +size := mpi.WorldSize() |
| 16 | +``` |
| 17 | + |
| 18 | +```go |
| 19 | +// v0.3 |
| 20 | +m, err := mpi.Start() |
| 21 | +if err != nil { |
| 22 | + log.Fatal(err) |
| 23 | +} |
| 24 | +defer m.Stop() |
| 25 | +rank := m.WorldRank() |
| 26 | +size := m.WorldSize() |
| 27 | +``` |
| 28 | + |
| 29 | +For threaded initialization: |
| 30 | + |
| 31 | +```go |
| 32 | +// v0.2 |
| 33 | +mpi.Start(true) |
| 34 | + |
| 35 | +// v0.3 |
| 36 | +m, err := mpi.StartThreaded() |
| 37 | +``` |
| 38 | + |
| 39 | +### Initialization check |
| 40 | + |
| 41 | +```go |
| 42 | +// v0.2 |
| 43 | +mpi.IsOn() |
| 44 | + |
| 45 | +// v0.3 |
| 46 | +mpi.IsInitialized() |
| 47 | +``` |
| 48 | + |
| 49 | +### Communicators |
| 50 | + |
| 51 | +`NewCommunicator` is now a method on `*MPI` rather than a package-level function. |
| 52 | + |
| 53 | +```go |
| 54 | +// v0.2 |
| 55 | +comm := mpi.NewCommunicator(nil) |
| 56 | + |
| 57 | +// v0.3 |
| 58 | +comm := m.NewCommunicator(nil) |
| 59 | +``` |
| 60 | + |
| 61 | +### Send and receive |
| 62 | + |
| 63 | +All type-specific send/receive methods (`SendBytes`, `SendInt32s`, `SendFloat64s`, |
| 64 | +etc.) have been replaced by generic methods. |
| 65 | + |
| 66 | +```go |
| 67 | +// v0.2 |
| 68 | +comm.SendFloat64s(vals, toID, tag) |
| 69 | +vals, status := comm.RecvFloat64s(fromID, tag) |
| 70 | +comm.RecvPreallocFloat64s(vals, fromID, tag) |
| 71 | +``` |
| 72 | + |
| 73 | +```go |
| 74 | +// v0.3 |
| 75 | +comm.Send(vals, toID, tag) |
| 76 | +vals, status := comm.Recv[float64](fromID, tag) |
| 77 | +comm.RecvPrealloc(vals, fromID, tag) |
| 78 | +``` |
| 79 | + |
| 80 | +The same pattern applies to all types: `byte`, `int8`, `int16`, `uint16`, |
| 81 | +`int32`, `uint32`, `int64`, `uint64`, `float32`, `float64`, `complex64`, |
| 82 | +`complex128`. |
| 83 | + |
| 84 | +### Single-value send/receive |
| 85 | + |
| 86 | +```go |
| 87 | +// v0.2 |
| 88 | +comm.SendFloat64(v, toID, tag) |
| 89 | +v, status := comm.RecvFloat64(fromID, tag) |
| 90 | +``` |
| 91 | + |
| 92 | +```go |
| 93 | +// v0.3 |
| 94 | +comm.SendOne(v, toID, tag) |
| 95 | +v, status := comm.RecvOne[float64](fromID, tag) |
| 96 | +``` |
| 97 | + |
| 98 | +### Broadcast |
| 99 | + |
| 100 | +```go |
| 101 | +// v0.2 |
| 102 | +comm.BcastFloat64s(vals, root) |
| 103 | + |
| 104 | +// v0.3 |
| 105 | +comm.Bcast(vals, root) |
| 106 | +``` |
| 107 | + |
| 108 | +### Reduce and Allreduce |
| 109 | + |
| 110 | +```go |
| 111 | +// v0.2 |
| 112 | +comm.ReduceFloat64s(dest, orig, mpi.OpSum, root) |
| 113 | +comm.AllreduceFloat64s(dest, orig, mpi.OpSum, root) |
| 114 | + |
| 115 | +// v0.3 |
| 116 | +comm.Reduce(dest, orig, mpi.OpSum, root) |
| 117 | +comm.Allreduce(dest, orig, mpi.OpSum) |
| 118 | +``` |
| 119 | + |
| 120 | +Note that `Allreduce` no longer takes a `root` parameter. The v0.2 parameter |
| 121 | +was accepted but never used; v0.3 removes it. |
| 122 | + |
| 123 | +### Status |
| 124 | + |
| 125 | +`Status` is now a value type. Methods that previously returned `*Status` now |
| 126 | +return `Status`. |
| 127 | + |
| 128 | +`Count` (formerly `GetCount`) is now generic and no longer takes a `DataType` argument, and has |
| 129 | +been renamed along with other `Status` methods. |
| 130 | + |
| 131 | +| v0.2 | v0.3 | |
| 132 | +|------|------| |
| 133 | +| `Status.GetSource()` | `Status.Source()` | |
| 134 | +| `Status.GetTag()` | `Status.Tag()` | |
| 135 | +| `Status.GetError()` | `Status.Error()` | |
| 136 | +| `Status.GetCount(mpi.Byte)` | `Status.Count[byte]()` | |
| 137 | + |
| 138 | +### Mprobe and Mrecv |
| 139 | + |
| 140 | +The v0.2 API exposed `C.MPI_Message` directly. In v0.3 this is encapsulated |
| 141 | +in `MatchedMessage`. |
| 142 | + |
| 143 | +```go |
| 144 | +// v0.2 |
| 145 | +status, msg := comm.Mprobe(fromID, tag) |
| 146 | +n := status.GetCount(mpi.Byte) |
| 147 | +buf := make([]byte, n) |
| 148 | +comm.MrecvPreallocBytes(buf, fromID, tag, msg) |
| 149 | +``` |
| 150 | + |
| 151 | +```go |
| 152 | +// v0.3 |
| 153 | +m := comm.Mprobe(fromID, tag) |
| 154 | +buf, status := m.Recv[byte]() |
| 155 | +// or, with a preallocated buffer: |
| 156 | +status = m.RecvPrealloc(buf) |
| 157 | +``` |
| 158 | + |
| 159 | +`Mrecv` is also available as a single call: |
| 160 | + |
| 161 | +```go |
| 162 | +buf, status := comm.Mrecv[byte](fromID, tag) |
| 163 | +``` |
| 164 | + |
| 165 | +`MatchedMessage` methods follow the same naming convention as `Status`: |
| 166 | + |
| 167 | +| v0.2 | v0.3 | |
| 168 | +|------|------| |
| 169 | +| `MatchedMessage.GetSource()` | `MatchedMessage.Source()` | |
| 170 | +| `MatchedMessage.GetTag()` | `MatchedMessage.Tag()` | |
| 171 | +| `MatchedMessage.GetError()` | `MatchedMessage.Error()` | |
| 172 | +| `MatchedMessage.GetCount[T]()` | `MatchedMessage.Count[T]()` | |
| 173 | + |
| 174 | +### Communicator methods |
| 175 | + |
| 176 | +| v0.2 | v0.3 | |
| 177 | +|------|------| |
| 178 | +| `Communicator.GetAttr()` | `Communicator.Attr()` | |
| 179 | +| `Communicator.GetMaxTag()` | `Communicator.MaxTag()` | |
| 180 | + |
| 181 | +### Communicator.MaxTag field removed |
| 182 | + |
| 183 | +The exported `MaxTag` field on `Communicator` has been unexported. Use |
| 184 | +`Communicator.MaxTag()` if you need this value. |
| 185 | + |
| 186 | +### DataType removed |
| 187 | + |
| 188 | +The exported `DataType` constants (`mpi.Byte`, `mpi.Int`, `mpi.Float`, |
| 189 | +`mpi.Double`, etc.) have been removed. Type information is now conveyed through |
| 190 | +Go generics and is not part of the public API. |
| 191 | + |
| 192 | +### Iprobe |
| 193 | + |
| 194 | +`Iprobe` now returns a value `Status` rather than a pointer. |
| 195 | + |
| 196 | +### String convenience methods |
| 197 | + |
| 198 | +`SendString` and `RecvString` have been removed. Use `Send` and `Recv` with a |
| 199 | +`[]byte` conversion: |
| 200 | + |
| 201 | +```go |
| 202 | +// v0.2 |
| 203 | +comm.SendString(s, toID, tag) |
| 204 | +s, status := comm.RecvString(fromID, tag) |
| 205 | + |
| 206 | +// v0.3 |
| 207 | +comm.Send([]byte(s), toID, tag) |
| 208 | +b, status := comm.Recv[byte](fromID, tag) |
| 209 | +s := string(b) |
| 210 | +``` |
0 commit comments