vtkProcessGroup.h 4.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// -*- c++ -*-
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkProcessGroup.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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.

=========================================================================*/
/*----------------------------------------------------------------------------
 Copyright (c) Sandia Corporation
 See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
----------------------------------------------------------------------------*/

21 22 23 24 25 26 27 28
/**
 * @class   vtkProcessGroup
 * @brief   A subgroup of processes from a communicator.
 *
 *
 *
 * This class is used for creating groups of processes.  A vtkProcessGroup is
 * initialized by passing the controller or communicator on which the group is
luz.paz's avatar
luz.paz committed
29
 * based off of.  You can then use the group to subset and reorder the
30 31 32 33 34 35 36 37 38 39 40 41 42 43
 * processes.  Eventually, you can pass the group object to the
 * CreateSubController method of vtkMultiProcessController to create a
 * controller for the defined group of processes.  You must use the same
 * controller (or attached communicator) from which this group was initialized
 * with.
 *
 * @sa
 * vtkMultiProcessController, vtkCommunicator
 *
 * @par Thanks:
 * This class was originally written by Kenneth Moreland (kmorel@sandia.gov)
 * from Sandia National Laboratories.
 *
*/
44

45 46
#ifndef vtkProcessGroup_h
#define vtkProcessGroup_h
47

48
#include "vtkParallelCoreModule.h" // For export macro
49 50 51 52 53
#include "vtkObject.h"

class vtkMultiProcessController;
class vtkCommunicator;

54
class VTKPARALLELCORE_EXPORT vtkProcessGroup : public vtkObject
55 56
{
public:
57
  vtkTypeMacro(vtkProcessGroup, vtkObject);
58
  static vtkProcessGroup *New();
59
  void PrintSelf(ostream &os, vtkIndent indent) override;
60

61 62 63 64 65 66
  //@{
  /**
   * Initialize the group to the given controller or communicator.  The group
   * will be set to contain all of the processes in the controller/communicator
   * in the same order.
   */
67 68
  void Initialize(vtkMultiProcessController *controller);
  void Initialize(vtkCommunicator *communicator);
69
  //@}
70

71 72 73 74
  //@{
  /**
   * Get the communicator on which this group is based on.
   */
75
  vtkGetObjectMacro(Communicator, vtkCommunicator);
76 77 78 79 80 81 82 83 84
  //@}

  /**
   * Set the communicator.  This has the same effect as Initialize except that
   * the contents of the group will not be modified (although they may be
   * truncated if the new communicator is smaller than the current group).
   * Note that this can lead to an invalid group if there are values in the
   * group that are not valid in the new communicator.
   */
85 86
  void SetCommunicator(vtkCommunicator *communicator);

87 88 89 90
  //@{
  /**
   * Returns the size of this group (the number of processes defined in it).
   */
91
  vtkGetMacro(NumberOfProcessIds, int);
92 93 94 95 96 97 98 99
  //@}

  /**
   * Given a position in the group, returns the id of the process in the
   * communicator this group is based on.  For example, if this group contains
   * {6, 2, 8, 1}, then GetProcessId(2) will return 8 and GetProcessId(3) will
   * return 1.
   */
100 101
  int GetProcessId(int pos) { return this->ProcessIds[pos]; }

102 103 104 105
  /**
   * Get the process id for the local process (as defined by the group's
   * communicator).  Returns -1 if the local process is not in the group.
   */
106 107
  int GetLocalProcessId();

108 109 110 111 112 113
  /**
   * Given a process id in the communicator, this method returns its location in
   * the group or -1 if it is not in the group.  For example, if this group
   * contains {6, 2, 8, 1}, then FindProcessId(2) will return 1 and
   * FindProcessId(3) will return -1.
   */
114 115
  int FindProcessId(int processId);

116 117 118 119
  /**
   * Add a process id to the end of the group (if it is not already in the
   * group).  Returns the location where the id was stored.
   */
120 121
  int AddProcessId(int processId);

122 123 124 125 126 127
  /**
   * Remove the given process id from the group (assuming it is in the group).
   * All ids to the "right" of the removed id are shifted over.  Returns 1
   * if the process id was removed, 0 if the process id was not in the group
   * in the first place.
   */
128 129
  int RemoveProcessId(int processId);

130 131 132
  /**
   * Removes all the processes ids from the group, leaving the group empty.
   */
133 134
  void RemoveAllProcessIds();

135 136 137
  /**
   * Copies the given group's communicator and process ids.
   */
138 139 140 141
  void Copy(vtkProcessGroup *group);

protected:
  vtkProcessGroup();
142
  ~vtkProcessGroup() override;
143 144 145 146 147 148 149

  int *ProcessIds;
  int NumberOfProcessIds;

  vtkCommunicator *Communicator;

private:
150 151
  vtkProcessGroup(const vtkProcessGroup &) = delete;
  void operator=(const vtkProcessGroup &) = delete;
152 153
};

154
#endif //vtkProcessGroup_h