Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
mesh_mpi.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Module libfe
4 // File mesh.h
5 // Declaration of class MeshMPI (distributed mesh)
6 // Uses Zoltan library for mesh partitioning
7 // ==========================================================================
8 
9 #ifndef __MESH_MPI_H
10 #define __MESH_MPI_H
11 
12 #include "mesh.h"
13 #include "zoltan.h"
14 
15 // ==========================================================================
16 // Prototypes
17 
18 // ==========================================================================
19 // class Mesh
20 // ==========================================================================
30 class FELIB MeshMPI: public QMMesh {
31 public:
32  struct GraphData {
33  int numMyVertices; // total vertices in my partition
34  int numAllNbors; // total number of neighbours of my vertices
35  ZOLTAN_ID_TYPE *vertexGID;// global IDs for my vertices (1-based)
36  int *nborIndex; // nborIndex[i] is start of neighbours for vtx i
37  ZOLTAN_ID_TYPE *nborGID; // nborGID[nborIndex[i]] is first neighbour of i
38  int *nborPart; // process owning each nbor in nborGID
39  int vertex_capacity; // size of vertexGID buffer
40  int nbor_capacity; // size of nborGID & nborPart buffers
41  struct Zoltan_DD_Struct *dd;
42  };
43 
44  MeshMPI ();
45  ~MeshMPI ();
46  void Setup (bool mark_boundary=true);
47  void NodeToElementMap (int **nndel, int ***ndel) const;
48  GraphData *GetGraphData() { return &myGraph; }
49  void Partition (struct Zoltan_Struct *zz);
50  void Migrate (struct Zoltan_Struct *zz);
51  Zoltan_DD_Struct *ZoltanDictionary () { return myGraph.dd; }
52  int GetOwnedElements (int **_ellist) const
53  { *_ellist = ellist; return nel; }
54  int GetNodeTypeList (int **_ntp) const { *_ntp = nodeType; }
55 
56  void AddToElMatrix (int el, CCompRowMatrixMPI &M, RVector *coeff,
57  int mode) const;
58  void AddToSysMatrix (CCompRowMatrixMPI &M, RVector *coeff, int mode) const;
59 
60  // temporary
61  int *Parts() const { return parts; }
62  ZOLTAN_ID_PTR Lids() const { return lids; }
63 
64 protected:
65  void ComputeNodeToElementMap (int **nndel, int ***ndel) const;
66  void ClearNodeToElementMap ();
67  void ComputeElementList (ZOLTAN_ID_TYPE *gid, int ngid,
68  int **_ellist, int *_nel) const;
69  void ComputeNodeTypeList (int **ntype) const;
70  void ComputePartition (GraphData *graph);
71  void CreateZoltanDictionary ();
72 
73 private:
74  // Zoltan access functions
75  static int Zoltan_get_number_of_vertices (void *data, int *ierr);
76  static void Zoltan_get_vertex_list (void *data, int sizeGID, int sizeLID,
77  ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int wgt_dim,
78  float *obj_wgts, int *ierr);
79  static void Zoltan_get_num_edges_list (void *data, int sizeGID, int sizeLID,
80  int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
81  int *numEdges, int *ierr);
82  static void Zoltan_get_edge_list (void *data, int sizeGID, int sizeLID,
83  int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
84  int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborPart,
85  int wgt_dim, float *ewgts, int *ierr);
86  static void Zoltan_get_message_sizes (void *data, int gidSize, int lidSize,
87  int num_ids, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int *sizes,
88  int *ierr);
89  static void Zoltan_pack_object_messages (void *data, int gidSize,
90  int lidSize, int num_ids, ZOLTAN_ID_PTR globalIDs,
91  ZOLTAN_ID_PTR localIDs, int *dests, int *sizes, int *idx, char *buf,
92  int *ierr);
93  static void Zoltan_unpack_object_messages (void *data, int gidSize,
94  int num_ids, ZOLTAN_ID_PTR globalIDs, int *size, int *idx, char *buf,
95  int *ierr);
96  static void Zoltan_mid_migrate (void *data, int gidSize, int lidSize,
97  int numImport, ZOLTAN_ID_PTR importGlobalID,
98  ZOLTAN_ID_PTR importLocalID, int *importProc, int *importPart,
99  int numExport, ZOLTAN_ID_PTR exportGlobalID,
100  ZOLTAN_ID_PTR exportLocalID, int *exportProc, int *exportPart,
101  int *ierr);
102 
103  int rank;
104  int nproc;
105  int *nndel; // number of elements for each node
106  int **ndel; // list of element indices for each node
107  int nel; // number of elements processed by this process
108  int *ellist; // list of elements processed by this process
109  int *nodeType; // 2=owned, 1=ghost, 0=not my node
110  GraphData myGraph; // mesh partition data for this process
111  int *parts;
112  ZOLTAN_ID_PTR lids;
113 
114  // the following data are returned by the Zoltan partitioner.
115  // Maybe store in local method if not required globally
116  int changes, numGidEntries, numLidEntries, numImport, numExport;
117  ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids,
118  exportLocalGids;
119  int *importProcs, *importToPart, *exportProcs, *exportToPart;
120 };
121 
122 #endif // !__MESH_MPI_H
Templated vector class.
Definition: vector.h:39
Definition: mesh_mpi.h:32
Definition: qmmesh.h:22
Distributed compressed-row sparse matrix class.
Definition: crmatrix_mpi.h:33
Finite-element mesh management.
Definition: mesh_mpi.h:30