[97] | 1 | // -*- c++ -*- |
---|
| 2 | // |
---|
| 3 | // Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana |
---|
| 4 | // University Research and Technology |
---|
| 5 | // Corporation. All rights reserved. |
---|
| 6 | // Copyright (c) 2004-2005 The University of Tennessee and The University |
---|
| 7 | // of Tennessee Research Foundation. All rights |
---|
| 8 | // reserved. |
---|
| 9 | // Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, |
---|
| 10 | // University of Stuttgart. All rights reserved. |
---|
| 11 | // Copyright (c) 2004-2005 The Regents of the University of California. |
---|
| 12 | // All rights reserved. |
---|
| 13 | // Copyright (c) 2006-2008 Cisco Systems, Inc. All rights reserved. |
---|
| 14 | // $COPYRIGHT$ |
---|
| 15 | // |
---|
| 16 | // Additional copyrights may follow |
---|
| 17 | // |
---|
| 18 | // $HEADER$ |
---|
| 19 | // |
---|
| 20 | |
---|
| 21 | class Comm_Null { |
---|
| 22 | #if 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 23 | // friend class PMPI::Comm_Null; |
---|
| 24 | #endif |
---|
| 25 | public: |
---|
| 26 | |
---|
| 27 | #if 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 28 | |
---|
| 29 | // construction |
---|
| 30 | inline Comm_Null() { } |
---|
| 31 | // copy |
---|
| 32 | inline Comm_Null(const Comm_Null& data) : pmpi_comm(data.pmpi_comm) { } |
---|
| 33 | // inter-language operability |
---|
| 34 | inline Comm_Null(MPI_Comm data) : pmpi_comm(data) { } |
---|
| 35 | |
---|
| 36 | inline Comm_Null(const PMPI::Comm_Null& data) : pmpi_comm(data) { } |
---|
| 37 | |
---|
| 38 | // destruction |
---|
| 39 | virtual inline ~Comm_Null() { } |
---|
| 40 | |
---|
| 41 | inline Comm_Null& operator=(const Comm_Null& data) { |
---|
| 42 | pmpi_comm = data.pmpi_comm; |
---|
| 43 | return *this; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | // comparison |
---|
| 47 | inline bool operator==(const Comm_Null& data) const { |
---|
| 48 | return (bool) (pmpi_comm == data.pmpi_comm); } |
---|
| 49 | |
---|
| 50 | inline bool operator!=(const Comm_Null& data) const { |
---|
| 51 | return (bool) (pmpi_comm != data.pmpi_comm);} |
---|
| 52 | |
---|
| 53 | // inter-language operability (conversion operators) |
---|
| 54 | inline operator MPI_Comm() const { return pmpi_comm; } |
---|
| 55 | // inline operator MPI_Comm*() /*const JGS*/ { return pmpi_comm; } |
---|
| 56 | inline operator const PMPI::Comm_Null&() const { return pmpi_comm; } |
---|
| 57 | |
---|
| 58 | #else |
---|
| 59 | |
---|
| 60 | // construction |
---|
| 61 | inline Comm_Null() : mpi_comm(MPI_COMM_NULL) { } |
---|
| 62 | // copy |
---|
| 63 | inline Comm_Null(const Comm_Null& data) : mpi_comm(data.mpi_comm) { } |
---|
| 64 | // inter-language operability |
---|
| 65 | inline Comm_Null(MPI_Comm data) : mpi_comm(data) { } |
---|
| 66 | |
---|
| 67 | // destruction |
---|
| 68 | virtual inline ~Comm_Null() { } |
---|
| 69 | |
---|
| 70 | // comparison |
---|
| 71 | // JGS make sure this is right (in other classes too) |
---|
| 72 | inline bool operator==(const Comm_Null& data) const { |
---|
| 73 | return (bool) (mpi_comm == data.mpi_comm); } |
---|
| 74 | |
---|
| 75 | inline bool operator!=(const Comm_Null& data) const { |
---|
| 76 | return (bool) !(*this == data);} |
---|
| 77 | |
---|
| 78 | // inter-language operability (conversion operators) |
---|
| 79 | inline operator MPI_Comm() const { return mpi_comm; } |
---|
| 80 | |
---|
| 81 | #endif |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | protected: |
---|
| 85 | |
---|
| 86 | #if 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 87 | PMPI::Comm_Null pmpi_comm; |
---|
| 88 | #else |
---|
| 89 | MPI_Comm mpi_comm; |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | class Comm : public Comm_Null { |
---|
| 97 | public: |
---|
| 98 | |
---|
| 99 | typedef void Errhandler_fn(Comm&, int*, ...); |
---|
| 100 | typedef int Copy_attr_function(const Comm& oldcomm, int comm_keyval, |
---|
| 101 | void* extra_state, void* attribute_val_in, |
---|
| 102 | void* attribute_val_out, |
---|
| 103 | bool& flag); |
---|
| 104 | typedef int Delete_attr_function(Comm& comm, int comm_keyval, |
---|
| 105 | void* attribute_val, |
---|
| 106 | void* extra_state); |
---|
| 107 | #if !0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 108 | #define _MPI2CPP_ERRHANDLERFN_ Errhandler_fn |
---|
| 109 | #define _MPI2CPP_COPYATTRFN_ Copy_attr_function |
---|
| 110 | #define _MPI2CPP_DELETEATTRFN_ Delete_attr_function |
---|
| 111 | #endif |
---|
| 112 | |
---|
| 113 | // construction |
---|
| 114 | Comm(); |
---|
| 115 | |
---|
| 116 | // copy |
---|
| 117 | Comm(const Comm_Null& data); |
---|
| 118 | |
---|
| 119 | #if 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 120 | Comm(const Comm& data) : |
---|
| 121 | Comm_Null(data), |
---|
| 122 | pmpi_comm((const PMPI::Comm&) data) { } |
---|
| 123 | |
---|
| 124 | // inter-language operability |
---|
| 125 | Comm(MPI_Comm data) : Comm_Null(data), pmpi_comm(data) { } |
---|
| 126 | |
---|
| 127 | Comm(const PMPI::Comm& data) : |
---|
| 128 | Comm_Null((const PMPI::Comm_Null&)data), |
---|
| 129 | pmpi_comm(data) { } |
---|
| 130 | |
---|
| 131 | operator const PMPI::Comm&() const { return pmpi_comm; } |
---|
| 132 | |
---|
| 133 | // assignment |
---|
| 134 | Comm& operator=(const Comm& data) { |
---|
| 135 | this->Comm_Null::operator=(data); |
---|
| 136 | pmpi_comm = data.pmpi_comm; |
---|
| 137 | return *this; |
---|
| 138 | } |
---|
| 139 | Comm& operator=(const Comm_Null& data) { |
---|
| 140 | this->Comm_Null::operator=(data); |
---|
| 141 | MPI_Comm tmp = data; |
---|
| 142 | pmpi_comm = tmp; |
---|
| 143 | return *this; |
---|
| 144 | } |
---|
| 145 | // inter-language operability |
---|
| 146 | Comm& operator=(const MPI_Comm& data) { |
---|
| 147 | this->Comm_Null::operator=(data); |
---|
| 148 | pmpi_comm = data; |
---|
| 149 | return *this; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | #else |
---|
| 153 | Comm(const Comm& data) : Comm_Null(data.mpi_comm) { } |
---|
| 154 | // inter-language operability |
---|
| 155 | Comm(MPI_Comm data) : Comm_Null(data) { } |
---|
| 156 | #endif |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | // |
---|
| 160 | // Point-to-Point |
---|
| 161 | // |
---|
| 162 | |
---|
| 163 | virtual void Send(const void *buf, int count, |
---|
| 164 | const Datatype & datatype, int dest, int tag) const; |
---|
| 165 | |
---|
| 166 | virtual void Recv(void *buf, int count, const Datatype & datatype, |
---|
| 167 | int source, int tag, Status & status) const; |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | virtual void Recv(void *buf, int count, const Datatype & datatype, |
---|
| 171 | int source, int tag) const; |
---|
| 172 | |
---|
| 173 | virtual void Bsend(const void *buf, int count, |
---|
| 174 | const Datatype & datatype, int dest, int tag) const; |
---|
| 175 | |
---|
| 176 | virtual void Ssend(const void *buf, int count, |
---|
| 177 | const Datatype & datatype, int dest, int tag) const ; |
---|
| 178 | |
---|
| 179 | virtual void Rsend(const void *buf, int count, |
---|
| 180 | const Datatype & datatype, int dest, int tag) const; |
---|
| 181 | |
---|
| 182 | virtual Request Isend(const void *buf, int count, |
---|
| 183 | const Datatype & datatype, int dest, int tag) const; |
---|
| 184 | |
---|
| 185 | virtual Request Ibsend(const void *buf, int count, const |
---|
| 186 | Datatype & datatype, int dest, int tag) const; |
---|
| 187 | |
---|
| 188 | virtual Request Issend(const void *buf, int count, |
---|
| 189 | const Datatype & datatype, int dest, int tag) const; |
---|
| 190 | |
---|
| 191 | virtual Request Irsend(const void *buf, int count, |
---|
| 192 | const Datatype & datatype, int dest, int tag) const; |
---|
| 193 | |
---|
| 194 | virtual Request Irecv(void *buf, int count, |
---|
| 195 | const Datatype & datatype, int source, int tag) const; |
---|
| 196 | |
---|
| 197 | virtual bool Iprobe(int source, int tag, Status & status) const; |
---|
| 198 | |
---|
| 199 | virtual bool Iprobe(int source, int tag) const; |
---|
| 200 | |
---|
| 201 | virtual void Probe(int source, int tag, Status & status) const; |
---|
| 202 | |
---|
| 203 | virtual void Probe(int source, int tag) const; |
---|
| 204 | |
---|
| 205 | virtual Prequest Send_init(const void *buf, int count, |
---|
| 206 | const Datatype & datatype, int dest, |
---|
| 207 | int tag) const; |
---|
| 208 | |
---|
| 209 | virtual Prequest Bsend_init(const void *buf, int count, |
---|
| 210 | const Datatype & datatype, int dest, |
---|
| 211 | int tag) const; |
---|
| 212 | |
---|
| 213 | virtual Prequest Ssend_init(const void *buf, int count, |
---|
| 214 | const Datatype & datatype, int dest, |
---|
| 215 | int tag) const; |
---|
| 216 | |
---|
| 217 | virtual Prequest Rsend_init(const void *buf, int count, |
---|
| 218 | const Datatype & datatype, int dest, |
---|
| 219 | int tag) const; |
---|
| 220 | |
---|
| 221 | virtual Prequest Recv_init(void *buf, int count, |
---|
| 222 | const Datatype & datatype, int source, |
---|
| 223 | int tag) const; |
---|
| 224 | |
---|
| 225 | virtual void Sendrecv(const void *sendbuf, int sendcount, |
---|
| 226 | const Datatype & sendtype, int dest, int sendtag, |
---|
| 227 | void *recvbuf, int recvcount, |
---|
| 228 | const Datatype & recvtype, int source, |
---|
| 229 | int recvtag, Status & status) const; |
---|
| 230 | |
---|
| 231 | virtual void Sendrecv(const void *sendbuf, int sendcount, |
---|
| 232 | const Datatype & sendtype, int dest, int sendtag, |
---|
| 233 | void *recvbuf, int recvcount, |
---|
| 234 | const Datatype & recvtype, int source, |
---|
| 235 | int recvtag) const; |
---|
| 236 | |
---|
| 237 | virtual void Sendrecv_replace(void *buf, int count, |
---|
| 238 | const Datatype & datatype, int dest, |
---|
| 239 | int sendtag, int source, |
---|
| 240 | int recvtag, Status & status) const; |
---|
| 241 | |
---|
| 242 | virtual void Sendrecv_replace(void *buf, int count, |
---|
| 243 | const Datatype & datatype, int dest, |
---|
| 244 | int sendtag, int source, |
---|
| 245 | int recvtag) const; |
---|
| 246 | |
---|
| 247 | // |
---|
| 248 | // Groups, Contexts, and Communicators |
---|
| 249 | // |
---|
| 250 | |
---|
| 251 | virtual Group Get_group() const; |
---|
| 252 | |
---|
| 253 | virtual int Get_size() const; |
---|
| 254 | |
---|
| 255 | virtual int Get_rank() const; |
---|
| 256 | |
---|
| 257 | static int Compare(const Comm & comm1, const Comm & comm2); |
---|
| 258 | |
---|
| 259 | virtual Comm& Clone() const = 0; |
---|
| 260 | |
---|
| 261 | virtual void Free(void); |
---|
| 262 | |
---|
| 263 | virtual bool Is_inter() const; |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | // |
---|
| 267 | // Collective Communication |
---|
| 268 | // |
---|
| 269 | // Up in Comm because as of MPI-2, they are common to intracomm and |
---|
| 270 | // intercomm -- with the exception of Scan and Exscan, which are not |
---|
| 271 | // defined on intercomms. |
---|
| 272 | // |
---|
| 273 | |
---|
| 274 | virtual void |
---|
| 275 | Barrier() const; |
---|
| 276 | |
---|
| 277 | virtual void |
---|
| 278 | Bcast(void *buffer, int count, |
---|
| 279 | const Datatype& datatype, int root) const; |
---|
| 280 | |
---|
| 281 | virtual void |
---|
| 282 | Gather(const void *sendbuf, int sendcount, |
---|
| 283 | const Datatype & sendtype, |
---|
| 284 | void *recvbuf, int recvcount, |
---|
| 285 | const Datatype & recvtype, int root) const; |
---|
| 286 | |
---|
| 287 | virtual void |
---|
| 288 | Gatherv(const void *sendbuf, int sendcount, |
---|
| 289 | const Datatype & sendtype, void *recvbuf, |
---|
| 290 | const int recvcounts[], const int displs[], |
---|
| 291 | const Datatype & recvtype, int root) const; |
---|
| 292 | |
---|
| 293 | virtual void |
---|
| 294 | Scatter(const void *sendbuf, int sendcount, |
---|
| 295 | const Datatype & sendtype, |
---|
| 296 | void *recvbuf, int recvcount, |
---|
| 297 | const Datatype & recvtype, int root) const; |
---|
| 298 | |
---|
| 299 | virtual void |
---|
| 300 | Scatterv(const void *sendbuf, const int sendcounts[], |
---|
| 301 | const int displs[], const Datatype & sendtype, |
---|
| 302 | void *recvbuf, int recvcount, |
---|
| 303 | const Datatype & recvtype, int root) const; |
---|
| 304 | |
---|
| 305 | virtual void |
---|
| 306 | Allgather(const void *sendbuf, int sendcount, |
---|
| 307 | const Datatype & sendtype, void *recvbuf, |
---|
| 308 | int recvcount, const Datatype & recvtype) const; |
---|
| 309 | |
---|
| 310 | virtual void |
---|
| 311 | Allgatherv(const void *sendbuf, int sendcount, |
---|
| 312 | const Datatype & sendtype, void *recvbuf, |
---|
| 313 | const int recvcounts[], const int displs[], |
---|
| 314 | const Datatype & recvtype) const; |
---|
| 315 | |
---|
| 316 | virtual void |
---|
| 317 | Alltoall(const void *sendbuf, int sendcount, |
---|
| 318 | const Datatype & sendtype, void *recvbuf, |
---|
| 319 | int recvcount, const Datatype & recvtype) const; |
---|
| 320 | |
---|
| 321 | virtual void |
---|
| 322 | Alltoallv(const void *sendbuf, const int sendcounts[], |
---|
| 323 | const int sdispls[], const Datatype & sendtype, |
---|
| 324 | void *recvbuf, const int recvcounts[], |
---|
| 325 | const int rdispls[], const Datatype & recvtype) const; |
---|
| 326 | |
---|
| 327 | virtual void |
---|
| 328 | Alltoallw(const void *sendbuf, const int sendcounts[], |
---|
| 329 | const int sdispls[], const Datatype sendtypes[], |
---|
| 330 | void *recvbuf, const int recvcounts[], |
---|
| 331 | const int rdispls[], const Datatype recvtypes[]) const; |
---|
| 332 | |
---|
| 333 | virtual void |
---|
| 334 | Reduce(const void *sendbuf, void *recvbuf, int count, |
---|
| 335 | const Datatype & datatype, const Op & op, |
---|
| 336 | int root) const; |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | virtual void |
---|
| 340 | Allreduce(const void *sendbuf, void *recvbuf, int count, |
---|
| 341 | const Datatype & datatype, const Op & op) const; |
---|
| 342 | |
---|
| 343 | virtual void |
---|
| 344 | Reduce_scatter(const void *sendbuf, void *recvbuf, |
---|
| 345 | int recvcounts[], |
---|
| 346 | const Datatype & datatype, |
---|
| 347 | const Op & op) const; |
---|
| 348 | |
---|
| 349 | // |
---|
| 350 | // Process Creation |
---|
| 351 | // |
---|
| 352 | |
---|
| 353 | virtual void Disconnect(); |
---|
| 354 | |
---|
| 355 | static Intercomm Get_parent(); |
---|
| 356 | |
---|
| 357 | static Intercomm Join(const int fd); |
---|
| 358 | |
---|
| 359 | // |
---|
| 360 | // External Interfaces |
---|
| 361 | // |
---|
| 362 | |
---|
| 363 | virtual void Get_name(char * comm_name, int& resultlen) const; |
---|
| 364 | |
---|
| 365 | virtual void Set_name(const char* comm_name); |
---|
| 366 | |
---|
| 367 | // |
---|
| 368 | // Process Topologies |
---|
| 369 | // |
---|
| 370 | |
---|
| 371 | virtual int Get_topology() const; |
---|
| 372 | |
---|
| 373 | // |
---|
| 374 | // Environmental Inquiry |
---|
| 375 | // |
---|
| 376 | |
---|
| 377 | virtual void Abort(int errorcode); |
---|
| 378 | |
---|
| 379 | // |
---|
| 380 | // Errhandler |
---|
| 381 | // |
---|
| 382 | |
---|
| 383 | static Errhandler Create_errhandler(Comm::Errhandler_fn* function); |
---|
| 384 | |
---|
| 385 | virtual void Set_errhandler(const Errhandler& errhandler) const; |
---|
| 386 | |
---|
| 387 | virtual Errhandler Get_errhandler() const; |
---|
| 388 | |
---|
| 389 | void Call_errhandler(int errorcode) const; |
---|
| 390 | |
---|
| 391 | // |
---|
| 392 | // Keys and Attributes |
---|
| 393 | // |
---|
| 394 | |
---|
| 395 | // Need 4 overloaded versions of this function because per the |
---|
| 396 | // MPI-2 spec, you can mix-n-match the C predefined functions with |
---|
| 397 | // C++ functions. |
---|
| 398 | static int Create_keyval(Copy_attr_function* comm_copy_attr_fn, |
---|
| 399 | Delete_attr_function* comm_delete_attr_fn, |
---|
| 400 | void* extra_state); |
---|
| 401 | static int Create_keyval(MPI_Comm_copy_attr_function* comm_copy_attr_fn, |
---|
| 402 | MPI_Comm_delete_attr_function* comm_delete_attr_fn, |
---|
| 403 | void* extra_state); |
---|
| 404 | static int Create_keyval(Copy_attr_function* comm_copy_attr_fn, |
---|
| 405 | MPI_Comm_delete_attr_function* comm_delete_attr_fn, |
---|
| 406 | void* extra_state); |
---|
| 407 | static int Create_keyval(MPI_Comm_copy_attr_function* comm_copy_attr_fn, |
---|
| 408 | Delete_attr_function* comm_delete_attr_fn, |
---|
| 409 | void* extra_state); |
---|
| 410 | |
---|
| 411 | protected: |
---|
| 412 | static int do_create_keyval(MPI_Comm_copy_attr_function* c_copy_fn, |
---|
| 413 | MPI_Comm_delete_attr_function* c_delete_fn, |
---|
| 414 | Copy_attr_function* cxx_copy_fn, |
---|
| 415 | Delete_attr_function* cxx_delete_fn, |
---|
| 416 | void* extra_state, int &keyval); |
---|
| 417 | |
---|
| 418 | public: |
---|
| 419 | |
---|
| 420 | static void Free_keyval(int& comm_keyval); |
---|
| 421 | |
---|
| 422 | virtual void Set_attr(int comm_keyval, const void* attribute_val) const; |
---|
| 423 | |
---|
| 424 | virtual bool Get_attr(int comm_keyval, void* attribute_val) const; |
---|
| 425 | |
---|
| 426 | virtual void Delete_attr(int comm_keyval); |
---|
| 427 | |
---|
| 428 | static int NULL_COPY_FN(const Comm& oldcomm, int comm_keyval, |
---|
| 429 | void* extra_state, void* attribute_val_in, |
---|
| 430 | void* attribute_val_out, bool& flag); |
---|
| 431 | |
---|
| 432 | static int DUP_FN(const Comm& oldcomm, int comm_keyval, |
---|
| 433 | void* extra_state, void* attribute_val_in, |
---|
| 434 | void* attribute_val_out, bool& flag); |
---|
| 435 | |
---|
| 436 | static int NULL_DELETE_FN(Comm& comm, int comm_keyval, void* attribute_val, |
---|
| 437 | void* extra_state); |
---|
| 438 | |
---|
| 439 | |
---|
| 440 | private: |
---|
| 441 | #if 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 442 | PMPI::Comm pmpi_comm; |
---|
| 443 | #endif |
---|
| 444 | |
---|
| 445 | #if ! 0 /* OMPI_ENABLE_MPI_PROFILING */ |
---|
| 446 | public: |
---|
| 447 | |
---|
| 448 | // Data that is passed through keyval create when C++ callback |
---|
| 449 | // functions are used |
---|
| 450 | struct keyval_intercept_data_t { |
---|
| 451 | MPI_Comm_copy_attr_function *c_copy_fn; |
---|
| 452 | MPI_Comm_delete_attr_function *c_delete_fn; |
---|
| 453 | Copy_attr_function* cxx_copy_fn; |
---|
| 454 | Delete_attr_function* cxx_delete_fn; |
---|
| 455 | void *extra_state; |
---|
| 456 | }; |
---|
| 457 | |
---|
| 458 | // Protect the global list from multiple thread access |
---|
| 459 | static opal_mutex_t cxx_extra_states_lock; |
---|
| 460 | #endif |
---|
| 461 | |
---|
| 462 | }; |
---|