LCOV - code coverage report
Current view: top level - ugbase/lib_grid/tools - partition_map.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 11 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 3 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2011-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG__partition_map__
      34              : #define __H__UG__partition_map__
      35              : 
      36              : #include "lib_grid/file_io/file_io.h"
      37              : #include "lib_grid/grid/grid.h"
      38              : #include "lib_grid/tools/subset_handler_grid.h"
      39              : #include "common/util/smart_pointer.h"
      40              : 
      41              : namespace ug
      42              : {
      43              : 
      44              : /** \ingroup lib_grid_tools
      45              :  *  \{ */
      46              : 
      47              : ///     Used to describe how a domain shall be distributed in a parallel environment.
      48              : /**     A partition map holds a subset handler and a map, which specifies the
      49              :  * target process of each subset. Make sure to assign a grid before performing
      50              :  * the partitioning.
      51              :  *
      52              :  * \todo        a partition map should feature a constructor which takes a grid.
      53              :  */
      54            0 : class PartitionMap{
      55              :         public:
      56              :                 PartitionMap();
      57              : 
      58              :                 void clear();
      59              : 
      60              :                 void assign_grid(Grid& grid);
      61              : 
      62              :                 SmartPtr<SubsetHandler> get_partition_handler();
      63              : 
      64              :                 void add_target_proc(int tarProcRank);
      65              : 
      66              :                 void add_target_procs(int first, int num);
      67              : 
      68              :                 size_t num_target_procs();
      69              : 
      70              :                 int get_target_proc(size_t index);
      71              : 
      72              :                 int* get_target_procs();
      73              : 
      74              :                 std::vector<int>& get_target_proc_vec();
      75              : 
      76              :         ///     changes an existing target process. Make sure that index < num_target_procs
      77              :                 bool change_target_proc(size_t index, int newRank);
      78              : 
      79              :         ///     returns the index at which the given process lies. -1 if it doesn't exist.
      80              :                 int find_target_proc(int procRank);
      81              : 
      82              :         ///     adds the given offset to all target-proc-ranks
      83              :                 void shift_target_procs(int offset);
      84              : 
      85              :         private:
      86              :                 SmartPtr<SubsetHandler>   m_shPartitions;
      87              :                 std::vector<int>          m_targetProcs;
      88              : };
      89              : 
      90              : typedef SmartPtr<PartitionMap>    SPPartitionMap;
      91              : 
      92              : 
      93              : 
      94              : ///     Save the partition map to a file.
      95              : /**     The resulting file will contain the grid on which the partition-map operates,
      96              :  * together with subsets, each representing the process on which the subset will
      97              :  * be sent.
      98              :  *
      99              :  * \todo        currently only the .ugx format is supported.
     100              :  */
     101              : template <class TAPos>
     102            0 : bool SavePartitionMapToFile(PartitionMap& pm, const char* filename,
     103              :                                                         TAPos& aPos)
     104              : {
     105            0 :         SubsetHandler& partsh = *pm.get_partition_handler();
     106              : 
     107              : //      make sure that a grid exists
     108            0 :         if(!partsh.grid()){
     109              :                 UG_LOG("WARNING IN SavePartitionMapToFile: a grid has to be assigned "
     110              :                                 "to the PartitionMap. Aborting.\n");
     111            0 :                 return false;
     112              :         }
     113              : 
     114            0 :         Grid& grid = *partsh.grid();
     115              : 
     116              : //      we need a subset-handler, which will have a 1-1 subset-process relation.
     117            0 :         SubsetHandler sh(grid);
     118              : 
     119              : //      add all partitions to the handler
     120            0 :         for(int si = 0; si < partsh.num_subsets(); ++si){
     121            0 :                 int newSI = pm.get_target_proc(si);
     122              :                 sh.assign_subset(partsh.begin<Vertex>(si),
     123              :                                                  partsh.end<Vertex>(si), newSI);
     124              :                 sh.assign_subset(partsh.begin<Edge>(si),
     125              :                                                  partsh.end<Edge>(si), newSI);
     126              :                 sh.assign_subset(partsh.begin<Face>(si),
     127              :                                                  partsh.end<Face>(si), newSI);
     128              :                 sh.assign_subset(partsh.begin<Volume>(si),
     129              :                                                  partsh.end<Volume>(si), newSI);
     130              :         }
     131              : 
     132              : //      now save the grid to file
     133            0 :         return SaveGridToFile(grid, sh, filename, aPos);
     134            0 : }
     135              : 
     136              : /** \} */
     137              : 
     138              : }//     end of namespace
     139              : 
     140              : #endif
        

Generated by: LCOV version 2.0-1