MFEM v2.0
communication.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
00003 // reserved. See file COPYRIGHT for details.
00004 //
00005 // This file is part of the MFEM library. For more information and source code
00006 // availability see http://mfem.googlecode.com.
00007 //
00008 // MFEM is free software; you can redistribute it and/or modify it under the
00009 // terms of the GNU Lesser General Public License (as published by the Free
00010 // Software Foundation) version 2.1 dated February 1999.
00011 
00012 #ifndef MFEM_COMMUNICATION
00013 #define MFEM_COMMUNICATION
00014 
00015 class GroupTopology
00016 {
00017 private:
00018    MPI_Comm   MyComm;
00019 
00020    /* The shared entities (e.g. vertices, faces and edges) are split into
00021       groups, each group determined by the set of participating processors.
00022       They are numbered locally in lproc. Assumptions:
00023       - group 0 is the 'local' group
00024       - groupmaster_lproc[0] = 0
00025       - lproc_proc[0] = MyRank */
00026    Table      group_lproc;
00027    Array<int> groupmaster_lproc;
00028    Array<int> lproc_proc;
00029    Array<int> group_mgroup; // group --> group number in the master
00030 
00031    void ProcToLProc();
00032 
00033 public:
00034    GroupTopology(MPI_Comm comm) { MyComm = comm; }
00035 
00036    MPI_Comm GetComm() { return MyComm; }
00037    int MyRank() { int r; MPI_Comm_rank(MyComm, &r); return r; }
00038    int NRanks() { int s; MPI_Comm_size(MyComm, &s); return s; }
00039 
00040    void Create(ListOfIntegerSets &groups, int mpitag);
00041 
00042    int NGroups() { return group_lproc.Size(); }
00043    // return the number of neighbors including the local processor
00044    int GetNumNeighbors() { return lproc_proc.Size(); }
00045    int GetNeighborRank(int i) { return lproc_proc[i]; }
00046    // am I master for group 'g'?
00047    bool IAmMaster(int g) { return (groupmaster_lproc[g] == 0); }
00048    // return the neighbor index of the group master for a given group.
00049    // neighbor 0 is the local processor
00050    int GetGroupMaster(int g) { return groupmaster_lproc[g]; }
00051    // return the rank of the group master for a given group
00052    int GetGroupMasterRank(int g) { return lproc_proc[groupmaster_lproc[g]]; }
00053    // for a given group return the group number in the master
00054    int GetGroupMasterGroup(int g) { return group_mgroup[g]; }
00055    // get the number of processors in a group
00056    int GetGroupSize(int g) { return group_lproc.RowSize(g); }
00057    // return a pointer to a list of neighbors for a given group.
00058    // neighbor 0 is the local processor
00059    const int *GetGroup(int g) { return group_lproc.GetRow(g); }
00060 };
00061 
00062 
00063 class GroupCommunicator
00064 {
00065 private:
00066    GroupTopology &gtopo;
00067    Table group_ldof;
00068    Array<int> group_buf;
00069    MPI_Request *requests;
00070    MPI_Status  *statuses;
00071 
00072 public:
00073    GroupCommunicator(GroupTopology &gt);
00076    void Create(Array<int> &ldof_group);
00079    Table &GroupLDofTable() { return group_ldof; }
00081    void Finalize();
00082 
00084    void Bcast(Array<int> &ldata);
00087    void Reduce(Array<int> &ldata);
00088    ~GroupCommunicator();
00089 };
00090 
00091 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines