XdmfDSMCommMPI.hpp 27.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfDSMCommMPI.hpp                                                  */
/*                                                                           */
/*  Author:                                                                  */
/*     Andrew Burns                                                          */
/*     andrew.j.burns2@us.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2013 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/

#ifndef XDMFDSMCOMMMPI_HPP_
#define XDMFDSMCOMMMPI_HPP_

// Forward Declarations

#define XDMF_DSM_COMM_MPI       0x11

#define XDMF_DSM_INTRA_COMM  0x00
#define XDMF_DSM_INTER_COMM  0x01
#define XDMF_DSM_ANY_COMM    0x02

#define XDMF_DSM_SERVER_ID          XDMF_DSM_INTRA_COMM
#define XDMF_DSM_CLIENT_ID          XDMF_DSM_INTER_COMM
#define XDMF_DSM_NUM_CONNECTION_IDS 0x02

// Includes
40
#include <XdmfDSM.hpp>
41 42 43

#include <mpi.h>

44 45
#include <string>

46 47 48 49 50 51 52
/**
 * @brief Holds communicators for interacting with H5FD dsm.
 *
 * XdmfDSMCommMPI takes the place of the H5FDdsmComm defined in H5FD.
 * It provides more access to the the intra and inter communicators.
 * It is primarily for allowing the XdmfDSM to interact with HDF5 dsm without threads.
 */
53
class XDMFDSM_EXPORT XdmfDSMCommMPI {
54 55 56 57 58 59 60

public:

  XdmfDSMCommMPI();
  ~XdmfDSMCommMPI();

  /**
61 62
   * Accepts connections to the port currently named by DsmPortName.
   * Called on server side, accepts from core 0.
63 64 65 66 67
   *
   * Example of use:
   *
   * C++
   *
68 69 70 71 72 73 74 75 76 77 78 79 80
   * @dontinclude XdmfAcceptTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#OpenPort
   * @until //#OpenPort
   * @skipline //#manualAccept
   * @until //#manualAccept
   * @skipline //#finishwork
   * @until //#finishwork
   * @skipline //#ClosePort
   * @until //#ClosePort
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
81 82 83
   *
   * Python
   *
84 85 86 87 88 89 90 91 92 93 94
   * @dontinclude XdmfExampleAcceptTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//OpenPort
   * @until #//OpenPort
   * @skipline #//manualAccept
   * @until #//manualAccept
   * @skipline #//finishwork
   * @until #//finishwork
   * @skipline #//ClosePort
   * @until #//ClosePort
95
   */
96
  void Accept(unsigned int numConnections = 1);
97 98

  /**
99
   * Closes the port currently named by DsmPortName.
100 101 102 103 104
   *
   * Example of use:
   *
   * C++
   *
105 106 107 108 109 110 111 112 113 114 115 116 117
   * @dontinclude XdmfAcceptTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#OpenPort
   * @until //#OpenPort
   * @skipline //#SendAccept
   * @until //#SendAccept
   * @skipline //#finishwork
   * @until //#finishwork
   * @skipline //#ClosePort
   * @until //#ClosePort
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
118 119 120
   *
   * Python
   *
121 122 123 124 125 126 127 128 129 130 131
   * @dontinclude XdmfExampleAcceptTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//OpenPort
   * @until #//OpenPort
   * @skipline #//SendAccept
   * @until #//SendAccept
   * @skipline #//finishwork
   * @until #//finishwork
   * @skipline #//ClosePort
   * @until #//ClosePort
132 133 134 135
   */
  void ClosePort();

  /**
136
   * If core ID is 0 then attempts to connect to the port currently named by DsmPortName
137 138 139 140 141
   *
   * Example of use:
   *
   * C++
   *
142 143 144 145 146 147 148 149 150 151 152
   * @dontinclude XdmfConnectTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#ReadDsmPortName
   * @until //#ReadDsmPortName
   * @skipline //#manualConnect
   * @until //#manualConnect
   * @skipline //#Disconnectcomm
   * @until //#Disconnectcomm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
153 154 155
   *
   * Python
   *
156 157 158 159 160 161 162 163 164 165
   * @dontinclude XdmfExampleConnectTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//ReadDsmPortName
   * @until #//ReadDsmPortName
   * @skipline #//manualConnect
   * @until #//manualConnect
   * @skipline #//Disconnectcomm
   * @until #//Disconnectcomm
   *
166
   * @return     Whether the connection was successful or not
167 168 169 170
   */
  int Connect();

  /**
171 172
   * Disconnects the intercomm if not in static intercomm mode.
   * Then sets the intercomm to MPI_COMM_NULL.
173 174 175 176 177
   *
   * Example of use:
   *
   * C++
   *
178 179 180 181 182 183 184 185 186 187 188
   * @dontinclude XdmfConnectTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#ReadDsmPortName
   * @until //#ReadDsmPortName
   * @skipline //#manualConnect
   * @until //#manualConnect
   * @skipline //#Disconnectcomm
   * @until //#Disconnectcomm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
189 190 191
   *
   * Python
   *
192 193 194 195 196 197 198 199 200
   * @dontinclude XdmfExampleConnectTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//ReadDsmPortName
   * @until #//ReadDsmPortName
   * @skipline #//manualConnect
   * @until #//manualConnect
   * @skipline #//Disconnectcomm
   * @until #//Disconnectcomm
201 202 203 204 205 206 207 208 209 210 211
   */
  void Disconnect();

  /**
   * Sets the IntraComm to the provided comm by duplicating it.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#commsplit
   * @until //#commsplit
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#DupComm
   * @until //#DupComm
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
240 241 242
   *
   * Python
   *
243
   * @dontinclude XdmfExampleDSMNoThread.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//DupComm
   * @until #//DupComm
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
264
   *
265
   * @param     comm    The comm to be used as the IntraComm
266 267 268 269 270 271 272 273 274 275 276
   */
  void DupComm(MPI_Comm comm);

  /**
   * Sets the intercomm to the communicator provided by duplicating it.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
277 278 279 280 281 282 283 284 285 286 287 288 289 290
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#commsplit
   * @until //#commsplit
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#DupInterComm
   * @until //#DupInterComm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
291 292 293
   *
   * Python
   *
294
   * @dontinclude XdmfExampleDSMNoThread.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//GetInterComm
   * @until #//GetInterComm
   * @skipline #//DupInterComm
   * @until #//DupInterComm
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
   *
310
   * @param     comm    The comm to be used as the intercomm
311 312 313
   */
  void DupInterComm(MPI_Comm comm);

314
  /**
315 316 317
   * Gets the current file name that connection info will be written to.
   *
   * Example of use:
318
   *
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
   * C++
   *
   * @dontinclude XdmfAcceptTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#GetDsmFileName
   * @until //#GetDsmFileName
   * @skipline //#OpenPort
   * @until //#OpenPort
   * @skipline //#SendAccept
   * @until //#SendAccept
   * @skipline //#finishwork
   * @until //#finishwork
   * @skipline //#ClosePort
   * @until //#ClosePort
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
   *
   * Python
   *
   * @dontinclude XdmfExampleAcceptTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//GetDsmFileName
   * @until #//GetDsmFileName
   * @skipline #//OpenPort
   * @until #//OpenPort
   * @skipline #//SendAccept
   * @until #//SendAccept
   * @skipline #//finishwork
   * @until #//finishwork
   * @skipline #//ClosePort
   * @until #//ClosePort
   *
353
   * @return    The file name where connection info will be written
354 355 356
   */
  std::string GetDsmFileName();

357 358 359 360 361 362 363
  /**
   * Gets the port name that will be connected to when Connect/Accept is called.
   *
   * Example of use:
   *
   * C++
   *
364 365 366 367 368 369 370 371 372 373 374 375 376
   * @dontinclude XdmfConnectTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#ReadDsmPortName
   * @until //#ReadDsmPortName
   * @skipline //#GetDsmPortName
   * @until //#GetDsmPortName
   * @skipline //#manualConnect
   * @until //#manualConnect
   * @skipline //#Disconnectcomm
   * @until //#Disconnectcomm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
377 378 379
   *
   * Python
   *
380 381 382 383 384 385 386 387 388 389 390 391
   * @dontinclude XdmfExampleConnectTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//ReadDsmPortName
   * @until #//ReadDsmPortName
   * @skipline #//GetDsmPortName
   * @until #//GetDsmPortName
   * @skipline #//manualConnect
   * @until #//manualConnect
   * @skipline #//Disconnectcomm
   * @until #//Disconnectcomm
   *
392
   * @return    a pointer to the character string that specifies the port
393
   */
394
  char * GetDsmPortName();
395 396 397 398 399 400 401 402 403

  /**
   * Gets the Id with regards to the IntraComm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetId
   * @until //#GetId
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
430 431 432
   *
   * Python
   *
433
   * @dontinclude XdmfExampleDSMNoThread.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetId
   * @until #//GetId
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
454
   *
455
   * @return    The Id of the core with regards to the IntraComm
456 457 458 459 460 461 462 463 464 465 466
   */
  int GetId();

  /**
   * Gets the communicator that is currently functioning as the intercomm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
467 468 469 470 471 472 473 474 475 476 477 478
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#GetInterComm
   * @until //#GetInterComm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
479 480 481
   *
   * Python
   *
482
   * @dontinclude XdmfExampleDSMNoThread.py
483 484 485 486 487 488 489 490 491 492 493 494 495
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//GetInterComm
   * @until #//GetInterComm
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
   *
496
   * @return     The communicator currently serving as the intercomm.
497 498 499 500 501 502 503 504 505 506 507
   */
  MPI_Comm GetInterComm();

  /**
   * Gets the type of the InterComm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetInterCommType
   * @until //#GetInterCommType
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
534 535 536
   *
   * Python
   *
537
   * @dontinclude XdmfExampleDSMNoThread.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetInterCommType
   * @until #//GetInterCommType
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
558
   *
559
   * @return    An integer representation of the InterComm's type
560 561 562
   */
  int GetInterCommType();

563
  /**
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
   * Gets the Id with regards to the InterComm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetInterId
   * @until //#GetInterId
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
   *
   * Python
599
   *
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
   * @dontinclude XdmfExampleDSMNoThread.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetInterId
   * @until #//GetInterId
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
   *
622
   * @return    The Id of the core with regards to the IntraComm
623 624 625
   */
  int GetInterId();

626 627 628 629 630 631 632 633
  /**
   * Gets the number of cores contained in the InterComm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetInterSize
   * @until //#GetInterSize
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
660 661 662
   *
   * Python
   *
663
   * @dontinclude XdmfExampleDSMNoThread.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetInterSize
   * @until #//GetInterSize
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
684
   *
685
   * @return    The number of cores in the InterComm
686 687 688 689 690 691 692 693 694 695 696
   */
  int GetInterSize();

  /**
   * Gets the communicator that is currently functioning as the intracomm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetIntraComm
   * @until //#GetIntraComm
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
723 724 725
   *
   * Python
   *
726
   * @dontinclude XdmfExampleDSMNoThread.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetIntraComm
   * @until #//GetIntraComm
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
   *
748
   * @return    The communicator currently serving as the intracomm.
749 750 751 752 753 754 755 756 757 758 759
   */
  MPI_Comm GetIntraComm();

  /**
   * Gets the number of cores contained in the IntraComm.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#GetIntraSize
   * @until //#GetIntraSize
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
786 787 788
   *
   * Python
   *
789
   * @dontinclude XdmfExampleDSMNoThread.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//GetIntraSize
   * @until #//GetIntraSize
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
810
   *
811
   * @return    The number of cores in the IntraComm
812 813 814 815
   */
  int GetIntraSize();

  /**
816 817
   * Initializes the Intracomm rank and size to the associated variables
   * in the internal structure
818 819 820 821 822 823
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude ExampleXdmfDSMNoThread.cpp
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#initwritevector
   * @until //#initwritevector
   * @skipline //#initwritergenerate
   * @until //#initwritergenerate
   * @skipline //#startworksection
   * @until //#startworksection
   * @skipline //#declaremanager
   * @until //#declaremanager
   * @skipline //#getServerManagerwriter
   * @until //#getServerManagerwriter
   * @skipline //#declarebuffer
   * @until //#declarebuffer
   * @skipline //#GetDsmBuffer
   * @until //#GetDsmBuffer
   * @skipline //#GetComm
   * @until //#GetComm
   * @skipline //#initcomm
   * @until //#initcomm
   * @skipline //#endworksection
   * @until //#endworksection
   * @skipline //#stopDSMwriter
   * @until //#stopDSMwriter
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
850 851 852
   *
   * Python
   *
853
   * @dontinclude XdmfExampleDSMNoThread.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//initwritevector
   * @until #//initwritevector
   * @skipline #//initwritergenerate
   * @until #//initwritergenerate
   * @skipline #//startworksection
   * @until #//startworksection
   * @skipline #//getServerManagerwriter
   * @until #//getServerManagerwriter
   * @skipline #//GetDsmBuffer
   * @until #//GetDsmBuffer
   * @skipline #//GetComm
   * @until #//GetComm
   * @skipline #//initcomm
   * @until #//initcomm
   * @skipline #//stopDSMwriter
   * @until #//stopDSMwriter
   * @skipline #//finalizeMPI
   * @until #//finalizeMPI
874 875 876 877
   */
  void Init();

  /**
878
   * Opens a port and stores the port name in DsmPortName.
879 880 881 882 883
   *
   * Example of use:
   *
   * C++
   *
884 885 886 887 888 889 890 891 892 893 894 895 896
   * @dontinclude XdmfAcceptTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#OpenPort
   * @until //#OpenPort
   * @skipline //#SendAccept
   * @until //#SendAccept
   * @skipline //#finishwork
   * @until //#finishwork
   * @skipline //#ClosePort
   * @until //#ClosePort
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
897 898 899
   *
   * Python
   *
900 901 902 903 904 905 906 907 908 909 910
   * @dontinclude XdmfExampleAcceptTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//OpenPort
   * @until #//OpenPort
   * @skipline #//SendAccept
   * @until #//SendAccept
   * @skipline #//finishwork
   * @until #//finishwork
   * @skipline #//ClosePort
   * @until #//ClosePort
911 912 913
   */
  void OpenPort();

914
  /**
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
   * Reads the connection information from the current DSMfile.
   *
   * Example of use:
   *
   * C++
   *
   * @dontinclude XdmfConnectTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#ReadDsmPortName
   * @until //#ReadDsmPortName
   * @skipline //#manualConnect
   * @until //#manualConnect
   * @skipline //#Disconnectcomm
   * @until //#Disconnectcomm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
   *
   * Python
934
   *
935 936 937 938 939 940 941 942 943
   * @dontinclude XdmfExampleConnectTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//ReadDsmPortName
   * @until #//ReadDsmPortName
   * @skipline #//manualConnect
   * @until #//manualConnect
   * @skipline #//Disconnectcomm
   * @until #//Disconnectcomm
944 945 946 947
   */
  void ReadDsmPortName();

  /**
948
   * Sets the file name that connection info will be written to.
949
   *
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
   * Example of use:
   *
   * C++
   *
   * @dontinclude XdmfAcceptTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#GetDsmFileName
   * @until //#GetDsmFileName
   * @skipline //#SetDsmFileName
   * @until //#SetDsmFileName
   * @skipline //#OpenPort
   * @until //#OpenPort
   * @skipline //#SendAccept
   * @until //#SendAccept
   * @skipline //#finishwork
   * @until //#finishwork
   * @skipline //#ClosePort
   * @until //#ClosePort
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
   *
   * Python
   *
   * @dontinclude XdmfExampleAcceptTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//GetDsmFileName
   * @until #//GetDsmFileName
   * @skipline #//SetDsmFileName
   * @until #//SetDsmFileName
   * @skipline #//OpenPort
   * @until #//OpenPort
   * @skipline #//SendAccept
   * @until #//SendAccept
   * @skipline #//finishwork
   * @until #//finishwork
   * @skipline #//ClosePort
   * @until #//ClosePort
   *
990
   * @param     filename        The file name where connection info will be written
991 992 993
   */
  void SetDsmFileName(std::string filename);

994 995 996 997 998 999 1000 1001
  /**
   * Sets the port name that will be connected to when Connect/Accept is called.
   * Data is copied, so the provided string is not modified.
   *
   * Example of use:
   *
   * C++
   *
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
   * @dontinclude XdmfConnectTest.cpp
   * @skipline //#initMPI
   * @until //#initMPI
   * @skipline //#ReadDsmPortName
   * @until //#ReadDsmPortName
   * @skipline //#GetDsmPortName
   * @until //#GetDsmPortName
   * @skipline //#manualConnect
   * @until //#manualConnect
   * @skipline //#Disconnectcomm
   * @until //#Disconnectcomm
   * @skipline //#finalizeMPI
   * @until //#finalizeMPI
1015 1016 1017
   *
   * Python
   *
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
   * @dontinclude XdmfExampleConnectTest.py
   * @skipline #//initMPI
   * @until #//initMPI
   * @skipline #//ReadDsmPortName
   * @until #//ReadDsmPortName
   * @skipline #//GetDsmPortName
   * @until #//GetDsmPortName
   * @skipline #//SetDsmPortName
   * @until #//SetDsmPortName
   * @skipline #//manualConnect
   * @until #//manualConnect
   * @skipline #//Disconnectcomm
   * @until #//Disconnectcomm
   *
1032
   * @param     hostName        a pointer to the character string that specifies the port
1033
   */
1034
  void SetDsmPortName(const char *hostName);
1035 1036 1037 1038 1039

protected:


private:
1040 1041 1042 1043 1044 1045 1046 1047 1048
  MPI_Comm      IntraComm;
  int           Id;
  int           IntraSize;
  MPI_Comm      InterComm;
  int           InterId;
  int           InterSize;
  int           InterCommType;
  char          DsmPortName[MPI_MAX_PORT_NAME];
  std::string   DsmFileName;
1049
  bool          HasOpenedPort;
1050 1051 1052 1053
};

#endif /* XDMFDSMCOMMMPI_HPP_ */